jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1306937 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/core/ oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ oak-jcr/src/main/java/org/apache/jackr...
Date Thu, 29 Mar 2012 15:49:38 GMT
Author: mduerig
Date: Thu Mar 29 15:49:37 2012
New Revision: 1306937

URL: http://svn.apache.org/viewvc?rev=1306937&view=rev
Log:
OAK-15: Clean up oak-jcr
- use new API from OAK-18 to reduce dependencies from oak-jcr to oak-mk

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
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeState.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionContext.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/state/TransientNodeState.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=1306937&r1=1306936&r2=1306937&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
Thu Mar 29 15:49:37 2012
@@ -16,14 +16,18 @@
  */
 package org.apache.jackrabbit.oak.core;
 
+import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.mk.model.NodeBuilder;
 import org.apache.jackrabbit.mk.model.NodeState;
+import org.apache.jackrabbit.mk.model.NodeStore;
 import org.apache.jackrabbit.oak.api.AuthInfo;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.Connection;
+import org.apache.jackrabbit.oak.kernel.KernelNodeStore;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import javax.jcr.NoSuchWorkspaceException;
 import javax.jcr.SimpleCredentials;
 import java.io.IOException;
 
@@ -37,19 +41,30 @@ public class ConnectionImpl implements C
      */
     private static final Logger log = LoggerFactory.getLogger(ConnectionImpl.class);
 
-    private final SimpleCredentials sc;
+    private final SimpleCredentials credentials;
     private final String workspaceName;
+    private final NodeStore store;
 
-    private String revision;
+    private NodeState root;
 
-    ConnectionImpl(SimpleCredentials sc, String workspaceName, String revision) {
-        this.sc = sc;
+    public ConnectionImpl(SimpleCredentials credentials, String workspaceName,
+            NodeStore store, NodeState root) {
+        this.credentials = credentials;
         this.workspaceName = workspaceName;
-        this.revision = revision;
+        this.store = store;
+        this.root = root;
     }
 
-    public String getRevision() {
-        return revision;
+    static Connection createWorkspaceConnection(SimpleCredentials credentials,
+            String workspace, MicroKernel microKernel, String revision) throws NoSuchWorkspaceException
{
+
+        NodeStore store = new KernelNodeStore(microKernel); // TODO: pass revision?
+        NodeState wspRoot = store.getRoot().getChildNode(workspace);
+        if (wspRoot == null) {
+            throw new NoSuchWorkspaceException(workspace);
+        }
+
+        return new ConnectionImpl(credentials, workspace, store, wspRoot);
     }
 
     @Override
@@ -58,34 +73,42 @@ public class ConnectionImpl implements C
         return new AuthInfo() {
             @Override
             public String getUserID() {
-                return sc.getUserID();
+                return credentials.getUserID();
             }
 
             @Override
             public String[] getAttributeNames() {
-                return sc.getAttributeNames();
+                return credentials.getAttributeNames();
             }
 
             @Override
             public Object getAttribute(String attributeName) {
-                return sc.getAttribute(attributeName);
+                return credentials.getAttribute(attributeName);
             }
         };
     }
 
     @Override
     public NodeState getCurrentRoot() {
-        return null; // todo implement getCurrentRoot
+        return root;
     }
 
     @Override
     public NodeState commit(NodeState newRoot) throws CommitFailedException {
-        return null; // todo implement commit
+        if (workspaceName == null) {
+// todo            store.setRoot(newRoot);
+            return root = store.getRoot();
+        }
+        else {
+// todo            NodeBuilder builder = store.getNodeBuilder(store.getRoot());
+//            builder.setChildNode(workspaceName, newRoot);
+            return root = store.getRoot().getChildNode(workspaceName);
+        }
     }
 
     @Override
     public NodeBuilder getNodeBuilder(NodeState state) {
-        return null; // todo implement getNodeBuilder
+        return store.getNodeBuilder(state);
     }
 
     @Override
@@ -100,6 +123,6 @@ public class ConnectionImpl implements C
 
     @Override
     public Connection getRepositoryConnection() {
-        return null; // todo implement getRepositoryConnection
+        return new ConnectionImpl(credentials, null, store, store.getRoot());
     }
 }
\ No newline at end of file

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=1306937&r1=1306936&r2=1306937&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
Thu Mar 29 15:49:37 2012
@@ -71,7 +71,7 @@ public class TmpRepositoryService implem
         final String revision = getRevision(credentials);
 
         if (sc != null) {
-            return new ConnectionImpl(sc, wspName, revision);
+            return ConnectionImpl.createWorkspaceConnection(sc, wspName, mk, revision);
         } else {
             throw new LoginException("login failed...");
         }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeState.java?rev=1306937&r1=1306936&r2=1306937&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeState.java
Thu Mar 29 15:49:37 2012
@@ -39,7 +39,7 @@ import java.util.Map;
  * Basic {@link NodeState} implementation based on the {@link MicroKernel}
  * interface. This class makes an attempt to load data lazily.
  */
