jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1324787 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/api/ oak-core/src/main/java/org/apache/jackrabbit/oak/core/ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/
Date Wed, 11 Apr 2012 14:40:24 GMT
Author: mduerig
Date: Wed Apr 11 14:40:22 2012
New Revision: 1324787

URL: http://svn.apache.org/viewvc?rev=1324787&view=rev
Log:
OAK-18: Define Oak API 
- add refresh method to Connection
- Javadoc

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Connection.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ConnectionImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Connection.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Connection.java?rev=1324787&r1=1324786&r2=1324787&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Connection.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Connection.java
Wed Apr 11 14:40:22 2012
@@ -80,8 +80,29 @@ public interface Connection extends Clos
 
     NodeState getCurrentRoot();
 
+    /**
+     * Refresh this connection to the latest revision of the underlying Microkernel.
+     */
+    void refresh();
+
+    /**
+     * Atomically apply all changes in the passed {@code editor} to the underlying
+     * Microkernel. On success this connection is implicitly refreshed to the state
+     * created by applying the editor.
+     *
+     * @param editor  editor carrying the changes to be applies
+     * @return  node state resulting from applying the changed
+     * @throws CommitFailedException
+     */
     NodeState commit(NodeStateEditor editor) throws CommitFailedException;
 
+    /**
+     * Get an node state editor for the given state. Use {@link #commit(NodeStateEditor)}
+     * to atomically apply the changes made in this editor to the underlying Microkernel.
+     *
+     * @param state  node state to edit
+     * @return  editor for the passed {@code state}
+     */
     NodeStateEditor getNodeStateEditor(NodeState state);
 
     /**

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=1324787&r1=1324786&r2=1324787&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 14:40:22 2012
@@ -48,16 +48,17 @@ public class ConnectionImpl implements C
     private final SimpleCredentials credentials;
     private final String workspaceName;
     private final NodeStore store;
-    private final NodeState root;
     private final QueryEngine queryEngine;
 
-    public ConnectionImpl(SimpleCredentials credentials, String workspaceName,
+    private NodeState root;
+
+    private ConnectionImpl(SimpleCredentials credentials, String workspaceName,
             NodeStore store, NodeState root, QueryEngine queryEngine) {
         this.credentials = credentials;
         this.workspaceName = workspaceName;
         this.store = store;
-        this.root = root;
         this.queryEngine = queryEngine;
+        this.root = root;
     }
 
     static Connection createWorkspaceConnection(SimpleCredentials credentials,
@@ -109,11 +110,18 @@ public class ConnectionImpl implements C
     public NodeState getCurrentRoot() {
         return root;
     }
+    
+    @Override
+    public void refresh() {
+        root = workspaceName == null
+            ? store.getRoot()
+            : store.getRoot().getChildNode(workspaceName);
+    }
 
     @Override
     public NodeState commit(NodeStateEditor editor) throws CommitFailedException {
         try {
-            return store.merge(editor, editor.getBaseNodeState());
+            return root = store.merge(editor, editor.getBaseNodeState());
         }
         catch (MicroKernelException e) {
             throw new CommitFailedException(e);

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=1324787&r1=1324786&r2=1324787&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
Wed Apr 11 14:40:22 2012
@@ -167,15 +167,10 @@ public class SessionImpl extends Abstrac
     @Override
     public void refresh(boolean keepChanges) throws RepositoryException {
         checkIsAlive();
-        try {
-            // todo: need a better way to update a connection to head
-            NodeState newState = connection.commit(connection.getNodeStateEditor(connection.getCurrentRoot()));
-            if (!keepChanges) {
-                editor = connection.getNodeStateEditor(newState);
-                itemStateProvider = new ItemStateProvider(editor.getTransientState());
-            }
-        } catch (CommitFailedException e) {
-            throw new RepositoryException(e);
+        connection.refresh();
+        if (!keepChanges) {
+            editor = connection.getNodeStateEditor(connection.getCurrentRoot());
+            itemStateProvider = new ItemStateProvider(editor.getTransientState());
         }
     }
 



Mime
View raw message