You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by ju...@apache.org on 2010/08/05 10:35:03 UTC

svn commit: r982504 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core: NodeImpl.java session/AddNodeOperation.java

Author: jukka
Date: Thu Aug  5 08:35:02 2010
New Revision: 982504

URL: http://svn.apache.org/viewvc?rev=982504&view=rev
Log:
JCR-890: concurrent read-only access to a session

Turn Node.addNode() into a SessionOperation

Added:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/AddNodeOperation.java   (with props)
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java?rev=982504&r1=982503&r2=982504&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java Thu Aug  5 08:35:02 2010
@@ -80,6 +80,7 @@ import org.apache.jackrabbit.core.nodety
 import org.apache.jackrabbit.core.query.QueryManagerImpl;
 import org.apache.jackrabbit.core.security.AccessManager;
 import org.apache.jackrabbit.core.security.authorization.Permission;
+import org.apache.jackrabbit.core.session.AddNodeOperation;
 import org.apache.jackrabbit.core.session.SessionContext;
 import org.apache.jackrabbit.core.session.SessionOperation;
 import org.apache.jackrabbit.core.state.ChildNodeEntry;
@@ -1498,7 +1499,7 @@ public class NodeImpl extends ItemImpl i
      * Same as <code>{@link Node#addNode(String, String)}</code> except that
      * this method takes <code>Name</code> arguments instead of
      * <code>String</code>s and has an additional <code>uuid</code> argument.
-     * <p/>
+     * <p>
      * <b>Important Notice:</b> This method is for internal use only! Passing
      * already assigned uuid's might lead to unexpected results and
      * data corruption in the worst case.
@@ -1511,6 +1512,7 @@ public class NodeImpl extends ItemImpl i
      * @return the newly added node
      * @throws RepositoryException if the node can not added
      */
+    // FIXME: This method should not be public
     public synchronized NodeImpl addNode(
             Name nodeName, Name nodeTypeName, NodeId id)
             throws RepositoryException {
@@ -2042,65 +2044,10 @@ public class NodeImpl extends ItemImpl i
      * @return the newly added node
      * @throws RepositoryException if the node can not be added
      */
-    public synchronized Node addNodeWithUuid(
+    public Node addNodeWithUuid(
             String relPath, String nodeTypeName, String uuid)
             throws RepositoryException {
-        // check state of this instance
-        sanityCheck();
-
-        // Get the canonical path of the new node
-        Path path;
-        try {
-            path = PathFactoryImpl.getInstance().create(
-                    getPrimaryPath(), session.getQPath(relPath), true);
-        } catch (NameException e) {
-            throw new RepositoryException(
-                    "Failed to resolve path " + relPath
-                    + " relative to " + this, e);
-        }
-
-        // Get the last path element and check that it's a simple name
-        Path.Element last = path.getNameElement();
-        if (!last.denotesName() || last.getIndex() != 0) {
-            throw new RepositoryException(
-                    "Invalid last path element for adding node "
-                    + relPath + " relative to " + this);
-        }
-
-        // Get the parent node instance
-        NodeImpl parentNode;
-        Path parentPath = path.getAncestor(1);
-        try {
-            parentNode = itemMgr.getNode(parentPath);
-        } catch (PathNotFoundException e) {
-            if (itemMgr.propertyExists(parentPath)) {
-                throw new ConstraintViolationException(
-                        "Unable to add a child node to property "
-                        + session.getJCRPath(parentPath));
-            }
-            throw e;
-        } catch (AccessDeniedException ade) {
-            throw new PathNotFoundException(
-                    "Failed to resolve path " + relPath + " relative to " + this);
-        }
-
-        // Resolve node type name (if any)
-        Name typeName = null;
-        if (nodeTypeName != null) {
-            typeName = session.getQName(nodeTypeName);
-        }
-
-        // Check that the given UUID (if any) does not already exist
-        NodeId id = null;
-        if (uuid != null) {
-            id = new NodeId(uuid);
-            if (itemMgr.itemExists(id)) {
-                throw new ItemExistsException(
-                        "A node with this UUID already exists: " + uuid);
-            }
-        }
-
-        return parentNode.addNode(last.getName(), typeName, id);
+        return perform(new AddNodeOperation(this, relPath, nodeTypeName, uuid));
     }
 
     /**

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/AddNodeOperation.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/AddNodeOperation.java?rev=982504&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/AddNodeOperation.java (added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/AddNodeOperation.java Thu Aug  5 08:35:02 2010
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.core.session;
+
+import javax.jcr.AccessDeniedException;
+import javax.jcr.ItemExistsException;
+import javax.jcr.Node;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.RepositoryException;
+import javax.jcr.nodetype.ConstraintViolationException;
+
+import org.apache.jackrabbit.core.ItemManager;
+import org.apache.jackrabbit.core.NodeImpl;
+import org.apache.jackrabbit.core.SessionImpl;
+import org.apache.jackrabbit.core.id.NodeId;
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.Path;
+import org.apache.jackrabbit.spi.commons.conversion.NameException;
+import org.apache.jackrabbit.spi.commons.name.PathFactoryImpl;
+
+/**
+ * Session operation for adding a new node.
+ */
+public class AddNodeOperation implements SessionOperation<Node> {
+
+    private final NodeImpl node;
+
+    private final String relPath;
+
+    private final String nodeTypeName;
+
+    private final String uuid;
+
+    public AddNodeOperation(
+            NodeImpl node, String relPath,
+            String nodeTypeName, String uuid) {
+        this.node = node;
+        this.relPath = relPath;
+        this.nodeTypeName = nodeTypeName;
+        this.uuid = uuid;
+    }
+
+    public Node perform(SessionContext context) throws RepositoryException {
+        SessionImpl session = context.getSessionImpl();
+        ItemManager itemMgr = context.getItemManager();
+
+        // Get the canonical path of the new node
+        Path path;
+        try {
+            path = PathFactoryImpl.getInstance().create(
+                    node.getPrimaryPath(), session.getQPath(relPath), true);
+        } catch (NameException e) {
+            throw new RepositoryException(
+                    "Failed to resolve path " + relPath
+                    + " relative to " + node, e);
+        }
+
+        // Get the last path element and check that it's a simple name
+        Path.Element last = path.getNameElement();
+        if (!last.denotesName() || last.getIndex() != 0) {
+            throw new RepositoryException(
+                    "Invalid last path element for adding node "
+                    + relPath + " relative to " + node);
+        }
+
+        // Get the parent node instance
+        NodeImpl parentNode;
+        Path parentPath = path.getAncestor(1);
+        try {
+            parentNode = itemMgr.getNode(parentPath);
+        } catch (PathNotFoundException e) {
+            if (itemMgr.propertyExists(parentPath)) {
+                throw new ConstraintViolationException(
+                        "Unable to add a child node to property "
+                        + session.getJCRPath(parentPath));
+            }
+            throw e;
+        } catch (AccessDeniedException ade) {
+            throw new PathNotFoundException(
+                    "Failed to resolve path " + relPath
+                    + " relative to " + node);
+        }
+
+        // Resolve node type name (if any)
+        Name typeName = null;
+        if (nodeTypeName != null) {
+            typeName = session.getQName(nodeTypeName);
+        }
+
+        // Check that the given UUID (if any) does not already exist
+        NodeId id = null;
+        if (uuid != null) {
+            id = new NodeId(uuid);
+            if (itemMgr.itemExists(id)) {
+                throw new ItemExistsException(
+                        "A node with this UUID already exists: " + uuid);
+            }
+        }
+
+        return parentNode.addNode(last.getName(), typeName, id);
+    }
+
+}
\ No newline at end of file

Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/AddNodeOperation.java
------------------------------------------------------------------------------
    svn:eol-style = native