jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r480587 - in /jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core: NodeImpl.java lock/LockManager.java lock/LockManagerImpl.java lock/XALockManager.java
Date Wed, 29 Nov 2006 14:59:44 GMT
Author: stefan
Date: Wed Nov 29 06:59:39 2006
New Revision: 480587

URL: http://svn.apache.org/viewvc?view=rev&rev=480587
Log:
JCR-641

Modified:
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/lock/LockManager.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/lock/LockManagerImpl.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/lock/XALockManager.java

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/NodeImpl.java?view=diff&rev=480587&r1=480586&r2=480587
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/NodeImpl.java (original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/NodeImpl.java Wed
Nov 29 06:59:39 2006
@@ -4090,7 +4090,7 @@
 
         LockManager lockMgr = session.getLockManager();
         synchronized (lockMgr) {
-            if (lockMgr.holdsLock(this)) {
+            if (lockMgr.isLockHolder(session, this)) {
                 // save first, and unlock later. this guards concurrent access
 
                 // remove properties in content

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/lock/LockManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/lock/LockManager.java?view=diff&rev=480587&r1=480586&r2=480587
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/lock/LockManager.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/lock/LockManager.java
Wed Nov 29 06:59:39 2006
@@ -65,13 +65,26 @@
 
     /**
      * Returns <code>true</code> if the node given holds a lock;
-     * otherwise returns <code>false</code>
+     * otherwise returns <code>false</code>.
      * @param node node
      * @return <code>true</code> if the node given holds a lock;
      *         otherwise returns <code>false</code>
      * @see javax.jcr.Node#holdsLock
      */
     boolean holdsLock(NodeImpl node) throws RepositoryException;
+
+    /**
+     * Returns <code>true</code> if the specified session holds a lock on the
+     * given node; otherwise returns <code>false</code>.
+     * <p/>
+     * Note that <code>isLockHolder(session, node)==true</code> implies
+     * <code>holdsLock(node)==true</code>.   
+     * @param session session
+     * @param node node
+     * @return if the specified session holds a lock on the given node;
+     *         otherwise returns <code>false</code>
+     */
+    boolean isLockHolder(Session session, NodeImpl node) throws RepositoryException;
 
     /**
      * Returns <code>true</code> if this node is locked either as a result

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/lock/LockManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/lock/LockManagerImpl.java?view=diff&rev=480587&r1=480586&r2=480587
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/lock/LockManagerImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/lock/LockManagerImpl.java
Wed Nov 29 06:59:39 2006
@@ -322,7 +322,7 @@
             if (info == null) {
                 throw new LockException("Node not locked: " + node.safeGetJCRPath());
             }
-            if (!session.equals(info.getLockHolder())) {
+            if (session != info.getLockHolder()) {
                 throw new LockException("Node not locked by session: " + node.safeGetJCRPath());
             }
             session.removeLockToken(info.getLockToken(session), false);
@@ -447,6 +447,27 @@
     /**
      * {@inheritDoc}
      */
+    public boolean isLockHolder(Session session, NodeImpl node) 
+            throws RepositoryException {
+        acquire();
+
+        try {
+            PathMap.Element element = lockMap.map(getPath(node.getId()), true);
+            if (element == null) {
+                return false;
+            }
+            AbstractLockInfo info = (AbstractLockInfo) element.get();
+            return info != null && info.getLockHolder() == session;
+        } catch (ItemNotFoundException e) {
+            return false;
+        } finally {
+            release();
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
     public boolean isLocked(NodeImpl node) throws RepositoryException {
         acquire();
 
@@ -490,7 +511,7 @@
         AbstractLockInfo info = (AbstractLockInfo) element.get();
         if (info != null) {
             if (element.hasPath(path) || info.deep) {
-                if (!session.equals(info.getLockHolder())) {
+                if (session != info.getLockHolder()) {
                     throw new LockException("Node locked.");
                 }
             }
@@ -512,6 +533,9 @@
                 if (info != null) {
                     if (info.getLockHolder() == null) {
                         info.setLockHolder(session);
+                        if (info instanceof LockInfo) {
+                            session.addListener((LockInfo) info);
+                        }
                     } else {
                         log.warn("Adding lock token has no effect: "
                                 + "lock already held by other session.");
@@ -539,7 +563,7 @@
             if (element != null) {
                 AbstractLockInfo info = (AbstractLockInfo) element.get();
                 if (info != null) {
-                    if (session.equals(info.getLockHolder())) {
+                    if (session == info.getLockHolder()) {
                         info.setLockHolder(null);
                     } else {
                         log.warn("Removing lock token has no effect: "
@@ -910,7 +934,7 @@
                         log.debug("Root cause: ", e);
                     }
                 } else {
-                    if (session.equals(lockHolder)) {
+                    if (session == lockHolder) {
                         session.removeLockToken(lockToken.toString());
                         lockHolder = null;
                     }

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/lock/XALockManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/lock/XALockManager.java?view=diff&rev=480587&r1=480586&r2=480587
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/lock/XALockManager.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/lock/XALockManager.java
Wed Nov 29 06:59:39 2006
@@ -25,6 +25,7 @@
 
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
+import javax.jcr.ItemNotFoundException;
 import javax.jcr.lock.Lock;
 import javax.jcr.lock.LockException;
 
@@ -122,6 +123,21 @@
             info = lockMgr.getLockInfo(node.getNodeId());
         }
         return info != null && info.getId().equals(node.getId());
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isLockHolder(Session session, NodeImpl node)
+            throws RepositoryException {
+        AbstractLockInfo info;
+        if (isInXA()) {
+            info = xaEnv.getLockInfo(node);
+        } else {
+            info = lockMgr.getLockInfo(node.getNodeId());
+        }
+        return info != null && info.getId().equals(node.getId())
+                && info.getLockHolder() == session;
     }
 
     /**



Mime
View raw message