jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1461699 - in /jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr: NodeImpl.java SessionContext.java SessionImpl.java WorkspaceImpl.java
Date Wed, 27 Mar 2013 16:30:42 GMT
Author: mduerig
Date: Wed Mar 27 16:30:42 2013
New Revision: 1461699

URL: http://svn.apache.org/r1461699
Log:
OAK-672: Avoid JCR APIs calling other JCR APIs
simplify checking for index on name element

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/SessionContext.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/WorkspaceImpl.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=1461699&r1=1461698&r2=1461699&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
Wed Mar 27 16:30:42 2013
@@ -207,15 +207,16 @@ public class NodeImpl<T extends NodeDele
     public Node addNode(final String relPath, final String primaryNodeTypeName) throws RepositoryException
{
         return perform(new ItemWriteOperation<Node>() {
             @Override
+            protected void checkPreconditions() throws RepositoryException {
+                super.checkPreconditions();
+                SessionImpl.checkIndexOnName(sessionContext, relPath);
+            }
+
+            @Override
             public Node perform() throws RepositoryException {
-                String oakPath = sessionContext.getOakPathKeepIndexOrThrowNotFound(relPath);
+                String oakPath = sessionContext.getOakPathOrThrowNotFound(relPath);
                 String oakName = PathUtils.getName(oakPath);
-                String parentPath = getOakPathOrThrow(PathUtils.getParentPath(oakPath));
-
-                // handle index
-                if (oakName.contains("[")) {
-                    throw new RepositoryException("Cannot create a new node using a name
including an index");
-                }
+                String parentPath = PathUtils.getParentPath(oakPath);
 
                 NodeDelegate parent = dlg.getChild(parentPath);
                 if (parent == null) {

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionContext.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionContext.java?rev=1461699&r1=1461698&r2=1461699&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionContext.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionContext.java
Wed Mar 27 16:30:42 2013
@@ -312,23 +312,6 @@ public abstract class SessionContext imp
         }
     }
 
-    /**
-     * Shortcut for {@code SessionDelegate.getOakPathKeepIndex(jcrPath)}.
-     *
-     * @param jcrPath JCR path
-     * @return Oak path, or {@code null}, with indexes left intact
-     * @throws javax.jcr.PathNotFoundException
-     */
-    @Nonnull
-    public String getOakPathKeepIndexOrThrowNotFound(String jcrPath) throws PathNotFoundException
{
-        String oakPath = namePathMapper.getOakPathKeepIndex(jcrPath);
-        if (oakPath != null) {
-            return oakPath;
-        } else {
-            throw new PathNotFoundException(jcrPath);
-        }
-    }
-
     //------------------------------------------------------------< internal >---
 
     void dispose() {

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java?rev=1461699&r1=1461698&r2=1461699&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
Wed Mar 27 16:30:42 2013
@@ -93,13 +93,22 @@ public class SessionImpl implements Jack
         this.namespaces = namespaces;
     }
 
-    public static void checkProtectedNodes(Session session, String... absJcrPaths) throws
RepositoryException {
+    static void checkProtectedNodes(Session session, String... absJcrPaths) throws RepositoryException
{
         for (String absPath : absJcrPaths) {
             NodeImpl<?> node = (NodeImpl<?>) session.getNode(absPath);
             node.checkProtected();
         }
     }
 
+    static void checkIndexOnName(SessionContext sessionContext, String path) throws RepositoryException
{
+        String oakPath = sessionContext.getOakPathKeepIndex(path);
+        if (oakPath != null) {
+            if (PathUtils.getName(oakPath).contains("[")) {
+                throw new RepositoryException("Cannot create a new node using a name including
an index");
+            }
+        }
+    }
+
     private abstract class CheckedSessionOperation<T> extends SessionOperation<T>
{
         @Override
         protected void checkPreconditions() throws RepositoryException {
@@ -336,19 +345,17 @@ public class SessionImpl implements Jack
             @Override
             protected void checkPreconditions() throws RepositoryException {
                 super.checkPreconditions();
+                // FIXME getRelativeParent doesn't work for fully qualified names. See OAK-724
                 checkProtectedNodes(SessionImpl.this,
                         Text.getRelativeParent(srcAbsPath, 1), Text.getRelativeParent(destAbsPath,
1));
+                checkIndexOnName(sessionContext, destAbsPath);
             }
 
             @Override
             public Void perform() throws RepositoryException {
-                String oakDestPath = sessionContext.getOakPathKeepIndexOrThrowNotFound(destAbsPath);
-                // handle index
-                if (PathUtils.getName(oakDestPath).contains("[")) {
-                    throw new RepositoryException("Cannot create a new node using a name
including an index");
-                }
-
-                sd.move(getOakPathOrThrowNotFound(srcAbsPath), oakDestPath, true);
+                sd.move(
+                        getOakPathOrThrowNotFound(srcAbsPath),
+                        getOakPathOrThrowNotFound(destAbsPath), true);
                 return null;
             }
         });

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/WorkspaceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/WorkspaceImpl.java?rev=1461699&r1=1461698&r2=1461699&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/WorkspaceImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/WorkspaceImpl.java
Wed Mar 27 16:30:42 2013
@@ -39,7 +39,6 @@ import org.apache.jackrabbit.api.Jackrab
 import org.apache.jackrabbit.api.security.authorization.PrivilegeManager;
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.api.Tree;
-import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate;
 import org.apache.jackrabbit.oak.jcr.lock.LockManagerImpl;
 import org.apache.jackrabbit.oak.jcr.query.QueryManagerImpl;
@@ -117,8 +116,8 @@ public class WorkspaceImpl implements Ja
         copy(getName(), srcAbsPath, destAbsPath);
     }
 
-    private String getOakPathKeepIndexOrThrowNotFound(String absPath) throws PathNotFoundException
{
-        return sessionContext.getOakPathKeepIndexOrThrowNotFound(absPath);
+    private String getOakPathOrThrowNotFound(String srcAbsPath) throws PathNotFoundException
{
+        return sessionContext.getOakPathOrThrowNotFound(srcAbsPath);
     }
 
     @Override
@@ -129,29 +128,22 @@ public class WorkspaceImpl implements Ja
             throw new UnsupportedRepositoryOperationException("Not implemented.");
         }
 
+        // FIXME getRelativeParent doesn't work for fully qualified names. See OAK-724
         SessionImpl.checkProtectedNodes(
                 getSession(), Text.getRelativeParent(srcAbsPath, 1), Text.getRelativeParent(destAbsPath,
1));
 
-        String oakPath = getOakPathKeepIndexOrThrowNotFound(destAbsPath);
-        String oakName = PathUtils.getName(oakPath);
-        // handle index
-        if (oakName.contains("[")) {
-            throw new RepositoryException("Cannot create a new node using a name including
an index");
-        }
+        SessionImpl.checkIndexOnName(sessionContext, destAbsPath);
 
         sessionDelegate.copy(
                 getOakPathOrThrowNotFound(srcAbsPath),
-                getOakPathOrThrowNotFound(oakPath));
-    }
-
-    private String getOakPathOrThrowNotFound(String srcAbsPath) throws PathNotFoundException
{
-        return sessionContext.getOakPathOrThrowNotFound(srcAbsPath);
+                getOakPathOrThrowNotFound(destAbsPath));
     }
 
     @Override
     public void clone(String srcWorkspace, String srcAbsPath, String destAbsPath, boolean
removeExisting) throws RepositoryException {
         ensureIsAlive();
 
+        // FIXME getRelativeParent doesn't work for fully qualified names. See OAK-724
         SessionImpl.checkProtectedNodes(
                 getSession(), Text.getRelativeParent(srcAbsPath, 1), Text.getRelativeParent(destAbsPath,
1));
 
@@ -163,19 +155,15 @@ public class WorkspaceImpl implements Ja
     public void move(String srcAbsPath, String destAbsPath) throws RepositoryException {
         ensureIsAlive();
 
+        // FIXME getRelativeParent doesn't work for fully qualified names. See OAK-724
         SessionImpl.checkProtectedNodes(
                 getSession(), Text.getRelativeParent(srcAbsPath, 1), Text.getRelativeParent(destAbsPath,
1));
 
-        String oakPath = getOakPathKeepIndexOrThrowNotFound(destAbsPath);
-        String oakName = PathUtils.getName(oakPath);
-        // handle index
-        if (oakName.contains("[")) {
-            throw new RepositoryException("Cannot create a new node using a name including
an index");
-        }
+        SessionImpl.checkIndexOnName(sessionContext, destAbsPath);
 
         sessionDelegate.move(
                 getOakPathOrThrowNotFound(srcAbsPath),
-                getOakPathOrThrowNotFound(oakPath),
+                getOakPathOrThrowNotFound(destAbsPath),
                 false);
     }
 



Mime
View raw message