jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1175026 - in /jackrabbit/sandbox/jackrabbit-mk: jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/ jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/
Date Fri, 23 Sep 2011 21:20:16 GMT
Author: mduerig
Date: Fri Sep 23 21:20:16 2011
New Revision: 1175026

URL: http://svn.apache.org/viewvc?rev=1175026&view=rev
Log:
Microkernel based Jackrabbit prototype (WIP)
refactor: simplify session acquire

Modified:
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/AbstractReadableRepositoryService.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/AbstractRepositoryService.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/Spi2MicrokernelRepositoryServiceFactory.java

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/AbstractReadableRepositoryService.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/AbstractReadableRepositoryService.java?rev=1175026&r1=1175025&r2=1175026&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/AbstractReadableRepositoryService.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/AbstractReadableRepositoryService.java
Fri Sep 23 21:20:16 2011
@@ -27,7 +27,6 @@ import org.apache.jackrabbit.spi.Session
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import javax.jcr.Credentials;
 import javax.jcr.ItemNotFoundException;
 import javax.jcr.NoSuchWorkspaceException;
 import javax.jcr.RepositoryException;
@@ -95,6 +94,7 @@ public abstract class AbstractReadableRe
     }
 
     //------------------------------------< may be overwritten by subclasses>---
+
     /**
      * Checks whether the {@code workspaceName} is valid.
      * @param workspaceName  name of the workspace to check
@@ -109,10 +109,8 @@ public abstract class AbstractReadableRe
     }
 
     @Override
-    protected SessionInfo createSessionInfo(Credentials credentials, String workspaceName)
-            throws RepositoryException {
-
-        return super.createSessionInfo(credentials, workspaceName == null? defaultWsp : workspaceName);
+    protected SessionInfo createSessionInfo(String userId, String workspaceName) throws RepositoryException
{
+        return super.createSessionInfo(userId, workspaceName == null? defaultWsp : workspaceName);
     }
 
     // -------------------------------------------------------------< cache >---

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/AbstractRepositoryService.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/AbstractRepositoryService.java?rev=1175026&r1=1175025&r2=1175026&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/AbstractRepositoryService.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/AbstractRepositoryService.java
Fri Sep 23 21:20:16 2011
@@ -243,51 +243,17 @@ public abstract class AbstractRepository
     }
 
     /**
-     * Creates a session info instance for the given {@code credentials} and
+     * Creates a session info instance for the given {@code userId} and
      * {@code workspaceName}. This default implementation creates a
      * {@link SessionInfoImpl} instance and sets the {@code userId} and
-     * workspaceName. The user {@code userId} is {@code null} or the
-     * {@code userId} from {@code credentials} if it is of type
-     * {@link SimpleCredentials}.
+     * workspaceName.
      *
-     * @param credentials the credentials.
-     * @param workspaceName the name of the workspace to access or {@code null}
-     *        for the default workspace.
-     * @return a session info instance for the given {@code credentials} and
-     *         {@code workspaceName}.
+     * @param userId
+     * @param workspaceName
+     * @return
      * @throws RepositoryException
      */
