jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r665851 - in /jackrabbit/sandbox/jackrabbit-ngp/src: main/java/org/apache/jackrabbit/ngp/SessionImpl.java main/java/org/apache/jackrabbit/ngp/state/TransientNodeState.java test/java/org/apache/jackrabbit/ngp/RepositoryTest.java
Date Mon, 09 Jun 2008 19:48:18 GMT
Author: jukka
Date: Mon Jun  9 12:48:18 2008
New Revision: 665851

URL: http://svn.apache.org/viewvc?rev=665851&view=rev
Log:
NGP: More work on Session.refresh(true), plus lock tokens

Modified:
    jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/SessionImpl.java
    jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/state/TransientNodeState.java
    jackrabbit/sandbox/jackrabbit-ngp/src/test/java/org/apache/jackrabbit/ngp/RepositoryTest.java

Modified: jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/SessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/SessionImpl.java?rev=665851&r1=665850&r2=665851&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/SessionImpl.java
(original)
+++ jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/SessionImpl.java
Mon Jun  9 12:48:18 2008
@@ -16,7 +16,9 @@
  */
 package org.apache.jackrabbit.ngp;
 
+import java.util.HashSet;
 import java.util.Map;
+import java.util.Set;
 
 import javax.jcr.Credentials;
 import javax.jcr.ItemNotFoundException;
@@ -43,6 +45,11 @@
 
     private final NamespaceRegistry registry;
 
+    /**
+     * Lock tokens associated with this session.
+     */
+    private final Set<String> tokens = new HashSet<String>();
+
     private NodeState root;
 
     private boolean live = true;
@@ -144,9 +151,8 @@
             throws RepositoryException {
         if (!keepChanges || !root.isModified()) {
             root = repository.getRoot();
-        } else if (
-                ((TransientNodeState) root).getBase() != repository.getRoot()) {
-            throw new UnsupportedRepositoryOperationException();
+        } else {
+            root = ((TransientNodeState) root).merge(repository.getRoot());
         }
     }
 
@@ -189,4 +195,18 @@
         }
     }
 
+    //-------------------------------------------------------< Lock tokens >--
+
+    public String[] getLockTokens() {
+        return (String[]) tokens.toArray(new String[tokens.size()]);
+    }
+
+    public void addLockToken(String lt) {
+        tokens.add(lt);
+    }
+
+    public void removeLockToken(String lt) {
+        tokens.remove(lt);
+    }
+
 }

Modified: jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/state/TransientNodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/state/TransientNodeState.java?rev=665851&r1=665850&r2=665851&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/state/TransientNodeState.java
(original)
+++ jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/state/TransientNodeState.java
Mon Jun  9 12:48:18 2008
@@ -139,4 +139,24 @@
         }
     }
 
+    public TransientNodeState merge(PersistentNodeState rebase) {
+        if (base.equals(rebase)) {
+            return this;
+        } else {
+            TransientNodeState result = new TransientNodeState(rebase);
+            for (Map.Entry<String, PropertyState> entry : properties.entrySet()) {
+                result.setProperty(entry.getKey(), entry.getValue());
+            }
+            for (Map.Entry<String, NodeState> entry : nodes.entrySet()) {
+                NodeState child = entry.getValue();
+                if (child instanceof TransientNodeState) {
+                    child = ((TransientNodeState) child).merge(
+                            (PersistentNodeState) rebase.getNodes().get(entry.getKey()));
+                }
+                result.setNode(entry.getKey(), child);
+            }
+            return result;
+        }
+    }
+
 }

Modified: jackrabbit/sandbox/jackrabbit-ngp/src/test/java/org/apache/jackrabbit/ngp/RepositoryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-ngp/src/test/java/org/apache/jackrabbit/ngp/RepositoryTest.java?rev=665851&r1=665850&r2=665851&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-ngp/src/test/java/org/apache/jackrabbit/ngp/RepositoryTest.java
(original)
+++ jackrabbit/sandbox/jackrabbit-ngp/src/test/java/org/apache/jackrabbit/ngp/RepositoryTest.java
Mon Jun  9 12:48:18 2008
@@ -85,4 +85,45 @@
         }
     }
 
+    @Test
+    public void testRefreshWithoutChanges() throws Exception {
+        Session sessionA = repository.login();
+        try {
+            Session sessionB = repository.login();
+            try {
+                assertFalse(sessionB.getRootNode().hasNode("test"));
+                sessionA.getRootNode().addNode("test");
+                sessionA.save();
+                assertFalse(sessionB.getRootNode().hasNode("test"));
+                sessionB.refresh(false);
+                assertTrue(sessionB.getRootNode().hasNode("test"));
+            } finally {
+                sessionB.logout();
+            }
+        } finally {
+            sessionA.logout();
+        }
+    }
+
+    @Test
+    public void testRefreshWithChanges() throws Exception {
+        Session sessionA = repository.login();
+        try {
+            Session sessionB = repository.login();
+            try {
+                sessionB.getRootNode().addNode("foo");
+                assertFalse(sessionB.getRootNode().hasNode("test"));
+                sessionA.getRootNode().addNode("test");
+                sessionA.save();
+                assertFalse(sessionB.getRootNode().hasNode("test"));
+                sessionB.refresh(true);
+                assertTrue(sessionB.getRootNode().hasNode("test"));
+            } finally {
+                sessionB.logout();
+            }
+        } finally {
+            sessionA.logout();
+        }
+    }
+
 }



Mime
View raw message