You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by an...@apache.org on 2022/10/20 08:50:16 UTC

[jackrabbit-oak] branch OAK-9970 created (now 29630a8893)

This is an automated email from the ASF dual-hosted git repository.

angela pushed a change to branch OAK-9970
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git


      at 29630a8893 OAK-9970 : Internal code calls LockManager.isLocked(String)

This branch includes the following new commits:

     new 29630a8893 OAK-9970 : Internal code calls LockManager.isLocked(String)

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[jackrabbit-oak] 01/01: OAK-9970 : Internal code calls LockManager.isLocked(String)

Posted by an...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

angela pushed a commit to branch OAK-9970
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git

commit 29630a8893194fa27782369bec3be78142308d47
Author: angela <an...@adobe.com>
AuthorDate: Thu Oct 20 10:50:00 2022 +0200

    OAK-9970 : Internal code calls LockManager.isLocked(String)
---
 .../apache/jackrabbit/oak/jcr/session/NodeImpl.java    |  9 ++++++++-
 .../jackrabbit/oak/jcr/version/VersionManagerImpl.java | 18 +++++++-----------
 .../apache/jackrabbit/oak/jcr/xml/ImporterImpl.java    |  5 +++--
 3 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/NodeImpl.java b/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/NodeImpl.java
index ab7cf7f677..589625448b 100644
--- a/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/NodeImpl.java
+++ b/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/NodeImpl.java
@@ -1230,7 +1230,14 @@ public class NodeImpl<T extends NodeDelegate> extends ItemImpl<T> implements Jac
         if (!LockDeprecation.isLockingSupported()) {
             return false;
         }
-        return getLockManager().isLocked(getPath());
+        // don't call LockManager.isLocked(String) to avoid duplicate tree resolution
+        return sessionDelegate.perform(new SessionOperation<Boolean>("isLocked") {
+            @NotNull
+            @Override
+            public Boolean perform() {
+                return dlg.isLocked();
+            }
+        });
     }
 
     @Override
diff --git a/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionManagerImpl.java b/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionManagerImpl.java
index 3106806c77..ff207bc118 100644
--- a/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionManagerImpl.java
+++ b/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionManagerImpl.java
@@ -49,7 +49,6 @@ import org.apache.jackrabbit.oak.jcr.delegate.VersionDelegate;
 import org.apache.jackrabbit.oak.jcr.delegate.VersionHistoryDelegate;
 import org.apache.jackrabbit.oak.jcr.delegate.VersionManagerDelegate;
 import org.apache.jackrabbit.oak.jcr.lock.LockDeprecation;
-import org.apache.jackrabbit.oak.jcr.lock.LockManagerImpl;
 import org.apache.jackrabbit.oak.jcr.session.SessionContext;
 import org.apache.jackrabbit.oak.jcr.session.operation.SessionOperation;
 import org.apache.jackrabbit.oak.plugins.nodetype.write.ReadWriteNodeTypeManager;
@@ -100,7 +99,7 @@ public class VersionManagerImpl implements VersionManager {
                 // check for pending changes
                 checkPendingChangesForRestore(sessionDelegate);
                 // check lock status
-                checkNotLocked(parent.getPath());
+                checkNotLocked(parent);
                 // check for existing nodes
                 List<NodeDelegate> existing = getExisting(version,
                         Collections.<String>emptySet());
@@ -180,7 +179,7 @@ public class VersionManagerImpl implements VersionManager {
                             "No versionable node with identifier: " + versionableId);
                 }
                 // check lock status
-                checkNotLocked(n.getPath());
+                checkNotLocked(n);
                 // check for existing nodes
                 List<NodeDelegate> existing = getExisting(version,
                         Collections.singleton(n.getPath()));
@@ -338,7 +337,7 @@ public class VersionManagerImpl implements VersionManager {
                 if (nodeDelegate == null) {
                     throw new PathNotFoundException(absPath);
                 }
-                checkNotLocked(absPath);
+                checkNotLocked(nodeDelegate);
                 versionManagerDelegate.checkout(nodeDelegate);
             }
         });
@@ -393,16 +392,13 @@ public class VersionManagerImpl implements VersionManager {
         }
     }
 
-    private void checkNotLocked(String absPath) throws RepositoryException {
+    private void checkNotLocked(@NotNull NodeDelegate nodeDelegate) throws RepositoryException {
         if (!LockDeprecation.isLockingSupported()) {
             return;
         }
-        // TODO: avoid nested calls
-        LockManagerImpl lockManager = sessionContext.getWorkspace().getLockManager();
-        if (lockManager.isLocked(absPath)) {
-            NodeDelegate node = sessionContext.getSessionDelegate().getNode(absPath);
-            if (!lockManager.canUnlock(node)) {
-                throw new LockException("Node at " + absPath + " is locked");
+        if (nodeDelegate.isLocked()) {
+            if (!sessionContext.getWorkspace().getLockManager().canUnlock(nodeDelegate)) {
+                throw new LockException("Node at " + nodeDelegate.getPath() + " is locked");
             }
         }
     }
diff --git a/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImporterImpl.java b/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImporterImpl.java
index a8f6f9934e..d981c28fe1 100644
--- a/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImporterImpl.java
+++ b/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImporterImpl.java
@@ -145,11 +145,12 @@ public class ImporterImpl implements Importer {
 
         WorkspaceImpl wsp = sessionContext.getWorkspace();
         VersionManagerImpl vMgr = wsp.internalGetVersionManager();
-        if (!vMgr.isCheckedOut(new NodeDelegate(sd, importTargetTree))) {
+        NodeDelegate nd = new NodeDelegate(sd, importTargetTree); 
+        if (!vMgr.isCheckedOut(nd)) {
             throw new VersionException("Target node is checked in.");
         }
         boolean hasLocking = sessionContext.getRepository().getDescriptorValue(Repository.OPTION_LOCKING_SUPPORTED).getBoolean();
-        if (importTargetTree.getStatus() != Tree.Status.NEW && hasLocking && wsp.getLockManager().isLocked(absPath)) {
+        if (importTargetTree.getStatus() != Tree.Status.NEW && hasLocking && nd.isLocked()) {
             throw new LockException("Target node is locked.");
         }
         effectiveNodeTypeProvider = wsp.getNodeTypeManager();