You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jackrabbit.apache.org by GitBox <gi...@apache.org> on 2021/11/04 18:24:43 UTC

[GitHub] [jackrabbit-oak] mreutegg commented on a change in pull request #408: OAK-9613 : Define API to retrieve parent or null for a given Item

mreutegg commented on a change in pull request #408:
URL: https://github.com/apache/jackrabbit-oak/pull/408#discussion_r743099330



##########
File path: oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionImpl.java
##########
@@ -233,6 +233,35 @@ public Item performNullable() throws RepositoryException {
         });
     }
 
+    @Override
+    @Nullable
+    public Node getParentOrNull(@NotNull Item item) throws RepositoryException {
+        checkAlive();
+        ItemImpl itemImpl = checkItemImpl(item);
+        checkContext(itemImpl, sessionContext);
+        return sd.performNullable(new ReadOperation<Node>("getParentOrNull") {
+            @Override
+            public Node performNullable() throws RepositoryException {
+                return NodeImpl.createNodeOrNull(itemImpl.dlg.getParent(), sessionContext);
+            }
+        });
+    }
+    
+    private static void checkContext(@NotNull ItemImpl item, @NotNull SessionContext context) throws RepositoryException {
+        if (item.sessionContext != context) {
+            throw new RepositoryException("Item '"+item+"' has been obtained through a different Session.");
+        }
+    }
+    
+    @NotNull
+    private static ItemImpl checkItemImpl(@NotNull Item item) throws RepositoryException {
+        if (item instanceof ItemImpl) {
+            return (ItemImpl) item;
+        } else {
+            throw new RepositoryException("Invalid item implementation '"+item.getClass().getName()+"'. Excpected org.apache.jackrabbit.oak.jcr.session.ItemImpl");

Review comment:
       Use ItemImpl.class.getName() instead of String literal?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@jackrabbit.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org