jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1513466 - in /jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr: NodeImpl.java delegate/NodeDelegate.java lock/LockImpl.java lock/LockManagerImpl.java
Date Tue, 13 Aug 2013 12:58:37 GMT
Author: jukka
Date: Tue Aug 13 12:58:36 2013
New Revision: 1513466

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

Move more locking code to the delegate layer

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/LockImpl.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=1513466&r1=1513465&r2=1513466&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 13 12:58:36 2013
@@ -1136,26 +1136,31 @@ public class NodeImpl<T extends NodeDele
 
     /**
      * Checks whether this node holds a lock by looking for the
-     * {@code jcr:lockOwner} property.
+     * {@code jcr:lockIsDeep} property.
      */
     @Override
     public boolean holdsLock() throws RepositoryException {
-        final String lockOwner = getOakPathOrThrow(JCR_LOCK_OWNER);
         return perform(new NodeOperation<Boolean>(dlg) {
             @Override
             public Boolean perform() throws RepositoryException {
-                return node.getPropertyOrNull(lockOwner) != null;
+                return node.getTree().hasProperty(JCR_LOCKISDEEP);
             }
         });
     }
 
-    /**
-     * @see javax.jcr.Node#getLock()
-     */
-    @Override
-    @Nonnull
+    @Override @Nonnull
     public Lock getLock() throws RepositoryException {
-        throw new UnsupportedRepositoryOperationException();
+        NodeDelegate lock = perform(new NodeOperation<NodeDelegate>(dlg) {
+            @Override
+            public NodeDelegate perform() {
+                return node.getLock();
+            }
+        });
+        if (lock != null) {
+            return new LockImpl(sessionContext, lock);
+        } else {
+            throw new LockException("Node " + getPath() + " is not locked");
+        }
     }
 
     /**

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=1513466&r1=1513465&r2=1513466&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 13 12:58:36 2013
@@ -674,23 +674,35 @@ public class NodeDelegate extends ItemDe
      */
     // FIXME: access to locking status should not depend on access rights
     public boolean isLocked() {
-        if (tree.hasProperty(JCR_LOCKOWNER)) {
-            return true;
-        }
+        return getLock() != null;
+    }
 
-        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;
-                }
-            }
+    public NodeDelegate getLock() {
+        return getLock(false);
+    }
+
+    private NodeDelegate getLock(boolean deep) {
+        if (holdsLock(deep)) {
+            return this;
+        } else if (tree.isRoot()) {
+            return null;
+        } else {
+            return getParent().getLock(true);
         }
+    }
 
-        return false;
+    /**
+     * 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));
     }
 
     public String getLockOwner() {

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/lock/LockImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/lock/LockImpl.java?rev=1513466&r1=1513465&r2=1513466&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/lock/LockImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/lock/LockImpl.java
Tue Aug 13 12:58:36 2013
@@ -17,7 +17,6 @@
 package org.apache.jackrabbit.oak.jcr.lock;
 
 import static com.google.common.base.Preconditions.checkNotNull;
-import static org.apache.jackrabbit.JcrConstants.JCR_LOCKISDEEP;
 
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
@@ -25,12 +24,10 @@ import javax.jcr.Node;
 import javax.jcr.RepositoryException;
 import javax.jcr.lock.Lock;
 
-import org.apache.jackrabbit.oak.api.PropertyState;
-import org.apache.jackrabbit.oak.api.Tree;
-import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.jcr.NodeImpl;
 import org.apache.jackrabbit.oak.jcr.SessionContext;
 import org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate;
+import org.apache.jackrabbit.oak.jcr.operation.NodeOperation;
 import org.apache.jackrabbit.oak.jcr.operation.SessionOperation;
 
 public final class LockImpl implements Lock {
@@ -56,36 +53,30 @@ public final class LockImpl implements L
 
     @Override
     public String getLockOwner() {
-        return safePerform(new SessionOperation<String>() {
+        return safePerform(new NodeOperation<String>(delegate) {
             @Override
             public String perform() throws RepositoryException {
-                return delegate.getLockOwner();
+                return node.getLockOwner();
             }
         });
     }
 
     @Override
     public boolean isDeep() {
-        return safePerform(new SessionOperation<Boolean>() {
+        return safePerform(new NodeOperation<Boolean>(delegate) {
             @Override
             public Boolean perform() throws RepositoryException {
-                Tree tree = delegate.getTree();
-                PropertyState property = tree.getProperty(JCR_LOCKISDEEP);
-                if (property != null && property.getType() == Type.BOOLEAN) {
-                    return property.getValue(Type.BOOLEAN);
-                } else {
-                    return false;
-                }
+                return node.holdsLock(true);
             }
         });
     }
 
     @Override
     public boolean isLive() {
-        return safePerform(new SessionOperation<Boolean>() {
+        return safePerform(new NodeOperation<Boolean>(delegate) {
             @Override
             public Boolean perform() throws RepositoryException {
-                return delegate.getTree().hasProperty(JCR_LOCKISDEEP);
+                return node.holdsLock(false);
             }
         });
     }

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=1513466&r1=1513465&r2=1513466&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 13 12:58:36 2013
@@ -95,9 +95,26 @@ public class LockManagerImpl implements 
     }
 
     @Override
-    @SuppressWarnings("deprecation")
     public Lock getLock(String absPath) throws RepositoryException {
-        return getSession().getNode(absPath).getLock();
+        final String oakPath =
+                sessionContext.getOakPathOrThrowNotFound(absPath);
+        NodeDelegate lock = perform(new SessionOperation<NodeDelegate>() {
+            @Override
+            public NodeDelegate perform() throws RepositoryException {
+                NodeDelegate node = delegate.getNode(oakPath);
+                if (node != null) {
+                    return node.getLock();
+                } else {
+                    throw new PathNotFoundException(
+                            "Node " + oakPath + " not found");
+                }
+            }
+        });
+        if (lock != null) {
+            return new LockImpl(sessionContext, lock);
+        } else {
+            throw new LockException("Node " + absPath + " is not locked");
+        }
     }
 
     @Override
@@ -118,4 +135,10 @@ public class LockManagerImpl implements 
     private Session getSession() {
         return sessionContext.getSession();
     }
+
+    private <T> T perform(SessionOperation<T> operation)
+            throws RepositoryException {
+        return delegate.perform(operation);
+    }
+
 }
\ No newline at end of file



Mime
View raw message