jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1533177 - /jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/NodeDelegate.java
Date Thu, 17 Oct 2013 17:52:49 GMT
Author: jukka
Date: Thu Oct 17 17:52:48 2013
New Revision: 1533177

URL: http://svn.apache.org/r1533177
Log:
OAK-150: Basic JCR LockManager support

Avoid an NPE in getLock() in case one of the parent nodes is read-protected

Modified:
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/NodeDelegate.java

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/NodeDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/NodeDelegate.java?rev=1533177&r1=1533176&r2=1533177&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/NodeDelegate.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/NodeDelegate.java
Thu Oct 17 17:52:48 2013
@@ -710,32 +710,46 @@ public class NodeDelegate extends ItemDe
     }
 
     public NodeDelegate getLock() {
-        return getLock(false);
+        Tree lock = findLock(tree, false);
+        if (lock != null) {
+            NodeDelegate delegate = new NodeDelegate(sessionDelegate, lock);
+            if (delegate.isNodeType(MIX_LOCKABLE)) {
+                return delegate;
+            } else if (lock.isRoot()) {
+                return null;
+            } else {
+                lock = findLock(lock.getParent(), true);
+            }
+        }
+        return null;
     }
 
-    private NodeDelegate getLock(boolean deep) {
-        if (holdsLock(deep)) {
-            return this;
+    private Tree findLock(Tree tree, boolean deep) {
+        if (holdsLock(tree, deep)) {
+            return tree;
         } else if (tree.isRoot()) {
             return null;
         } else {
-            return getParent().getLock(true);
+            return findLock(tree.getParent(), true);
         }
     }
 
+    private boolean holdsLock(Tree tree, boolean deep) {
+        // FIXME: access to locking status should not depend on access rights
+        PropertyState property = tree.getProperty(JCR_LOCKISDEEP);
+        return property != null
+                && property.getType() == Type.BOOLEAN
+                && (!deep || property.getValue(BOOLEAN));
+    }
+
     /**
      * Checks whether this node holds a lock.
      *
      * @param deep if {@code true}, only check for deep locks
      * @return whether this node holds a lock
      */
-    // FIXME: access to locking status should not depend on access rights
     public boolean holdsLock(boolean deep) {
-        PropertyState property = tree.getProperty(JCR_LOCKISDEEP);
-        return property != null
-                && property.getType() == Type.BOOLEAN
-                && (!deep || property.getValue(BOOLEAN))
-                && isNodeType(MIX_LOCKABLE);
+        return holdsLock(tree, deep) && isNodeType(MIX_LOCKABLE);
     }
 
     public String getLockOwner() {



Mime
View raw message