You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by ck...@apache.org on 2009/05/11 09:04:39 UTC

svn commit: r773483 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/lock/LockManagerImpl.java test/java/org/apache/jackrabbit/core/XATest.java

Author: ckoell
Date: Mon May 11 07:04:38 2009
New Revision: 773483

URL: http://svn.apache.org/viewvc?rev=773483&view=rev
Log:
JCR-1633: When node is created and locked in same transaction, exception is thrown

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockManagerImpl.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/XATest.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockManagerImpl.java?rev=773483&r1=773482&r2=773483&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockManagerImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockManagerImpl.java Mon May 11 07:04:38 2009
@@ -134,7 +134,7 @@
     /**
      * System session
      */
-    private final SessionImpl session;
+    private final SessionImpl sysSession;
 
     /**
      * Locks file
@@ -161,7 +161,7 @@
     public LockManagerImpl(SessionImpl session, FileSystem fs)
             throws RepositoryException {
 
-        this.session = session;
+        this.sysSession = session;
         this.locksFile = new FileSystemResource(fs, FileSystem.SEPARATOR + LOCKS_FILE);
 
         session.getWorkspace().getObservationManager().
@@ -216,8 +216,8 @@
     private void reapplyLock(LockToken lockToken) {
         try {
             NodeImpl node = (NodeImpl)
-                session.getItemManager().getItem(lockToken.getId());
-            Path path = getPath(lockToken.getId());
+                sysSession.getItemManager().getItem(lockToken.getId());
+            Path path = getPath(sysSession, lockToken.getId());
 
             LockInfo info = new LockInfo(lockToken, false,
                     node.getProperty(NameConstants.JCR_LOCKISDEEP).getBoolean(),
@@ -314,7 +314,7 @@
 
         try {
             // check whether node is already locked
-            Path path = getPath(node.getId());
+            Path path = getPath(session, node.getId());
             PathMap.Element element = lockMap.map(path, false);
 
             LockInfo other = (LockInfo) element.get();
@@ -375,7 +375,7 @@
         try {
             SessionImpl session = (SessionImpl) node.getSession();
             // check whether node is locked by this session
-            PathMap.Element element = lockMap.map(getPath(node.getId()), true);
+            PathMap.Element element = lockMap.map(getPath(session, node.getId()), true);
             if (element == null) {
                 throw new LockException("Node not locked: " + node);
             }
@@ -436,7 +436,7 @@
     public AbstractLockInfo getLockInfo(NodeId id) throws RepositoryException {
         Path path;
         try {
-            path = getPath(id);
+            path = getPath(sysSession, id);
         } catch (ItemNotFoundException e) {
             return null;
         }
@@ -484,7 +484,7 @@
 
         try {
             SessionImpl session = (SessionImpl) node.getSession();
-            Path path = getPath(node.getId());
+            Path path = getPath(session, node.getId());
 
             PathMap.Element element = lockMap.map(path, false);
             AbstractLockInfo info = (AbstractLockInfo) element.get();
@@ -542,7 +542,8 @@
         acquire();
 
         try {
-            PathMap.Element element = lockMap.map(getPath(node.getId()), true);
+            SessionImpl session = (SessionImpl) node.getSession();
+            PathMap.Element element = lockMap.map(getPath(session, node.getId()), true);
             if (element == null) {
                 return false;
             }
@@ -562,7 +563,8 @@
         acquire();
 
         try {
-            PathMap.Element element = lockMap.map(getPath(node.getId()), true);
+            SessionImpl nodeSession = (SessionImpl) node.getSession();
+            PathMap.Element element = lockMap.map(getPath(nodeSession, node.getId()), true);
             if (element == null) {
                 return false;
             }
@@ -582,7 +584,8 @@
         acquire();
 
         try {
-            Path path = getPath(node.getId());
+            SessionImpl session = (SessionImpl) node.getSession();
+            Path path = getPath(session, node.getId());
 
             PathMap.Element element = lockMap.map(path, false);
             AbstractLockInfo info = (AbstractLockInfo) element.get();
@@ -608,7 +611,7 @@
             throws LockException, RepositoryException {
 
         SessionImpl session = (SessionImpl) node.getSession();
-        checkLock(getPath(node.getId()), session);
+        checkLock(getPath(session, node.getId()), session);
     }
 
     /**
@@ -636,7 +639,7 @@
             LockToken lockToken = LockToken.parse(lt);
 
             NodeImpl node = (NodeImpl)
-                this.session.getItemManager().getItem(lockToken.getId());
+                this.sysSession.getItemManager().getItem(lockToken.getId());
             PathMap.Element element = lockMap.map(node.getPrimaryPath(), true);
             if (element != null) {
                 AbstractLockInfo info = (AbstractLockInfo) element.get();
@@ -670,7 +673,7 @@
             LockToken lockToken = LockToken.parse(lt);
 
             NodeImpl node = (NodeImpl)
-                this.session.getItemManager().getItem(lockToken.getId());
+                this.sysSession.getItemManager().getItem(lockToken.getId());
             PathMap.Element element = lockMap.map(node.getPrimaryPath(), true);
             if (element != null) {
                 AbstractLockInfo info = (AbstractLockInfo) element.get();
@@ -697,7 +700,7 @@
      * Return the path of an item given its id. This method will lookup the
      * item inside the systme session.
      */
