Index: src/test/java/org/apache/jackrabbit/spi/commons/nodetype/NodeTypeDefDiffTest.java =================================================================== --- src/test/java/org/apache/jackrabbit/spi/commons/nodetype/NodeTypeDefDiffTest.java (revision 0) +++ src/test/java/org/apache/jackrabbit/spi/commons/nodetype/NodeTypeDefDiffTest.java (revision 0) @@ -0,0 +1,84 @@ +package org.apache.jackrabbit.spi.commons.nodetype; + +import junit.framework.TestCase; + +import org.apache.jackrabbit.spi.Name; +import org.apache.jackrabbit.spi.NameFactory; +import org.apache.jackrabbit.spi.QNodeDefinition; +import org.apache.jackrabbit.spi.commons.name.NameConstants; +import org.apache.jackrabbit.spi.commons.name.NameFactoryImpl; + +public class NodeTypeDefDiffTest extends TestCase { + + private static final String NODE_TYPE1 = "nodeType1"; + private static final String NODE_TYPE2A = "nodeType2a"; + private static final String NODE_TYPE2B = "nodeType2b"; + private static final String CHILD_NAME = "child"; + + NameFactory nameFactory = NameFactoryImpl.getInstance(); + + public void testAddRequiredTypeToChildNodeDefinition() throws Exception { + // Old node type definition + QNodeTypeDefinitionBuilder oldDef = new QNodeTypeDefinitionBuilder(); + oldDef.setName(nameFactory.create("", NODE_TYPE1)); + oldDef.setSupertypes(new Name[] { NameConstants.NT_BASE }); + + QNodeDefinitionBuilder oldChildDef = new QNodeDefinitionBuilder(); + oldChildDef.setRequiredPrimaryTypes(new Name[]{ + nameFactory.create("", NODE_TYPE2A)}); + oldChildDef.setName(nameFactory.create("", CHILD_NAME)); + oldChildDef.setDeclaringNodeType(oldDef.getName()); + + oldDef.setChildNodeDefs(new QNodeDefinition[] { oldChildDef.build() }); + + // New node type definition + QNodeTypeDefinitionBuilder newDef = new QNodeTypeDefinitionBuilder(); + newDef.setName(nameFactory.create("", NODE_TYPE1)); + newDef.setSupertypes(new Name[] { NameConstants.NT_BASE }); + + // Child node with additional required primary types + QNodeDefinitionBuilder newChildDef = new QNodeDefinitionBuilder(); + newChildDef.setRequiredPrimaryTypes(new Name[]{ + nameFactory.create("", NODE_TYPE2A), nameFactory.create("", NODE_TYPE2B)}); + newChildDef.setName(nameFactory.create("", CHILD_NAME)); + newChildDef.setDeclaringNodeType(newDef.getName()); + + newDef.setChildNodeDefs(new QNodeDefinition[] { newChildDef.build() }); + + NodeTypeDefDiff nodeTypeDefDiff = NodeTypeDefDiff.create(oldDef.build(), newDef.build()); + System.out.println(nodeTypeDefDiff); + assertTrue(nodeTypeDefDiff.isTrivial()); + } + + public void testRemoveRequiredTypeToChildNodeDefinition() throws Exception { + // Old node type definition + QNodeTypeDefinitionBuilder oldDef = new QNodeTypeDefinitionBuilder(); + oldDef.setName(nameFactory.create("", NODE_TYPE1)); + oldDef.setSupertypes(new Name[] { NameConstants.NT_BASE }); + + QNodeDefinitionBuilder oldChildDef = new QNodeDefinitionBuilder(); + oldChildDef.setRequiredPrimaryTypes(new Name[]{ + nameFactory.create("", NODE_TYPE2A)}); + oldChildDef.setName(nameFactory.create("", CHILD_NAME)); + oldChildDef.setDeclaringNodeType(oldDef.getName()); + + oldDef.setChildNodeDefs(new QNodeDefinition[] { oldChildDef.build() }); + + // Old node type definition + QNodeTypeDefinitionBuilder newDef = new QNodeTypeDefinitionBuilder(); + newDef.setName(nameFactory.create("", NODE_TYPE1)); + newDef.setSupertypes(new Name[] { NameConstants.NT_BASE }); + + // Child node without required primary types + QNodeDefinitionBuilder newChildDef = new QNodeDefinitionBuilder(); + newChildDef.setName(nameFactory.create("", CHILD_NAME)); + newChildDef.setDeclaringNodeType(newDef.getName()); + + newDef.setChildNodeDefs(new QNodeDefinition[] { newChildDef.build() }); + + NodeTypeDefDiff nodeTypeDefDiff = NodeTypeDefDiff.create(oldDef.build(), newDef.build()); + System.out.println(nodeTypeDefDiff); + assertTrue(nodeTypeDefDiff.isTrivial()); + } + +} Index: src/main/java/org/apache/jackrabbit/spi/commons/nodetype/NodeTypeDefDiff.java =================================================================== --- src/main/java/org/apache/jackrabbit/spi/commons/nodetype/NodeTypeDefDiff.java (revision 1403182) +++ src/main/java/org/apache/jackrabbit/spi/commons/nodetype/NodeTypeDefDiff.java (working copy) @@ -16,15 +16,6 @@ */ package org.apache.jackrabbit.spi.commons.nodetype; -import org.apache.jackrabbit.spi.Name; -import org.apache.jackrabbit.spi.QItemDefinition; -import org.apache.jackrabbit.spi.QNodeDefinition; -import org.apache.jackrabbit.spi.QNodeTypeDefinition; -import org.apache.jackrabbit.spi.QPropertyDefinition; -import org.apache.jackrabbit.spi.QValueConstraint; -import org.apache.jackrabbit.spi.commons.name.NameConstants; - -import javax.jcr.PropertyType; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -34,6 +25,16 @@ import java.util.Map; import java.util.Set; +import javax.jcr.PropertyType; + +import org.apache.jackrabbit.spi.Name; +import org.apache.jackrabbit.spi.QItemDefinition; +import org.apache.jackrabbit.spi.QNodeDefinition; +import org.apache.jackrabbit.spi.QNodeTypeDefinition; +import org.apache.jackrabbit.spi.QPropertyDefinition; +import org.apache.jackrabbit.spi.QValueConstraint; +import org.apache.jackrabbit.spi.commons.name.NameConstants; + /** * A NodeTypeDefDiff represents the result of the comparison of * two node type definitions. @@ -606,14 +607,17 @@ List l2 = Arrays.asList(getNewDef().getRequiredPrimaryTypes()); if (!l1.equals(l2)) { // requiredPrimaryTypes have been modified - if (l1.containsAll(l2)) { + if (l2.size() == 1 && l2.get(0).equals(NameConstants.NT_BASE)) { + // new requiredPrimaryType is nt:base (TRIVIAL change) + type = TRIVIAL; + } else if (l1.containsAll(l2)) { // old list is a superset of new list - // => removed requiredPrimaryType (TRIVIAL change) - type = TRIVIAL; - } else { - // added/modified requiredPrimaryType (MAJOR change) + // => removed requiredPrimaryType (MAJOR change) // todo check whether aggregate of old requiredTypes would include aggregate of new requiredTypes => trivial change type = MAJOR; + } else { + // added/modified requiredPrimaryType (TRIVIAL change) + type = TRIVIAL; } } } @@ -628,16 +632,10 @@ Name declaringNodeType; Name name; - int requiredType; - boolean definesResidual; - boolean isMultiple; QPropertyDefinitionId(QPropertyDefinition def) { declaringNodeType = def.getDeclaringNodeType(); name = def.getName(); - requiredType = def.getRequiredType(); - definesResidual = def.definesResidual(); - isMultiple = def.isMultiple(); } //---------------------------------------< java.lang.Object overrides > @@ -649,10 +647,7 @@ if (obj instanceof QPropertyDefinitionId) { QPropertyDefinitionId other = (QPropertyDefinitionId) obj; return declaringNodeType.equals(other.declaringNodeType) - && name.equals(other.name) - && requiredType == other.requiredType - && definesResidual == other.definesResidual - && isMultiple == other.isMultiple; + && name.equals(other.name); } return false; } @@ -662,9 +657,6 @@ int h = 17; h = 37 * h + declaringNodeType.hashCode(); h = 37 * h + name.hashCode(); - h = 37 * h + (definesResidual ? 11 : 43); - h = 37 * h + (isMultiple ? 11 : 43); - h = 37 * h + requiredType; return h; } } @@ -676,16 +668,10 @@ Name declaringNodeType; Name name; - Name[] requiredPrimaryTypes; QNodeDefinitionId(QNodeDefinition def) { declaringNodeType = def.getDeclaringNodeType(); name = def.getName(); - requiredPrimaryTypes = def.getRequiredPrimaryTypes(); - if (requiredPrimaryTypes == null || requiredPrimaryTypes.length == 0) { - requiredPrimaryTypes = new Name[]{NameConstants.NT_BASE}; - } - Arrays.sort(requiredPrimaryTypes); } //---------------------------------------< java.lang.Object overrides > @@ -697,8 +683,7 @@ if (obj instanceof QNodeDefinitionId) { QNodeDefinitionId other = (QNodeDefinitionId) obj; return declaringNodeType.equals(other.declaringNodeType) - && name.equals(other.name) - && Arrays.equals(requiredPrimaryTypes, other.requiredPrimaryTypes); + && name.equals(other.name); } return false; } @@ -708,9 +693,6 @@ int h = 17; h = 37 * h + declaringNodeType.hashCode(); h = 37 * h + name.hashCode(); - for (int i = 0; i < requiredPrimaryTypes.length; i++) { - h = 37 * h + requiredPrimaryTypes[i].hashCode(); - } return h; } }