Return-Path: Delivered-To: apmail-jackrabbit-commits-archive@www.apache.org Received: (qmail 69741 invoked from network); 21 Sep 2009 08:32:05 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 21 Sep 2009 08:32:05 -0000 Received: (qmail 87617 invoked by uid 500); 21 Sep 2009 08:32:05 -0000 Delivered-To: apmail-jackrabbit-commits-archive@jackrabbit.apache.org Received: (qmail 87531 invoked by uid 500); 21 Sep 2009 08:32:05 -0000 Mailing-List: contact commits-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@jackrabbit.apache.org Delivered-To: mailing list commits@jackrabbit.apache.org Received: (qmail 87521 invoked by uid 99); 21 Sep 2009 08:32:05 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 21 Sep 2009 08:32:05 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 21 Sep 2009 08:32:03 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id F16A023888CC; Mon, 21 Sep 2009 08:31:42 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@jackrabbit.apache.org From: mreutegg@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090921083142.F16A023888CC@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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; + +/** + * ReplaceTest 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