-    private Path getPath(ItemId id) throws RepositoryException {
+    private Path getPath(SessionImpl session, ItemId id) throws RepositoryException {
         return session.getHierarchyManager().getPath(id);
     }
 
@@ -992,7 +995,7 @@
 
             try {
                 he = new HierarchyEvent(event.getChildId(),
-                        session.getQPath(event.getPath()).getNormalizedPath(),
+                        sysSession.getQPath(event.getPath()).getNormalizedPath(),
                         event.getType());
             } catch (MalformedPathException e) {
                 log.info("Unable to get event's path: " + e.getMessage());
@@ -1036,7 +1039,7 @@
         for (int i = 0; i < infos.size(); i++) {
             LockInfo info = (LockInfo) infos.get(i);
             try {
-                NodeImpl node = (NodeImpl) session.getItemManager().
+                NodeImpl node = (NodeImpl) sysSession.getItemManager().
                         getItem(info.getId());
                 lockMap.put(node.getPrimaryPath(), info);
             } catch (RepositoryException e) {
@@ -1176,7 +1179,7 @@
                         // Use system session present with lock-mgr as fallback
                         // in order to make sure, that session-scoped locks are
                         // properly cleaned.
-                        SessionImpl systemSession = LockManagerImpl.this.session;
+                        SessionImpl systemSession = LockManagerImpl.this.sysSession;
                         setLockHolder(systemSession);
                         try {
                             NodeImpl node = (NodeImpl) systemSession.getItemManager().getItem(getId());
@@ -1221,7 +1224,7 @@
         acquire();
 
         try {
-            Path path = getPath(nodeId);
+            Path path = getPath(sysSession, nodeId);
 
             // create lock token
             LockInfo info = new LockInfo(new LockToken(nodeId), false, isDeep, lockOwner);
@@ -1241,7 +1244,7 @@
         acquire();
 
         try {
-            Path path = getPath(nodeId);
+            Path path = getPath(sysSession, nodeId);
             PathMap.Element element = lockMap.map(path, true);
             if (element == null) {
                 throw new LockException("Node not locked: " + path.toString());

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/XATest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/XATest.java?rev=773483&r1=773482&r2=773483&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/XATest.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/XATest.java Mon May 11 07:04:38 2009
@@ -887,7 +887,7 @@
      * Test locking a new node inside a transaction.
      * @throws Exception
      */
-    public void xxxtestLockNewNode() throws Exception {
+    public void testLockNewNode() throws Exception {
         // get user transaction object, start
         UserTransaction utx = new UserTransactionImpl(superuser);
         utx.begin();
@@ -900,9 +900,27 @@
 
         // lock this new node
         n.lock(false, true);
+        assertTrue("Node locked in transaction", n.isLocked());
 
         // commit
         utx.commit();
+        
+        // Check if it is locked in other session
+        Session other = helper.getSuperuserSession();
+        Node nOther = other.getNodeByUUID(n.getUUID());        
+        assertTrue(nOther.isLocked());
+
+        // Check if it is also locked in other transaction
+        Session other2 = helper.getSuperuserSession();
+        // start new Transaction and try to add locktoken
+        utx = new UserTransactionImpl(other2);
+        utx.begin();
+        
+        Node nOther2 = other2.getNodeByUUID(n.getUUID());        
+        assertTrue(nOther2.isLocked());
+        
+        utx.commit();
+
     }
 
     /**