jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1510935 - in /jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr: NodeImpl.java delegate/NodeDelegate.java lock/LockManagerImpl.java
Date Tue, 06 Aug 2013 12:43:53 GMT
Author: jukka
Date: Tue Aug  6 12:43:52 2013
New Revision: 1510935

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

Improve the isLocked() implementation.

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

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java?rev=1510935&r1=1510934&r2=1510935&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
Tue Aug  6 12:43:52 2013
@@ -86,7 +86,6 @@ import static javax.jcr.Property.JCR_LOC
 import static javax.jcr.Property.JCR_LOCK_OWNER;
 import static org.apache.jackrabbit.JcrConstants.JCR_MIXINTYPES;
 import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE;
-import static org.apache.jackrabbit.oak.api.Type.BOOLEAN;
 import static org.apache.jackrabbit.oak.api.Type.NAME;
 import static org.apache.jackrabbit.oak.api.Type.NAMES;
 
@@ -1089,39 +1088,12 @@ public class NodeImpl<T extends NodeDele
         return getVersionManager().getBaseVersion(getPath());
     }
 
-    /**
-     * Checks whether this node is locked by looking for the
-     * {@code jcr:lockOwner} property either on this node or
-     * on any ancestor that also has the {@code jcr:lockIsDeep}
-     * property set to {@code true}.
-     */
     @Override
     public boolean isLocked() throws RepositoryException {
-        final String lockOwner = getOakPathOrThrow(JCR_LOCK_OWNER);
-        final String lockIsDeep = getOakPathOrThrow(JCR_LOCK_IS_DEEP);
         return perform(new NodeOperation<Boolean>(dlg) {
             @Override
             public Boolean perform() throws RepositoryException {
-                if (node.getPropertyOrNull(lockOwner) != null) {
-                    return true;
-                }
-
-                NodeDelegate parent = node.getParent();
-                while (parent != null) {
-                    if (parent.getPropertyOrNull(lockOwner) != null) {
-                        PropertyDelegate isDeep =
-                                parent.getPropertyOrNull(lockIsDeep);
-                        if (isDeep != null) {
-                            PropertyState state = isDeep.getPropertyState();
-                            if (!state.isArray() && state.getValue(BOOLEAN)) {
-                                return true;
-                            }
-                        }
-                    }
-                    parent = parent.getParent();
-                }
-
-                return false;
+                return node.isLocked();
             }
         });
     }

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=1510935&r1=1510934&r2=1510935&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
Tue Aug  6 12:43:52 2013
@@ -26,6 +26,8 @@ import static com.google.common.collect.
 import static com.google.common.collect.Sets.newLinkedHashSet;
 import static java.util.Collections.singletonList;
 import static org.apache.jackrabbit.JcrConstants.JCR_ISMIXIN;
+import static org.apache.jackrabbit.JcrConstants.JCR_LOCKISDEEP;
+import static org.apache.jackrabbit.JcrConstants.JCR_LOCKOWNER;
 import static org.apache.jackrabbit.JcrConstants.JCR_MIXINTYPES;
 import static org.apache.jackrabbit.JcrConstants.JCR_MULTIPLE;
 import static org.apache.jackrabbit.JcrConstants.JCR_NODETYPENAME;
@@ -35,6 +37,7 @@ import static org.apache.jackrabbit.JcrC
 import static org.apache.jackrabbit.JcrConstants.JCR_SAMENAMESIBLINGS;
 import static org.apache.jackrabbit.JcrConstants.JCR_UUID;
 import static org.apache.jackrabbit.JcrConstants.NT_BASE;
+import static org.apache.jackrabbit.oak.api.Type.BOOLEAN;
 import static org.apache.jackrabbit.oak.api.Type.NAMES;
 import static org.apache.jackrabbit.oak.api.Type.UNDEFINED;
 import static org.apache.jackrabbit.oak.api.Type.UNDEFINEDS;
@@ -663,6 +666,34 @@ public class NodeDelegate extends ItemDe
         getTree().setOrderableChildren(enable);
     }
 
+    /**
+     * Checks whether this node is locked, either directly or through
+     * a deep lock on an ancestor.
+     *
+     * @return whether this node is locked
+     */
+    // FIXME: access to locking status should not depend on access rights
+    public boolean isLocked() {
+        if (tree.hasProperty(JCR_LOCKOWNER)) {
+            return true;
+        }
+
+        Tree ancestor = tree;
+        while (!ancestor.isRoot()) {
+            ancestor = ancestor.getParent();
+            if (ancestor.hasProperty(JCR_LOCKOWNER)) {
+                PropertyState isDeep = ancestor.getProperty(JCR_LOCKISDEEP);
+                if (isDeep != null && !isDeep.isArray()
+                        && isDeep.getValue(BOOLEAN)) {
+                    return true;
+                }
+            }
+        }
+
+        return false;
+    }
+
+
     @Override
     public String toString() {
         return toStringHelper(this).add("tree", tree).toString();

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/lock/LockManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/lock/LockManagerImpl.java?rev=1510935&r1=1510934&r2=1510935&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/lock/LockManagerImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/lock/LockManagerImpl.java
Tue Aug  6 12:43:52 2013
@@ -22,6 +22,7 @@ import java.util.Set;
 
 import javax.annotation.Nonnull;
 import javax.jcr.Node;
+import javax.jcr.PathNotFoundException;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.lock.Lock;
@@ -29,6 +30,9 @@ import javax.jcr.lock.LockException;
 import javax.jcr.lock.LockManager;
 
 import org.apache.jackrabbit.oak.jcr.SessionContext;
+import org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate;
+import org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate;
+import org.apache.jackrabbit.oak.jcr.operation.SessionOperation;
 
 /**
  * Simple lock manager implementation that just keeps track of a set of lock
@@ -38,10 +42,14 @@ import org.apache.jackrabbit.oak.jcr.Ses
 public class LockManagerImpl implements LockManager {
 
     private final SessionContext sessionContext;
+
+    private final SessionDelegate delegate;
+
     private final Set<String> tokens = new HashSet<String>();
 
     public LockManagerImpl(SessionContext sessionContext) {
         this.sessionContext = sessionContext;
+        this.delegate = sessionContext.getSessionDelegate();
     }
 
     @Override
@@ -66,7 +74,18 @@ public class LockManagerImpl implements 
 
     @Override
     public boolean isLocked(String absPath) throws RepositoryException {
-        return getSession().getNode(absPath).isLocked();
+        final String path = sessionContext.getOakPathOrThrowNotFound(absPath);
+        return delegate.perform(new SessionOperation<Boolean>() {
+            @Override public Boolean perform() throws RepositoryException {
+                NodeDelegate node = delegate.getNode(path);
+                if (node != null) {
+                    return node.isLocked();
+                } else {
+                    throw new PathNotFoundException(
+                            "Node " + path + " does not exist");
+                }
+            }
+        });
     }
 
     @Override



Mime
View raw message