-public class KernelNodeState extends AbstractNodeState { // fixme make package private
+class KernelNodeState extends AbstractNodeState {
 
     /**
      * Maximum number of child nodes kept in memory.

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionContext.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionContext.java?rev=1306937&r1=1306936&r2=1306937&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionContext.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionContext.java
Thu Mar 29 15:49:37 2012
@@ -20,6 +20,7 @@
 package org.apache.jackrabbit.oak.jcr;
 
 import org.apache.jackrabbit.mk.api.MicroKernel;
+import org.apache.jackrabbit.oak.api.Connection;
 import org.apache.jackrabbit.oak.jcr.state.NodeStateProvider;
 
 import javax.jcr.Session;
@@ -29,6 +30,7 @@ public interface SessionContext<T extend
     T getSession();
     GlobalContext getGlobalContext();
     String getWorkspaceName();
+    Connection getConnection();
     MicroKernel getMicrokernel();
     String getRevision(); // TODO: this should be superfluous if SessionInfo is used for
communication
     ValueFactory getValueFactory();

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java?rev=1306937&r1=1306936&r2=1306937&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
Thu Mar 29 15:49:37 2012
@@ -18,8 +18,8 @@ package org.apache.jackrabbit.oak.jcr;
 
 import org.apache.jackrabbit.commons.AbstractSession;
 import org.apache.jackrabbit.mk.api.MicroKernel;
+import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.Connection;
-import org.apache.jackrabbit.oak.core.ConnectionImpl;
 import org.apache.jackrabbit.oak.jcr.state.NodeStateProvider;
 import org.apache.jackrabbit.oak.jcr.state.TransientNodeState;
 import org.apache.jackrabbit.oak.jcr.state.TransientSpace;
@@ -74,7 +74,7 @@ public class SessionImpl extends Abstrac
 
         this.globalContext = globalContext;
         this.connection = connection;
-        this.revision = ((ConnectionImpl) connection).getRevision();
+        this.revision = globalContext.getInstance(MicroKernel.class).getHeadRevision(); 
// fixme: this is a hack and creates a race. however we will get rid of tracking the revision
here anyway
 
         valueFactory = new ValueFactoryImpl();
         repository = new RepositoryAdaptor(globalContext.getInstance(Repository.class), valueFactory);
@@ -213,15 +213,27 @@ public class SessionImpl extends Abstrac
     @Override
     public void save() throws RepositoryException {
         checkIsAlive();
-        revision = transientSpace.save();
-        nodeStateProvider.clear();
+        try {
+            revision = transientSpace.save();
+            connection.commit(connection.getCurrentRoot());  // todo: need a way to update
a connection to head
+            nodeStateProvider.clear();
+        }
+        catch (CommitFailedException e) {
+            throw new RepositoryException(e);
+        }
     }
 
     @Override
     public void refresh(boolean keepChanges) throws RepositoryException {
         checkIsAlive();
-        revision = transientSpace.refresh(keepChanges);
-        nodeStateProvider.clear();
+        try {
+            revision = transientSpace.refresh(keepChanges);
+            connection.commit(connection.getCurrentRoot());  // todo: need a way to update
a connection to head
+            nodeStateProvider.clear();
+        }
+        catch (CommitFailedException e) {
+            throw new RepositoryException(e);
+        }
     }
 
     @Override
@@ -480,6 +492,11 @@ public class SessionImpl extends Abstrac
         }
 
         @Override
+        public Connection getConnection() {
+            return connection;
+        }
+
+        @Override
         public MicroKernel getMicrokernel() {
             return globalContext.getInstance(MicroKernel.class);
         }

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/state/TransientNodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/state/TransientNodeState.java?rev=1306937&r1=1306936&r2=1306937&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/state/TransientNodeState.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/state/TransientNodeState.java
Thu Mar 29 15:49:37 2012
@@ -19,11 +19,12 @@
 
 package org.apache.jackrabbit.oak.jcr.state;
 
-import org.apache.jackrabbit.mk.model.Scalar;
-import org.apache.jackrabbit.mk.model.ScalarImpl;
 import org.apache.jackrabbit.mk.model.ChildNodeEntry;
 import org.apache.jackrabbit.mk.model.NodeState;
 import org.apache.jackrabbit.mk.model.PropertyState;
+import org.apache.jackrabbit.mk.model.Scalar;
+import org.apache.jackrabbit.mk.model.ScalarImpl;
+import org.apache.jackrabbit.oak.api.Connection;
 import org.apache.jackrabbit.oak.jcr.SessionContext;
 import org.apache.jackrabbit.oak.jcr.SessionImpl;
 import org.apache.jackrabbit.oak.jcr.state.ChangeTree.NodeDelta;
@@ -32,7 +33,6 @@ import org.apache.jackrabbit.oak.jcr.uti
 import org.apache.jackrabbit.oak.jcr.util.PagedIterator;
 import org.apache.jackrabbit.oak.jcr.util.Path;
 import org.apache.jackrabbit.oak.jcr.util.Predicate;
-import org.apache.jackrabbit.oak.kernel.KernelNodeState;
 import org.apache.jackrabbit.oak.kernel.KernelPropertyState;
 
 import javax.jcr.ItemExistsException;
@@ -331,8 +331,7 @@ public class TransientNodeState {
             if (path == null) {
                 persistentNodeState = EmptyNodeState.INSTANCE;
             } else {
-                // TODO: use oak-api here in order to avoid reading directly from MK
-                persistentNodeState = new KernelNodeState(sessionContext.getMicrokernel(),
path.toMkPath(), revision);
+                persistentNodeState = getPersistentNodeState(sessionContext.getConnection(),
path);
             }
         }
 
@@ -343,4 +342,16 @@ public class TransientNodeState {
         return nodeDelta = getNodeStateProvider().getNodeDelta(nodeDelta.getPath());
     }
 
+    private static NodeState getPersistentNodeState(Connection connection, Path path) {
+        NodeState state = connection.getCurrentRoot();
+        for (String name : path.getNames()) {
+            state = state.getChildNode(name);
+            if (state == null) {
+                return null;
+            }
+        }
+
+        return state;
+    }
+
 }



Mime
View raw message