jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r817192 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/ItemManager.java test/java/org/apache/jackrabbit/core/ReplaceTest.java test/java/org/apache/jackrabbit/core/TestAll.java
Date Mon, 21 Sep 2009 08:31:29 GMT
Author: mreutegg
Date: Mon Sep 21 08:31:17 2009
New Revision: 817192

URL: http://svn.apache.org/viewvc?rev=817192&view=rev
Log:
JCR-2170: Remove PropDefId and NodeDefId
- fix regression and add test case

Added:
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/ReplaceTest.java
  (with props)
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemManager.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/TestAll.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemManager.java?rev=817192&r1=817191&r2=817192&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemManager.java
Mon Sep 21 08:31:17 2009
@@ -29,6 +29,7 @@
 import javax.jcr.PathNotFoundException;
 import javax.jcr.PropertyIterator;
 import javax.jcr.RepositoryException;
+import javax.jcr.nodetype.ConstraintViolationException;
 
 import org.apache.commons.collections.map.ReferenceMap;
 import org.apache.jackrabbit.core.id.ItemId;
@@ -54,6 +55,8 @@
 import org.apache.jackrabbit.spi.QPropertyDefinition;
 import org.apache.jackrabbit.spi.QNodeDefinition;
 import org.apache.jackrabbit.spi.commons.name.NameConstants;
+import org.apache.jackrabbit.spi.commons.nodetype.NodeDefinitionImpl;
+import org.apache.jackrabbit.spi.commons.nodetype.PropertyDefinitionImpl;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -163,7 +166,7 @@
         shareableNodesCache.clear();
     }
 
-    org.apache.jackrabbit.spi.commons.nodetype.NodeDefinitionImpl getDefinition(NodeState
state)
+    NodeDefinitionImpl getDefinition(NodeState state)
             throws RepositoryException {
         if (state.getId().equals(rootNodeId)) {
             // special handling required for root node
@@ -176,18 +179,28 @@
             // get from overlayed state
             parentId = state.getOverlayedState().getParentId();
         }
-        NodeState parentState;
+        NodeState parentState = null;
         try {
             NodeImpl parent = (NodeImpl) getItem(parentId);
             parentState = parent.getNodeState();
             if (state.getParentId() == null) {
                 // indicates state has been removed, must use
                 // overlayed state of parent, otherwise child node entry
-                // cannot be found
-                parentState = (NodeState) parentState.getOverlayedState();
+                // cannot be found. unless the parentState is new, which
+                // means it was recreated in place of a removed node
+                // that used to be the actual parent
+                if (parentState.getStatus() == ItemState.STATUS_NEW) {
+                    // force getting parent from attic
+                    parentState = null;
+                } else {
+                    parentState = (NodeState) parentState.getOverlayedState();
+                }
             }
         } catch (ItemNotFoundException e) {
-            // parent probably removed, get it from attic
+            // parent probably removed, get it from attic. see below
+        }
+
+        if (parentState == null) {
             try {
                 // use overlayed state if available
                 parentState = (NodeState) sism.getAttic().getItemState(
@@ -196,21 +209,32 @@
                 throw new RepositoryException(ex);
             }
         }
+
         // get child node entry
         ChildNodeEntry cne = parentState.getChildNodeEntry(state.getNodeId());
         NodeTypeRegistry ntReg = session.getNodeTypeManager().getNodeTypeRegistry();
         try {
             EffectiveNodeType ent = ntReg.getEffectiveNodeType(
                     parentState.getNodeTypeName(), parentState.getMixinTypeNames());
-            QNodeDefinition def = ent.getApplicableChildNodeDef(
+            QNodeDefinition def;
+            try {
+                def = ent.getApplicableChildNodeDef(
                     cne.getName(), state.getNodeTypeName(), ntReg);
+            } catch (ConstraintViolationException e) {
+                // fallback to child node definition of a nt:unstructured
+                ent = ntReg.getEffectiveNodeType(NameConstants.NT_UNSTRUCTURED);
+                def = ent.getApplicableChildNodeDef(
+                        cne.getName(), state.getNodeTypeName(), ntReg);
+                log.warn("Fallback to nt:unstructured due to unknown child " +
+                        "node definition for type '" + state.getNodeTypeName() + "'");
+            }
             return session.getNodeTypeManager().getNodeDefinition(def);
         } catch (NodeTypeConflictException e) {
             throw new RepositoryException(e);
         }
     }
 
-    org.apache.jackrabbit.spi.commons.nodetype.PropertyDefinitionImpl getDefinition(PropertyState
state)
+    PropertyDefinitionImpl getDefinition(PropertyState state)
             throws RepositoryException {
         try {
             NodeImpl parent = (NodeImpl) getItem(state.getParentId());
@@ -225,8 +249,17 @@
             NodeTypeRegistry ntReg = session.getNodeTypeManager().getNodeTypeRegistry();
             EffectiveNodeType ent = ntReg.getEffectiveNodeType(
                     parent.getNodeTypeName(), parent.getMixinTypeNames());
-            QPropertyDefinition def = ent.getApplicablePropertyDef(
+            QPropertyDefinition def;
+            try {
+                def = ent.getApplicablePropertyDef(
                     state.getName(), state.getType(), state.isMultiValued());
+            } catch (ConstraintViolationException e) {
+                ent = ntReg.getEffectiveNodeType(NameConstants.NT_UNSTRUCTURED);
+                def = ent.getApplicablePropertyDef(state.getName(),
+                        state.getType(), state.isMultiValued());
+                log.warn("Fallback to nt:unstructured due to unknown property " +
+                        "definition for '" + state.getName() + "'");
+            }
             return session.getNodeTypeManager().getPropertyDefinition(def);
         } catch (ItemStateException e) {
             throw new RepositoryException(e);

Added: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/ReplaceTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/ReplaceTest.java?rev=817192&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/ReplaceTest.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/ReplaceTest.java
Mon Sep 21 08:31:17 2009
@@ -0,0 +1,42 @@
+/*
+ * 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;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Node;
+
+import org.apache.jackrabbit.test.AbstractJCRTest;
+
+/**
+ * <code>ReplaceTest</code> checks if the node definition for a removed node
+ * is correctly calculated when its parent node had been replaced with a new
+ * node and the uuid is still the same.
+ */
+public class ReplaceTest extends AbstractJCRTest {
+
+    public void testReplace() throws RepositoryException {
+        Node n1 = testRootNode.addNode("node1");
+        n1.addMixin(mixReferenceable);
+        String uuid = n1.getIdentifier();
+        n1.addNode("node2");
+        superuser.save();
+
+        n1.remove();
+        ((NodeImpl) testRootNode).addNodeWithUuid("node1", uuid);
+        superuser.save();
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/ReplaceTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/TestAll.java?rev=817192&r1=817191&r2=817192&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/TestAll.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/TestAll.java
Mon Sep 21 08:31:17 2009
@@ -44,6 +44,7 @@
         suite.addTestSuite(InvalidDateTest.class);
         suite.addTestSuite(SessionGarbageCollectedTest.class);
         suite.addTestSuite(ReferencesTest.class);
+        suite.addTestSuite(ReplaceTest.class);
 
         // test related to NodeStateMerger
         // temporarily disabled see JCR-2272 and JCR-2295



Mime
View raw message