jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1324877 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core: ConnectionImpl.java TmpRepositoryService.java
Date Wed, 11 Apr 2012 17:19:12 GMT
Author: mduerig
Date: Wed Apr 11 17:19:11 2012
New Revision: 1324877

URL: http://svn.apache.org/viewvc?rev=1324877&view=rev
Log:
OAK-62: ConnectionImpl should not acquire Microkernel instance

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ConnectionImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TmpRepositoryService.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ConnectionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ConnectionImpl.java?rev=1324877&r1=1324876&r2=1324877&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ConnectionImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ConnectionImpl.java
Wed Apr 11 17:19:11 2012
@@ -16,8 +16,6 @@
  */
 package org.apache.jackrabbit.oak.core;
 
-import org.apache.jackrabbit.mk.MicroKernelFactory;
-import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.mk.api.MicroKernelException;
 import org.apache.jackrabbit.oak.api.AuthInfo;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
@@ -26,8 +24,6 @@ import org.apache.jackrabbit.oak.api.Nod
 import org.apache.jackrabbit.oak.api.NodeStateEditor;
 import org.apache.jackrabbit.oak.api.NodeStore;
 import org.apache.jackrabbit.oak.api.QueryEngine;
-import org.apache.jackrabbit.oak.kernel.KernelNodeStore;
-import org.apache.jackrabbit.oak.query.QueryEngineImpl;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -62,25 +58,14 @@ public class ConnectionImpl implements C
     }
 
     static Connection createWorkspaceConnection(SimpleCredentials credentials,
-            String workspace, boolean create, String microKernelUrl, String revision)
+            String workspace, NodeStore store, String revision, QueryEngine queryEngine)
             throws NoSuchWorkspaceException {
 
-        MicroKernel microKernel = MicroKernelFactory.getInstance(microKernelUrl);
-
-        // FIXME: workspace setup must be done elsewhere...
-        if (create) {
-            String headRev = microKernel.getHeadRevision();
-            if (!microKernel.nodeExists('/' + workspace, headRev)) {
-                microKernel.commit("/", "+ \"" + workspace + "\" : {}", headRev, null);
-            }
-        }
-
-        NodeStore store = new KernelNodeStore(microKernel); // TODO: pass revision?
+        // TODO set revision!?
         NodeState wspRoot = store.getRoot().getChildNode(workspace);
         if (wspRoot == null) {
             throw new NoSuchWorkspaceException(workspace);
         }
-        QueryEngine queryEngine = new QueryEngineImpl(microKernel);
 
         return new ConnectionImpl(credentials, workspace, store, wspRoot, queryEngine);
     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TmpRepositoryService.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TmpRepositoryService.java?rev=1324877&r1=1324876&r2=1324877&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TmpRepositoryService.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TmpRepositoryService.java
Wed Apr 11 17:19:11 2012
@@ -16,8 +16,15 @@
  */
 package org.apache.jackrabbit.oak.core;
 
+import org.apache.jackrabbit.mk.MicroKernelFactory;
+import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.oak.api.Connection;
+import org.apache.jackrabbit.oak.api.NodeState;
+import org.apache.jackrabbit.oak.api.NodeStateEditor;
+import org.apache.jackrabbit.oak.api.QueryEngine;
 import org.apache.jackrabbit.oak.api.RepositoryService;
+import org.apache.jackrabbit.oak.kernel.KernelNodeStore;
+import org.apache.jackrabbit.oak.query.QueryEngineImpl;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -39,10 +46,12 @@ public class TmpRepositoryService implem
     // TODO: retrieve default wsp-name from configuration
     private static final String DEFAULT_WORKSPACE_NAME = "default";
 
-    private final String microKernelUrl;
+    private final MicroKernel microKernel;
+    private final KernelNodeStore nodeStore;
 
     public TmpRepositoryService(String microKernelUrl) {
-        this.microKernelUrl = microKernelUrl;
+        microKernel = MicroKernelFactory.getInstance(microKernelUrl);
+        nodeStore = new KernelNodeStore(microKernel);
     }
 
     @Override
@@ -61,17 +70,28 @@ public class TmpRepositoryService implem
         } else {
             sc = null;
         }
+        
+        if (sc == null) {
+            throw new LoginException("login failed");
+        }
 
         final String wspName = (workspaceName == null) ? DEFAULT_WORKSPACE_NAME : workspaceName;
         final String revision = getRevision(credentials);
 
-        if (sc != null) {
-            return ConnectionImpl.createWorkspaceConnection(
-                    sc, wspName, wspName.equals(DEFAULT_WORKSPACE_NAME),
-                    microKernelUrl, revision);
-        } else {
-            throw new LoginException("login failed...");
+        // FIXME: workspace setup must be done elsewhere...
+        if (wspName.equals(DEFAULT_WORKSPACE_NAME)) {
+            NodeState root = nodeStore.getRoot();
+            NodeState wspNode = root.getChildNode(wspName);
+            if (wspNode == null) {
+                NodeStateEditor editor = nodeStore.branch(root);
+                editor.addNode(wspName);
+                nodeStore.merge(editor, editor.getBaseNodeState());
+            }
         }
+
+        QueryEngine queryEngine = new QueryEngineImpl(microKernel);
+        return ConnectionImpl.createWorkspaceConnection(sc, wspName, nodeStore, revision,
+                queryEngine);
     }
 
     /**



Mime
View raw message