jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r158325 - incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/SessionImporter.java
Date Sun, 20 Mar 2005 13:24:32 GMT
Author: stefan
Date: Sun Mar 20 05:24:31 2005
New Revision: 158325

URL: http://svn.apache.org/viewcvs?view=rev&rev=158325
Log:
JCR-31 sysview import cannot handle auto-created nodes

Modified:
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/SessionImporter.java

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/SessionImporter.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/SessionImporter.java?view=diff&r1=158324&r2=158325
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/SessionImporter.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/SessionImporter.java
Sun Mar 20 05:24:31 2005
@@ -33,6 +33,7 @@
 import javax.jcr.ValueFormatException;
 import javax.jcr.nodetype.ConstraintViolationException;
 import javax.jcr.nodetype.PropertyDef;
+import javax.jcr.nodetype.NodeDef;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -129,8 +130,14 @@
                 log.debug(msg);
                 throw new RepositoryException(msg);
             }
-            // @todo implement IMPORT_UUID_COLLISION_REPLACE_EXISTING behavior
-            throw new RepositoryException("uuidBehavior IMPORT_UUID_COLLISION_REPLACE_EXISTING
is not yet implemented");
+            // 'replace' current parent with parent of conflicting
+            parent = (NodeImpl) conflicting.getParent();
+            // remove conflicting
+            conflicting.remove();
+            // create new with given uuid at same location as conflicting
+            node = createNode(parent, nodeInfo.getName(),
+                    nodeInfo.getNodeTypeName(), nodeInfo.getMixinNames(),
+                    nodeInfo.getUUID());
         } else {
             String msg = "unknown uuidBehavior: " + uuidBehavior;
             log.debug(msg);
@@ -163,25 +170,48 @@
         QName ntName = nodeInfo.getNodeTypeName();
         QName[] mixins = nodeInfo.getMixinNames();
 
-        // @todo check for auto-created node (JIRA issue JCR-31)
-        
-        if (uuid == null) {
-            // no potential uuid conflict, always add new node
-            node = createNode(parent, nodeName, ntName, mixins, null);
+        if (parent == null) {
+            // parent node was skipped, skip this child node also
+            parents.push(null); // push null on stack for skipped node
+            log.debug("skipping node " + nodeName);
+            return;
+        }
+        if (parent.hasNode(nodeName)) {
+            // a node with that name already exists...
+            NodeImpl existing = parent.getNode(nodeName);
+            NodeDef def = existing.getDefinition();
+            if (def.isProtected() && existing.isNodeType(ntName)) {
+                // skip protected node
+                parents.push(null); // push null on stack for skipped node
+                log.debug("skipping protected node " + existing.safeGetJCRPath());
+                return;
+            }
+            if (def.isAutoCreate() && existing.isNodeType(ntName)) {
+                // this node has already been auto-created, no need to create it
+                node = existing;
+            } else {
+                throw new ItemExistsException(existing.safeGetJCRPath());
+            }
         } else {
-            // potential uuid conflict
-            NodeImpl conflicting;
-            try {
-                conflicting = (NodeImpl) session.getNodeByUUID(uuid);
-            } catch (ItemNotFoundException infe) {
-                conflicting = null;
-            }
-            if (conflicting != null) {
-                // resolve uuid conflict
-                node = resolveUUIDConflict(parent, conflicting, nodeInfo);
+            // there's no node with that name...
+            if (uuid == null) {
+                // no potential uuid conflict, always add new node
+                node = createNode(parent, nodeName, ntName, mixins, null);
             } else {
-                // create new with given uuid
-                node = createNode(parent, nodeName, ntName, mixins, uuid);
+                // potential uuid conflict
+                NodeImpl conflicting;
+                try {
+                    conflicting = (NodeImpl) session.getNodeByUUID(uuid);
+                } catch (ItemNotFoundException infe) {
+                    conflicting = null;
+                }
+                if (conflicting != null) {
+                    // resolve uuid conflict
+                    node = resolveUUIDConflict(parent, conflicting, nodeInfo);
+                } else {
+                    // create new with given uuid
+                    node = createNode(parent, nodeName, ntName, mixins, uuid);
+                }
             }
         }
 



Mime
View raw message