-    protected SessionInfo createSessionInfo(Credentials credentials, String workspaceName)
throws RepositoryException {
-        String userId = null;
-        if (credentials instanceof SimpleCredentials) {
-            userId = ((SimpleCredentials) credentials).getUserID();
-        }
-        else if (credentials instanceof GuestCredentials) {
-            userId = "anonymous";
-        }
-
-        SessionInfoImpl s = new SessionInfoImpl();
-        s.setUserID(userId);
-        s.setWorkspacename(workspaceName);
-        return s;
-    }
-
-    /**
-     * Creates a session info instance for the given {@code sessionInfo} and
-     * {@code workspaceName}. This default implementation creates a
-     * {@link SessionInfoImpl} instance and sets the {@code userId} and
-     * workspaceName. The user {@code userId} is set to the return value of
-     * {@link SessionInfo#getUserID()}.
-     *
-     * @param sessionInfo the sessionInfo.
-     * @param workspaceName the name of the workspace to access.
-     * @return a session info instance for the given {@code credentials} and
-     *         {@code workspaceName}.
-     * @throws RepositoryException
-     */
-    protected SessionInfo createSessionInfo(SessionInfo sessionInfo, String workspaceName)
throws RepositoryException {
-        String userId = sessionInfo.getUserID();
-
+    protected SessionInfo createSessionInfo(String userId, String workspaceName) throws RepositoryException
{
         SessionInfoImpl s = new SessionInfoImpl();
         s.setUserID(userId);
         s.setWorkspacename(workspaceName);
@@ -329,7 +295,7 @@ public abstract class AbstractRepository
      * <ul>
      * <li>calls {@link #checkCredentials(Credentials, String)}</li>
      * <li>calls {@link #checkWorkspace(String)}</li>
-     * <li>calls {@link #createSessionInfo(Credentials, String)}</li>.
+     * <li>calls {@link #createSessionInfo(String, String)}</li>.
      * </ul>
      * @param credentials the credentials for the login.
      * @param workspaceName the name of the workspace to log in.
@@ -342,16 +308,25 @@ public abstract class AbstractRepository
     public SessionInfo obtain(Credentials credentials, String workspaceName) throws RepositoryException
{
         checkCredentials(credentials, workspaceName);
         checkWorkspace(workspaceName);
-        return createSessionInfo(credentials, workspaceName);
+
+        String userId = null;
+        if (credentials instanceof SimpleCredentials) {
+            userId = ((SimpleCredentials) credentials).getUserID();
+        }
+        else if (credentials instanceof GuestCredentials) {
+            userId = "anonymous";
+        }
+
+        return createSessionInfo(userId, workspaceName);
     }
 
     /**
      * This default implementation returns the session info returned by the call
-     * to {@link #createSessionInfo(SessionInfo, String)}.
+     * to {@link #createSessionInfo(String, String)}.
      */
     @Override
     public SessionInfo obtain(SessionInfo sessionInfo, String workspaceName) throws RepositoryException
{
-        return createSessionInfo(sessionInfo, workspaceName);
+        return createSessionInfo(sessionInfo.getUserID(), workspaceName);
     }
 
 

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java?rev=1175026&r1=1175025&r2=1175026&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
Fri Sep 23 21:20:16 2011
@@ -62,8 +62,6 @@ import org.json.simple.parser.ParseExcep
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import javax.jcr.Credentials;
-import javax.jcr.GuestCredentials;
 import javax.jcr.ItemNotFoundException;
 import javax.jcr.NamespaceException;
 import javax.jcr.NoSuchWorkspaceException;
@@ -71,6 +69,7 @@ import javax.jcr.PathNotFoundException;
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
 import javax.jcr.UnsupportedRepositoryOperationException;
+import javax.jcr.query.InvalidQueryException;
 import javax.jcr.query.Query;
 import javax.jcr.version.OnParentVersionAction;
 import java.io.IOException;
@@ -135,6 +134,7 @@ public class RepositoryServiceImpl exten
     private static final long BINARY_VALUE_INLINE_THRESHOLD = 0x1000;
     private static final String DEFAULT_DEFAULT_WORKSPACE = "default";
     private static final String DEFAULT_SYSTEM_WORKSPACE = "system";
+    private static final String DEFAULT_ANONYMOUS_ID = "anonymous";
 
     private static final String[] SUPPORTED_LANGUAGES = new String[]{Query.SQL, Query.JCR_JQOM,
Query.JCR_SQL2, Query.XPATH};
 
@@ -201,9 +201,10 @@ public class RepositoryServiceImpl exten
     private final PrefixIndex weakReferenceIndex;
     private final Map<SessionInfo, SessionState> sessions = new ConcurrentHashMap<SessionInfo,
SessionState>();
     private final NodeTypeStore nodeTypeStore;
+    private final QueryProcessor queryProcessor;
     private final String defaultWorkspace;
     private final String systemWorkspace;
-    private final QueryProcessor queryProcessor;
+    private final String anonymousId;
 
     public RepositoryServiceImpl(MicroKernel microKernel, Map<?, ?> parameters) throws
RepositoryException {
         super(DESCRIPTORS, Collections.<String, String>emptyMap(), new QNodeTypeDefinition[0]);
@@ -211,11 +212,14 @@ public class RepositoryServiceImpl exten
         try {
             this.microKernel = microKernel;  // todo who disposes the micro kernel?
 
-            defaultWorkspace = getWorkspaceName(parameters,
+            anonymousId = getStringOrDefault(parameters,
+                    Spi2MicrokernelRepositoryServiceFactory.PARAM_ANONYMOUS_ID, DEFAULT_ANONYMOUS_ID);
+
+            defaultWorkspace = getStringOrDefault(parameters,
                     Spi2MicrokernelRepositoryServiceFactory.PARAM_DEFAULT_WORKSPACE, DEFAULT_DEFAULT_WORKSPACE);
             createWorkspace(microKernel.getHeadRevision(), defaultWorkspace, true);
 
-            systemWorkspace = getWorkspaceName(parameters,
+            systemWorkspace = getStringOrDefault(parameters,
                     Spi2MicrokernelRepositoryServiceFactory.PARAM_SYSTEM_WORKSPACE, DEFAULT_SYSTEM_WORKSPACE);
             createWorkspace(microKernel.getHeadRevision(), systemWorkspace, true);
 
@@ -238,7 +242,7 @@ public class RepositoryServiceImpl exten
         }
     }
 
-    private static String getWorkspaceName(Map<?, ?> parameters, String key, String
defaultName) {
+    private static String getStringOrDefault(Map<?, ?> parameters, String key, String
defaultName) {
         Object value = getOrElse(parameters, (Object) key, (Object) defaultName);
         return value instanceof String
             ? (String) value
@@ -267,25 +271,15 @@ public class RepositoryServiceImpl exten
     //------------------------------------------< Session and Workspace handling >---
 
     @Override
-    protected SessionInfo createSessionInfo(SessionInfo sessionInfo, String workspaceName)
throws RepositoryException {
+    protected SessionInfo createSessionInfo(String userId, String workspaceName) throws RepositoryException
{
         if (workspaceName == null) {
             workspaceName = defaultWorkspace;
         }
-        SessionInfo s = super.createSessionInfo(sessionInfo, workspaceName);
-        createSessionState(s);
-        return s;
-    }
-
-    @Override
-    protected SessionInfo createSessionInfo(Credentials credentials, String workspaceName)
throws RepositoryException {
-        if (credentials == null) {
-            credentials = new GuestCredentials();
-        }
-        if (workspaceName == null) {
-            workspaceName = defaultWorkspace;
+        if (userId == null) {
+            userId = anonymousId;
         }
 
-        SessionInfo s = super.createSessionInfo(credentials, workspaceName);
+        SessionInfo s = super.createSessionInfo(userId, workspaceName);
         createSessionState(s);
         return s;
     }

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/Spi2MicrokernelRepositoryServiceFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/Spi2MicrokernelRepositoryServiceFactory.java?rev=1175026&r1=1175025&r2=1175026&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/Spi2MicrokernelRepositoryServiceFactory.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/Spi2MicrokernelRepositoryServiceFactory.java
Fri Sep 23 21:20:16 2011
@@ -31,6 +31,7 @@ public class Spi2MicrokernelRepositorySe
     public static final String PARAM_URL = PARAM_BASE_NAME + ".url";
     public static final String PARAM_DEFAULT_WORKSPACE = PARAM_BASE_NAME + ".default-workspace";
     public static final String PARAM_SYSTEM_WORKSPACE = PARAM_BASE_NAME + ".system-workspace";
+    public static final String PARAM_ANONYMOUS_ID = PARAM_BASE_NAME + ".anonymous-id";
 
     @Override
     public RepositoryService createRepositoryService(Map<?, ?> parameters) throws RepositoryException
{



Mime
View raw message