DNA SVN: r839 - trunk/dna-jcr/src/main/java/org/jboss/dna/jcr.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-04-17 10:23:57 -0400 (Fri, 17 Apr 2009)
New Revision: 839
Modified:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java
Log:
DNA-359 Session.refresh and Node.refresh Methods Not Supported
Added a short-circuit for 'refresh(UUID,boolean)' that checks whether the supplied UUID is that of the root, and if so 'refresh(boolean)' is called since it is significantly more efficient.
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java 2009-04-17 14:21:31 UTC (rev 838)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java 2009-04-17 14:23:57 UTC (rev 839)
@@ -268,6 +268,13 @@
*/
public void refresh( UUID nodeUuid,
boolean keepChanges ) throws RepositoryException {
+ assert nodeUuid != null;
+ // If the node being refreshed is the root node, then it's more efficient to refresh the whole workspace ...
+ if (this.root.equals(nodeUuid)) {
+ refresh(keepChanges);
+ return;
+ }
+
// Build the set of affected node UUIDs
Set<UUID> nodesUnderBranch = new HashSet<UUID>();
Stack<UUID> nodesToVisit = new Stack<UUID>();
16 years, 8 months
DNA SVN: r838 - in trunk/dna-jcr/src/main: resources/org/jboss/dna/jcr and 1 other directory.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-04-17 10:21:31 -0400 (Fri, 17 Apr 2009)
New Revision: 838
Modified:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java
trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties
Log:
DNA-359 Session.refresh and Node.refresh Methods Not Supported
Applied the patch that figures out whether any nodes that were removed from the branch were not deleted (meaning they were moved to another branch). Note that this does handle the case where a node was moved to another parent within the branch being refreshed.
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java 2009-04-17 13:54:29 UTC (rev 837)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java 2009-04-17 14:21:31 UTC (rev 838)
@@ -83,6 +83,7 @@
public static I18n unableToSaveNodeThatWasCreatedSincePreviousSave;
public static I18n unableToSetMultiValuedPropertyUsingSingleValue;
public static I18n unableToSetSingleValuedPropertyUsingMultipleValues;
+ public static I18n unableToRefreshBranchSinceAtLeastOneNodeMovedToParentOutsideOfBranch;
public static I18n allPropertyValuesMustHaveSameType;
public static I18n unableToRemoveRootNode;
@@ -126,7 +127,7 @@
public static I18n cannotRedefineProperty;
public static I18n autocreatedPropertyNeedsDefault;
public static I18n singleValuedPropertyNeedsSingleValuedDefault;
-
+
static {
try {
I18n.initialize(JcrI18n.class);
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java 2009-04-17 13:54:29 UTC (rev 837)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java 2009-04-17 14:21:31 UTC (rev 838)
@@ -268,12 +268,10 @@
*/
public void refresh( UUID nodeUuid,
boolean keepChanges ) throws RepositoryException {
- // Find the path of the given node ...
- Path path = getPathFor(nodeUuid);
-
// Build the set of affected node UUIDs
Set<UUID> nodesUnderBranch = new HashSet<UUID>();
Stack<UUID> nodesToVisit = new Stack<UUID>();
+ Set<UUID> nodesRemovedFromBranch = new HashSet<UUID>();
nodesToVisit.add(nodeUuid);
while (!nodesToVisit.isEmpty()) {
@@ -283,7 +281,9 @@
NodeInfo nodeInfo = null;
ChangedNodeInfo changedInfo = this.changedNodes.get(uuid);
if (changedInfo != null) {
- nodesToVisit.addAll(changedInfo.getUuidsForRemovedChildren());
+ Collection<UUID> removedNodes = changedInfo.getUuidsForRemovedChildren();
+ nodesToVisit.addAll(removedNodes);
+ nodesRemovedFromBranch.addAll(removedNodes);
nodeInfo = changedInfo;
} else {
nodeInfo = this.cachedNodes.get(uuid);
@@ -295,6 +295,23 @@
}
}
+ if (!nodesRemovedFromBranch.isEmpty()) {
+ // Skip any nodes that were moved from one parent to another within this branch ...
+ nodesRemovedFromBranch.removeAll(nodesUnderBranch);
+ // Skip any nodes that were actually deleted (not moved)...
+ nodesRemovedFromBranch.removeAll(this.deletedNodes.keySet());
+ if (!nodesRemovedFromBranch.isEmpty()) {
+ // There was at least one node that was moved from this branch to another parent outside this branch
+ Path path = getPathFor(nodeUuid);
+ String msg = JcrI18n.unableToRefreshBranchSinceAtLeastOneNodeMovedToParentOutsideOfBranch.text(path,
+ workspaceName());
+ throw new RepositoryException(msg);
+ }
+ }
+
+ // Find the path of the given node ...
+ Path path = getPathFor(nodeUuid);
+
if (keepChanges) {
// Keep the pending operations
for (UUID uuid : nodesUnderBranch) {
Modified: trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties
===================================================================
--- trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties 2009-04-17 13:54:29 UTC (rev 837)
+++ trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties 2009-04-17 14:21:31 UTC (rev 838)
@@ -73,6 +73,7 @@
unableToSaveNodeThatWasCreatedSincePreviousSave = Unable to save node "{0}" in workspace "{1}" because it was created since the last save
unableToSetMultiValuedPropertyUsingSingleValue = Unable to set existing multi-valued property "{0}" on node "{1}" in workspace "{2}" using single-value setter methods
unableToSetSingleValuedPropertyUsingMultipleValues = Unable to set existing single-valued property "{0}" on node "{1}" in workspace "{2}" using multi-value setter methods
+unableToRefreshBranchSinceAtLeastOneNodeMovedToParentOutsideOfBranch = Unable to refresh "{0}" in workspace "{2}" because at least one of its decendants was moved to another node outside of the branch that is not being refreshed
allPropertyValuesMustHaveSameType = All values of property "{0}" on node "{3}" in workspace "{4}" must all be {2} values (values were: {1})
unableToRemoveRootNode = Unable to remove the root node in workspace "{1}"
16 years, 8 months
DNA SVN: r837 - in trunk/dna-jcr/src: main/java/org/jboss/dna/jcr/cache and 1 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-04-17 09:54:29 -0400 (Fri, 17 Apr 2009)
New Revision: 837
Modified:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/cache/ChangedNodeInfo.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrTckTest.java
Log:
DNA-359 Session.refresh and Node.refresh Methods Not Supported
Applied the second patch, which corrects how the nodes under the refreshed node are computed (to also take into account nodes that were removed from the subgraph).
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java 2009-04-16 17:50:46 UTC (rev 836)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java 2009-04-17 13:54:29 UTC (rev 837)
@@ -280,10 +280,14 @@
UUID uuid = nodesToVisit.pop();
nodesUnderBranch.add(uuid);
- NodeInfo nodeInfo = cachedNodes.get(uuid);
- // Newly added nodes will be changedNodes but not cachedNodes
- if (nodeInfo == null) nodeInfo = changedNodes.get(uuid);
-
+ NodeInfo nodeInfo = null;
+ ChangedNodeInfo changedInfo = this.changedNodes.get(uuid);
+ if (changedInfo != null) {
+ nodesToVisit.addAll(changedInfo.getUuidsForRemovedChildren());
+ nodeInfo = changedInfo;
+ } else {
+ nodeInfo = this.cachedNodes.get(uuid);
+ }
if (nodeInfo != null) {
for (ChildNode childNode : nodeInfo.getChildren()) {
nodesToVisit.add(childNode.getUuid());
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/cache/ChangedNodeInfo.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/cache/ChangedNodeInfo.java 2009-04-16 17:50:46 UTC (rev 836)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/cache/ChangedNodeInfo.java 2009-04-17 13:54:29 UTC (rev 837)
@@ -23,6 +23,8 @@
*/
package org.jboss.dna.jcr.cache;
+import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
@@ -95,6 +97,15 @@
}
/**
+ * Return the original node information. May be null if this is a new node.
+ *
+ * @return the original node information
+ */
+ public NodeInfo getOriginal() {
+ return original;
+ }
+
+ /**
* {@inheritDoc}
*
* @see org.jboss.dna.jcr.cache.NodeInfo#getOriginalLocation()
@@ -195,6 +206,23 @@
}
/**
+ * Get the UUIDs for the children for this node that have been removed since the node was last persisted.
+ *
+ * @return a collection of the UUIDs of the removed children; never null but possibly empty
+ */
+ public Collection<UUID> getUuidsForRemovedChildren() {
+ if (original == null) return Collections.emptySet();
+
+ Set<UUID> removedChildren = new HashSet<UUID>();
+ for (ChildNode originalChildNode : original.getChildren()) {
+ if (!this.changedChildren.childrenByUuid.containsKey(originalChildNode.getUuid())) {
+ removedChildren.add(originalChildNode.getUuid());
+ }
+ }
+ return removedChildren;
+ }
+
+ /**
* Add a child to the children. This method does nothing if the child is already in the children.
*
* @param childName the name of the child that is to be added; may not be null
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrTckTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrTckTest.java 2009-04-16 17:50:46 UTC (rev 836)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrTckTest.java 2009-04-17 13:54:29 UTC (rev 837)
@@ -43,7 +43,11 @@
import org.apache.jackrabbit.test.api.NamespaceRegistryTest;
import org.apache.jackrabbit.test.api.NodeAddMixinTest;
import org.apache.jackrabbit.test.api.NodeCanAddMixinTest;
+import org.apache.jackrabbit.test.api.NodeItemIsModifiedTest;
+import org.apache.jackrabbit.test.api.NodeItemIsNewTest;
import org.apache.jackrabbit.test.api.NodeRemoveMixinTest;
+import org.apache.jackrabbit.test.api.PropertyItemIsModifiedTest;
+import org.apache.jackrabbit.test.api.PropertyItemIsNewTest;
import org.apache.jackrabbit.test.api.PropertyTest;
import org.apache.jackrabbit.test.api.RepositoryLoginTest;
import org.apache.jackrabbit.test.api.SessionUUIDTest;
@@ -213,12 +217,12 @@
addTestSuite(SetPropertyValueTest.class);
addTestSuite(SetPropertyConstraintViolationExceptionTest.class);
// addTestSuite(SetPropertyAssumeTypeTest.class);
- //
- // addTestSuite(NodeItemIsModifiedTest.class);
- // addTestSuite(NodeItemIsNewTest.class);
- // addTestSuite(PropertyItemIsModifiedTest.class);
- // addTestSuite(PropertyItemIsNewTest.class);
+ addTestSuite(NodeItemIsModifiedTest.class);
+ addTestSuite(NodeItemIsNewTest.class);
+ addTestSuite(PropertyItemIsModifiedTest.class);
+ addTestSuite(PropertyItemIsNewTest.class);
+
addTestSuite(NodeAddMixinTest.class);
addTestSuite(NodeCanAddMixinTest.class);
addTestSuite(NodeRemoveMixinTest.class);
16 years, 8 months
DNA SVN: r836 - in trunk: dna-jcr/src/main/java/org/jboss/dna/jcr and 1 other directory.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-04-16 13:50:46 -0400 (Thu, 16 Apr 2009)
New Revision: 836
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/JcrLexicon.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/JcrNtLexicon.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNodeTypeSource.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrBuiltinNodeTypeSource.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrLexicon.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNtLexicon.java
Log:
DNA-363 Define node types via CND files
The first step of several. This change moves some of the names in the JCR-related lexicons from the "dna-jcr" project's lexicons into the "dna-graph" project's corresponding lexicons.
Also added to the "nt:nodeType" and "nt:propertyDefinition" node types in JcrBuiltinNodeTypeSource were several additional property definitions new in JSR-283 . However, because the JSR-170 TCK unit tests are checking that only the JSR-170 property definitions are there, these new definitions have been commented out for the time being. (JSR-283 also makes all of the property definitions on "nt:nodeType", "nt:propertyDefinition", and "nt:childNodeDefinition" to be protected, though JSR-170 TCK unit tests are checking that they are not. These also were left as not being protected so that we are JSR-170 compliant.)
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/JcrLexicon.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/JcrLexicon.java 2009-04-16 16:08:24 UTC (rev 835)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/JcrLexicon.java 2009-04-16 17:50:46 UTC (rev 836)
@@ -46,4 +46,28 @@
public static final Name MIMETYPE = new BasicName(Namespace.URI, "mimeType");
public static final Name DATA = new BasicName(Namespace.URI, "data");
public static final Name LAST_MODIFIED = new BasicName(Namespace.URI, "lastModified");
+
+ // Names used in the node type definitions ...
+ public static final Name AUTO_CREATED = new BasicName(Namespace.URI, "autoCreated");
+ public static final Name CHILD_NODE_DEFINITION = new BasicName(Namespace.URI, "childNodeDefinition");
+ public static final Name DEFAULT_PRIMARY_TYPE = new BasicName(Namespace.URI, "defaultPrimaryType");
+ public static final Name DEFAULT_VALUES = new BasicName(Namespace.URI, "defaultValues");
+ public static final Name HAS_ORDERABLE_CHILD_NODES = new BasicName(Namespace.URI, "hasOrderableChildNodes");
+ public static final Name IS_ABSTRACT = new BasicName(Namespace.URI, "isAbstract");
+ public static final Name IS_FULL_TEXT_SEARCHABLE = new BasicName(Namespace.URI, "isFullTextSearchable");
+ public static final Name IS_MIXIN = new BasicName(Namespace.URI, "isMixin");
+ public static final Name IS_QUERY_ORDERABLE = new BasicName(Namespace.URI, "isQueryOrderable");
+ public static final Name IS_QUERYABLE = new BasicName(Namespace.URI, "isQueryable");
+ public static final Name MANDATORY = new BasicName(Namespace.URI, "mandatory");
+ public static final Name MULTIPLE = new BasicName(Namespace.URI, "multiple");
+ public static final Name ON_PARENT_VERSION = new BasicName(Namespace.URI, "onParentVersion");
+ public static final Name PRIMARY_ITEM_NAME = new BasicName(Namespace.URI, "primaryItemName");
+ public static final Name PROPERTY_DEFINITION = new BasicName(Namespace.URI, "propertyDefinition");
+ public static final Name PROTECTED = new BasicName(Namespace.URI, "protected");
+ public static final Name REQUIRED_PRIMARY_TYPES = new BasicName(Namespace.URI, "requiredPrimaryTypes");
+ public static final Name REQUIRED_TYPE = new BasicName(Namespace.URI, "requiredType");
+ public static final Name SAME_NAME_SIBLINGS = new BasicName(Namespace.URI, "sameNameSiblings");
+ public static final Name SUPERTYPES = new BasicName(Namespace.URI, "supertypes");
+ public static final Name VALUE_CONSTRAINTS = new BasicName(Namespace.URI, "valueConstraints");
+
}
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/JcrNtLexicon.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/JcrNtLexicon.java 2009-04-16 16:08:24 UTC (rev 835)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/JcrNtLexicon.java 2009-04-16 17:50:46 UTC (rev 836)
@@ -41,4 +41,10 @@
public static final Name FOLDER = new BasicName(Namespace.URI, "folder");
public static final Name RESOURCE = new BasicName(Namespace.URI, "resource");
public static final Name BASE = new BasicName(Namespace.URI, "base");
+
+ // Names used in the node type definitions ...
+ public static final Name NODE_TYPE = new BasicName(Namespace.URI, "nodeType");
+ public static final Name CHILD_NODE_DEFINITION = new BasicName(Namespace.URI, "childNodeDefinition");
+ public static final Name PROPERTY_DEFINITION = new BasicName(Namespace.URI, "propertyDefinition");
+
}
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNodeTypeSource.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNodeTypeSource.java 2009-04-16 16:08:24 UTC (rev 835)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNodeTypeSource.java 2009-04-16 17:50:46 UTC (rev 836)
@@ -27,6 +27,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import javax.jcr.PropertyType;
import javax.jcr.Value;
import org.jboss.dna.common.util.CheckArg;
import org.jboss.dna.graph.property.Name;
@@ -42,6 +43,12 @@
protected static final List<JcrNodeType> NO_SUPERTYPES = Collections.<JcrNodeType>emptyList();
protected static final List<JcrNodeDefinition> NO_CHILD_NODES = Collections.<JcrNodeDefinition>emptyList();
protected static final List<JcrPropertyDefinition> NO_PROPERTIES = Collections.<JcrPropertyDefinition>emptyList();
+ protected static final String[] ALL_PROPERTY_TYPES_WITH_UNDEFINED = new String[] {
+ PropertyType.nameFromValue(PropertyType.BINARY), PropertyType.nameFromValue(PropertyType.BOOLEAN),
+ PropertyType.nameFromValue(PropertyType.DATE), PropertyType.nameFromValue(PropertyType.DOUBLE),
+ PropertyType.nameFromValue(PropertyType.LONG), PropertyType.nameFromValue(PropertyType.NAME),
+ PropertyType.nameFromValue(PropertyType.PATH), PropertyType.nameFromValue(PropertyType.REFERENCE),
+ PropertyType.nameFromValue(PropertyType.STRING), PropertyType.nameFromValue(PropertyType.UNDEFINED),};
/** Indicates that the node type has no primary item name - added for readability */
protected static final Name NO_PRIMARY_ITEM_NAME = null;
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrBuiltinNodeTypeSource.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrBuiltinNodeTypeSource.java 2009-04-16 16:08:24 UTC (rev 835)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrBuiltinNodeTypeSource.java 2009-04-16 17:50:46 UTC (rev 836)
@@ -38,6 +38,14 @@
@Immutable
class JcrBuiltinNodeTypeSource extends AbstractJcrNodeTypeSource {
+ protected static final String[] ON_PARENT_VERSION_VALUES = new String[] {OnParentVersionBehavior.ABORT.getName(),
+ OnParentVersionBehavior.COMPUTE.getName(), OnParentVersionBehavior.COPY.getName(),
+ OnParentVersionBehavior.IGNORE.getName(), OnParentVersionBehavior.INITIALIZE.getName(),
+ OnParentVersionBehavior.VERSION.getName(),};
+
+ protected static final boolean NT_NODE_TYPES_PROTECTED = false; // JSR-170 requires they not be protected, but JSR-283 says
+ // they are.
+
/** The list of primary node types. */
private final List<JcrNodeType> nodeTypes;
@@ -58,28 +66,29 @@
Value ntBaseValue = new JcrValue(context.getValueFactories(), null, PropertyType.NAME, JcrNtLexicon.BASE);
JcrNodeType defined = new JcrNodeType(
- context,
- NO_NODE_TYPE_MANAGER,
- DnaLexicon.DEFINED,
- NO_SUPERTYPES,
- DnaLexicon.NODE_DEFINITON,
- NO_CHILD_NODES,
- Arrays.asList(new JcrPropertyDefinition[] {new JcrPropertyDefinition(
- context,
- null,
- DnaLexicon.NODE_DEFINITON,
- OnParentVersionBehavior.INITIALIZE.getJcrValue(),
- false,
- false,
- true,
- NO_DEFAULT_VALUES,
- PropertyType.STRING,
- NO_CONSTRAINTS,
- false),}),
- IS_A_MIXIN, UNORDERABLE_CHILD_NODES);
+ context,
+ NO_NODE_TYPE_MANAGER,
+ DnaLexicon.DEFINED,
+ NO_SUPERTYPES,
+ DnaLexicon.NODE_DEFINITON,
+ NO_CHILD_NODES,
+ Arrays.asList(new JcrPropertyDefinition[] {new JcrPropertyDefinition(
+ context,
+ null,
+ DnaLexicon.NODE_DEFINITON,
+ OnParentVersionBehavior.INITIALIZE.getJcrValue(),
+ false,
+ false,
+ true,
+ NO_DEFAULT_VALUES,
+ PropertyType.STRING,
+ NO_CONSTRAINTS,
+ false),}),
+ IS_A_MIXIN, UNORDERABLE_CHILD_NODES);
// Stubbing in child node and property definitions for now
- JcrNodeType base = new JcrNodeType(context, NO_NODE_TYPE_MANAGER, JcrNtLexicon.BASE, Arrays.asList(new JcrNodeType[] {defined}), NO_PRIMARY_ITEM_NAME,
- NO_CHILD_NODES, Arrays.asList(new JcrPropertyDefinition[] {
+ JcrNodeType base = new JcrNodeType(context, NO_NODE_TYPE_MANAGER, JcrNtLexicon.BASE,
+ Arrays.asList(new JcrNodeType[] {defined}), NO_PRIMARY_ITEM_NAME, NO_CHILD_NODES,
+ Arrays.asList(new JcrPropertyDefinition[] {
new JcrPropertyDefinition(context, null, JcrLexicon.PRIMARY_TYPE,
OnParentVersionBehavior.COMPUTE.getJcrValue(), true,
true, true, NO_DEFAULT_VALUES, PropertyType.NAME,
@@ -125,53 +134,55 @@
null,
JcrLexicon.AUTO_CREATED,
OnParentVersionBehavior.COPY.getJcrValue(),
- false, true, false, NO_DEFAULT_VALUES,
- PropertyType.BOOLEAN, NO_CONSTRAINTS,
- false),
+ false, true, NT_NODE_TYPES_PROTECTED,
+ NO_DEFAULT_VALUES, PropertyType.BOOLEAN,
+ NO_CONSTRAINTS, false),
new JcrPropertyDefinition(
context,
null,
JcrLexicon.DEFAULT_PRIMARY_TYPE,
OnParentVersionBehavior.COPY.getJcrValue(),
- false, false, false, NO_DEFAULT_VALUES,
- PropertyType.NAME, NO_CONSTRAINTS, false),
+ false, false, NT_NODE_TYPES_PROTECTED,
+ NO_DEFAULT_VALUES, PropertyType.NAME,
+ NO_CONSTRAINTS, false),
new JcrPropertyDefinition(
context,
null,
JcrLexicon.MANDATORY,
OnParentVersionBehavior.COPY.getJcrValue(),
- false, true, false, NO_DEFAULT_VALUES,
- PropertyType.BOOLEAN, NO_CONSTRAINTS,
- false),
+ false, true, NT_NODE_TYPES_PROTECTED,
+ NO_DEFAULT_VALUES, PropertyType.BOOLEAN,
+ NO_CONSTRAINTS, false),
new JcrPropertyDefinition(
context,
null,
JcrLexicon.NAME,
OnParentVersionBehavior.COPY.getJcrValue(),
- false, false, false, NO_DEFAULT_VALUES,
- PropertyType.NAME, NO_CONSTRAINTS, false),
+ false, false, NT_NODE_TYPES_PROTECTED,
+ NO_DEFAULT_VALUES, PropertyType.NAME,
+ NO_CONSTRAINTS, false),
new JcrPropertyDefinition(
context,
null,
JcrLexicon.ON_PARENT_VERSION,
OnParentVersionBehavior.COPY.getJcrValue(),
- false, true, false, NO_DEFAULT_VALUES,
- PropertyType.STRING, NO_CONSTRAINTS,
- false),
+ false, true, NT_NODE_TYPES_PROTECTED,
+ NO_DEFAULT_VALUES, PropertyType.STRING,
+ NO_CONSTRAINTS, false),
new JcrPropertyDefinition(
context,
null,
JcrLexicon.PROTECTED,
OnParentVersionBehavior.COPY.getJcrValue(),
- false, true, false, NO_DEFAULT_VALUES,
- PropertyType.BOOLEAN, NO_CONSTRAINTS,
- false),
+ false, true, NT_NODE_TYPES_PROTECTED,
+ NO_DEFAULT_VALUES, PropertyType.BOOLEAN,
+ NO_CONSTRAINTS, false),
new JcrPropertyDefinition(
context,
null,
JcrLexicon.REQUIRED_PRIMARY_TYPES,
OnParentVersionBehavior.COPY.getJcrValue(),
- false, true, false,
+ false, true, NT_NODE_TYPES_PROTECTED,
new Value[] {ntBaseValue},
PropertyType.NAME, NO_CONSTRAINTS, true),
new JcrPropertyDefinition(
@@ -179,9 +190,9 @@
null,
JcrLexicon.SAME_NAME_SIBLINGS,
OnParentVersionBehavior.COPY.getJcrValue(),
- false, true, false, NO_DEFAULT_VALUES,
- PropertyType.BOOLEAN, NO_CONSTRAINTS,
- false)}), NOT_MIXIN,
+ false, true, NT_NODE_TYPES_PROTECTED,
+ NO_DEFAULT_VALUES, PropertyType.BOOLEAN,
+ NO_CONSTRAINTS, false)}), NOT_MIXIN,
UNORDERABLE_CHILD_NODES);
JcrNodeType hierarchyNode = new JcrNodeType(
@@ -315,104 +326,142 @@
null,
JcrLexicon.AUTO_CREATED,
OnParentVersionBehavior.COPY.getJcrValue(),
- false, true, false, NO_DEFAULT_VALUES,
- PropertyType.BOOLEAN, NO_CONSTRAINTS,
- false),
+ false, true, NT_NODE_TYPES_PROTECTED,
+ NO_DEFAULT_VALUES, PropertyType.BOOLEAN,
+ NO_CONSTRAINTS, false),
new JcrPropertyDefinition(
context,
null,
JcrLexicon.DEFAULT_VALUES,
OnParentVersionBehavior.COPY.getJcrValue(),
- false, false, false, NO_DEFAULT_VALUES,
- PropertyType.UNDEFINED, NO_CONSTRAINTS,
- true),
+ false, false, NT_NODE_TYPES_PROTECTED,
+ NO_DEFAULT_VALUES, PropertyType.UNDEFINED,
+ NO_CONSTRAINTS, true),
+ // new JcrPropertyDefinition(
+ // context,
+ // null,
+ // JcrLexicon.IS_FULL_TEXT_SEARCHABLE,
+ // OnParentVersionBehavior.COPY.getJcrValue(),
+ // false, true, NT_NODE_TYPES_PROTECTED,
+ // NO_DEFAULT_VALUES, PropertyType.BOOLEAN,
+ // NO_CONSTRAINTS, false),
+ // new JcrPropertyDefinition(
+ // context,
+ // null,
+ // JcrLexicon.IS_QUERY_ORDERABLE,
+ // OnParentVersionBehavior.COPY.getJcrValue(),
+ // false, true, NT_NODE_TYPES_PROTECTED,
+ // NO_DEFAULT_VALUES, PropertyType.BOOLEAN,
+ // NO_CONSTRAINTS, false),
+ // new JcrPropertyDefinition(
+ // context,
+ // null,
+ // JcrLexicon.IS_QUERYABLE,
+ // OnParentVersionBehavior.COPY.getJcrValue(),
+ // false, true, NT_NODE_TYPES_PROTECTED,
+ // NO_DEFAULT_VALUES, PropertyType.BOOLEAN,
+ // NO_CONSTRAINTS, false),
new JcrPropertyDefinition(
context,
null,
JcrLexicon.MANDATORY,
OnParentVersionBehavior.COPY.getJcrValue(),
- false, true, false, NO_DEFAULT_VALUES,
- PropertyType.BOOLEAN, NO_CONSTRAINTS,
- false),
+ false, true, NT_NODE_TYPES_PROTECTED,
+ NO_DEFAULT_VALUES, PropertyType.BOOLEAN,
+ NO_CONSTRAINTS, false),
new JcrPropertyDefinition(
context,
null,
JcrLexicon.MULTIPLE,
OnParentVersionBehavior.COPY.getJcrValue(),
- false, true, false, NO_DEFAULT_VALUES,
- PropertyType.BOOLEAN, NO_CONSTRAINTS,
- false),
+ false, true, NT_NODE_TYPES_PROTECTED,
+ NO_DEFAULT_VALUES, PropertyType.BOOLEAN,
+ NO_CONSTRAINTS, false),
new JcrPropertyDefinition(
context,
null,
JcrLexicon.NAME,
OnParentVersionBehavior.COPY.getJcrValue(),
- false, false, false, NO_DEFAULT_VALUES,
- PropertyType.NAME, NO_CONSTRAINTS, false),
+ false, false, NT_NODE_TYPES_PROTECTED,
+ NO_DEFAULT_VALUES, PropertyType.NAME,
+ NO_CONSTRAINTS, false),
new JcrPropertyDefinition(
context,
null,
JcrLexicon.ON_PARENT_VERSION,
OnParentVersionBehavior.COPY.getJcrValue(),
- false, true, false, NO_DEFAULT_VALUES,
- PropertyType.STRING, NO_CONSTRAINTS, false),
+ false, true, NT_NODE_TYPES_PROTECTED,
+ NO_DEFAULT_VALUES, PropertyType.STRING,
+ ON_PARENT_VERSION_VALUES, false),
new JcrPropertyDefinition(
context,
null,
JcrLexicon.PROTECTED,
OnParentVersionBehavior.COPY.getJcrValue(),
- false, true, false, NO_DEFAULT_VALUES,
- PropertyType.BOOLEAN, NO_CONSTRAINTS,
- false),
+ false, true, NT_NODE_TYPES_PROTECTED,
+ NO_DEFAULT_VALUES, PropertyType.BOOLEAN,
+ NO_CONSTRAINTS, false),
new JcrPropertyDefinition(
context,
null,
JcrLexicon.REQUIRED_TYPE,
OnParentVersionBehavior.COPY.getJcrValue(),
- false, true, false, NO_DEFAULT_VALUES,
- PropertyType.STRING, NO_CONSTRAINTS, false),
+ false, true, NT_NODE_TYPES_PROTECTED,
+ NO_DEFAULT_VALUES, PropertyType.STRING,
+ ALL_PROPERTY_TYPES_WITH_UNDEFINED, false),
new JcrPropertyDefinition(
context,
null,
JcrLexicon.VALUE_CONSTRAINTS,
OnParentVersionBehavior.COPY.getJcrValue(),
- false, false, false, NO_DEFAULT_VALUES,
- PropertyType.STRING, NO_CONSTRAINTS, true)}),
- NOT_MIXIN, UNORDERABLE_CHILD_NODES);
+ false, false, NT_NODE_TYPES_PROTECTED,
+ NO_DEFAULT_VALUES, PropertyType.STRING,
+ NO_CONSTRAINTS, true)}), NOT_MIXIN,
+ UNORDERABLE_CHILD_NODES);
JcrNodeType nodeType = new JcrNodeType(context, NO_NODE_TYPE_MANAGER, JcrNtLexicon.NODE_TYPE,
Arrays.asList(new JcrNodeType[] {base}), NO_PRIMARY_ITEM_NAME,
Arrays.asList(new JcrNodeDefinition[] {
new JcrNodeDefinition(context, null, JcrLexicon.CHILD_NODE_DEFINITION,
OnParentVersionBehavior.VERSION.getJcrValue(), false,
- false, false, true, JcrNtLexicon.CHILD_NODE_DEFINITION,
+ false, NT_NODE_TYPES_PROTECTED, true,
+ JcrNtLexicon.CHILD_NODE_DEFINITION,
new JcrNodeType[] {childNodeDefinition}),
new JcrNodeDefinition(context, null, JcrLexicon.PROPERTY_DEFINITION,
OnParentVersionBehavior.VERSION.getJcrValue(), false,
- false, false, true, JcrNtLexicon.PROPERTY_DEFINITION,
+ false, NT_NODE_TYPES_PROTECTED, true,
+ JcrNtLexicon.PROPERTY_DEFINITION,
new JcrNodeType[] {propertyDefinition})}),
Arrays.asList(new JcrPropertyDefinition[] {
new JcrPropertyDefinition(context, null, JcrLexicon.HAS_ORDERABLE_CHILD_NODES,
OnParentVersionBehavior.COPY.getJcrValue(), false,
- true, false, NO_DEFAULT_VALUES,
+ true, NT_NODE_TYPES_PROTECTED, NO_DEFAULT_VALUES,
PropertyType.BOOLEAN, NO_CONSTRAINTS, false),
+ // new JcrPropertyDefinition(context, null, JcrLexicon.IS_ABSTRACT,
+ // OnParentVersionBehavior.COPY.getJcrValue(), false,
+ // true, NT_NODE_TYPES_PROTECTED, NO_DEFAULT_VALUES, PropertyType.BOOLEAN,
+ // NO_CONSTRAINTS, false),
new JcrPropertyDefinition(context, null, JcrLexicon.IS_MIXIN,
OnParentVersionBehavior.COPY.getJcrValue(), false,
- true, false, NO_DEFAULT_VALUES,
+ true, NT_NODE_TYPES_PROTECTED, NO_DEFAULT_VALUES,
PropertyType.BOOLEAN, NO_CONSTRAINTS, false),
+ // new JcrPropertyDefinition(context, null, JcrLexicon.IS_QUERYABLE,
+ // OnParentVersionBehavior.COPY.getJcrValue(), false,
+ // true, NT_NODE_TYPES_PROTECTED, NO_DEFAULT_VALUES, PropertyType.BOOLEAN,
+ // NO_CONSTRAINTS, false),
new JcrPropertyDefinition(context, null, JcrLexicon.NODE_TYPE_NAME,
OnParentVersionBehavior.COPY.getJcrValue(), false,
- true, false, NO_DEFAULT_VALUES, PropertyType.NAME,
- NO_CONSTRAINTS, false),
+ true, NT_NODE_TYPES_PROTECTED, NO_DEFAULT_VALUES,
+ PropertyType.NAME, NO_CONSTRAINTS, false),
new JcrPropertyDefinition(context, null, JcrLexicon.PRIMARY_ITEM_NAME,
OnParentVersionBehavior.COPY.getJcrValue(), false,
- false, false, NO_DEFAULT_VALUES, PropertyType.NAME,
- NO_CONSTRAINTS, false),
+ false, NT_NODE_TYPES_PROTECTED, NO_DEFAULT_VALUES,
+ PropertyType.NAME, NO_CONSTRAINTS, false),
new JcrPropertyDefinition(context, null, JcrLexicon.SUPERTYPES,
OnParentVersionBehavior.COPY.getJcrValue(), false,
- false, false, NO_DEFAULT_VALUES, PropertyType.NAME,
- NO_CONSTRAINTS, true),}), NOT_MIXIN,
- UNORDERABLE_CHILD_NODES);
+ false, NT_NODE_TYPES_PROTECTED, NO_DEFAULT_VALUES,
+ PropertyType.NAME, NO_CONSTRAINTS, true),}),
+ NOT_MIXIN, UNORDERABLE_CHILD_NODES);
JcrNodeType query = new JcrNodeType(context, NO_NODE_TYPE_MANAGER, JcrNtLexicon.QUERY,
Arrays.asList(new JcrNodeType[] {base}), NO_PRIMARY_ITEM_NAME, NO_CHILD_NODES,
@@ -585,9 +634,9 @@
// NOT_MIXIN, UNORDERABLE_CHILD_NODES);
// Disabling version-related types until DNA supports versioning, as per section 4.11 of the 1.0.1 specification
- nodeTypes.addAll(Arrays.asList(new JcrNodeType[] {defined, base, unstructured, childNodeDefinition, file, folder, frozenNode,
- hierarchyNode, linkedFile, nodeType, propertyDefinition, query, resource, nodeType /*, version, versionHistory,
- versionLabels, versionedChild */}));
+ nodeTypes.addAll(Arrays.asList(new JcrNodeType[] {defined, base, unstructured, childNodeDefinition, file, folder,
+ frozenNode, hierarchyNode, linkedFile, nodeType, propertyDefinition, query, resource, nodeType /*, version, versionHistory,
+ versionLabels, versionedChild */}));
JcrNodeType lockable = new JcrNodeType(context, NO_NODE_TYPE_MANAGER, JcrMixLexicon.LOCKABLE, NO_SUPERTYPES,
NO_PRIMARY_ITEM_NAME, NO_CHILD_NODES, Arrays.asList(new JcrPropertyDefinition[] {
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrLexicon.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrLexicon.java 2009-04-16 16:08:24 UTC (rev 835)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrLexicon.java 2009-04-16 17:50:46 UTC (rev 836)
@@ -31,47 +31,29 @@
*/
class JcrLexicon extends org.jboss.dna.graph.JcrLexicon {
- public static final Name AUTO_CREATED = new BasicName(Namespace.URI, "autoCreated");
public static final Name BASE_VERSION = new BasicName(Namespace.URI, "baseVersion");
- public static final Name CHILD_NODE_DEFINITION = new BasicName(Namespace.URI, "childNodeDefinition");
public static final Name CONTENT = new BasicName(Namespace.URI, "content");
public static final Name CREATED = new BasicName(Namespace.URI, "created");
public static final Name DATA = new BasicName(Namespace.URI, "data");
- public static final Name DEFAULT_PRIMARY_TYPE = new BasicName(Namespace.URI, "defaultPrimaryType");
- public static final Name DEFAULT_VALUES = new BasicName(Namespace.URI, "defaultValues");
public static final Name ENCODING = new BasicName(Namespace.URI, "encoding");
public static final Name FROZEN_MIXIN_TYPES = new BasicName(Namespace.URI, "frozenMixinTypes");
public static final Name FROZEN_NODE = new BasicName(Namespace.URI, "frozenNode");
public static final Name FROZEN_PRIMARY_TYPE = new BasicName(Namespace.URI, "frozenPrimaryType");
public static final Name FROZEN_UUID = new BasicName(Namespace.URI, "frozenUuid");
- public static final Name HAS_ORDERABLE_CHILD_NODES = new BasicName(Namespace.URI, "hasOrderableChildNodes");
public static final Name IS_CHECKED_OUT = new BasicName(Namespace.URI, "isCheckedOut");
- public static final Name IS_MIXIN = new BasicName(Namespace.URI, "isMixin");
public static final Name LANGUAGE = new BasicName(Namespace.URI, "language");
public static final Name LAST_MODIFIED = new BasicName(Namespace.URI, "lastModified");
public static final Name LOCK_IS_DEEP = new BasicName(Namespace.URI, "lockIsDeep");
public static final Name LOCK_OWNER = new BasicName(Namespace.URI, "lockOwner");
- public static final Name MANDATORY = new BasicName(Namespace.URI, "mandatory");
public static final Name MERGE_FAILED = new BasicName(Namespace.URI, "mergeFailed");
- public static final Name MULTIPLE = new BasicName(Namespace.URI, "multiple");
- public static final Name NAME = new BasicName(Namespace.URI, "name");
public static final Name NODE_TYPES = new BasicName(Namespace.URI, "nodeTypes");
public static final Name NODE_TYPE_NAME = new BasicName(Namespace.URI, "nodeTypeName");
- public static final Name ON_PARENT_VERSION = new BasicName(Namespace.URI, "onParentVersion");
public static final Name PREDECESSORS = new BasicName(Namespace.URI, "predecessors");
- public static final Name PRIMARY_ITEM_NAME = new BasicName(Namespace.URI, "primaryItemName");
- public static final Name PROPERTY_DEFINITION = new BasicName(Namespace.URI, "propertyDefinition");
- public static final Name PROTECTED = new BasicName(Namespace.URI, "protected");
- public static final Name REQUIRED_PRIMARY_TYPES = new BasicName(Namespace.URI, "requiredPrimaryTypes");
- public static final Name REQUIRED_TYPE = new BasicName(Namespace.URI, "requiredType");
public static final Name ROOT = new BasicName(Namespace.URI, "root");
public static final Name ROOT_VERSION = new BasicName(Namespace.URI, "rootVersion");
- public static final Name SAME_NAME_SIBLINGS = new BasicName(Namespace.URI, "sameNameSiblings");
public static final Name STATEMENT = new BasicName(Namespace.URI, "statement");
public static final Name SUCCESSORS = new BasicName(Namespace.URI, "successors");
- public static final Name SUPERTYPES = new BasicName(Namespace.URI, "supertypes");
public static final Name SYSTEM = new BasicName(Namespace.URI, "system");
- public static final Name VALUE_CONSTRAINTS = new BasicName(Namespace.URI, "valueConstraints");
public static final Name VERSIONABLE_UUID = new BasicName(Namespace.URI, "versionableUuid");
public static final Name VERSION_HISTORY = new BasicName(Namespace.URI, "versionHistory");
public static final Name VERSION_LABELS = new BasicName(Namespace.URI, "versionLabels");
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNtLexicon.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNtLexicon.java 2009-04-16 16:08:24 UTC (rev 835)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNtLexicon.java 2009-04-16 17:50:46 UTC (rev 836)
@@ -28,12 +28,9 @@
public class JcrNtLexicon extends org.jboss.dna.graph.JcrNtLexicon {
- public static final Name CHILD_NODE_DEFINITION = new BasicName(Namespace.URI, "childNodeDefinition");
public static final Name FROZEN_NODE = new BasicName(Namespace.URI, "frozenNode");
public static final Name HIERARCHY_NODE = new BasicName(Namespace.URI, "hierarchyNode");
public static final Name LINKED_FILE = new BasicName(Namespace.URI, "linkedFile");
- public static final Name NODE_TYPE = new BasicName(Namespace.URI, "nodeType");
- public static final Name PROPERTY_DEFINITION = new BasicName(Namespace.URI, "propertyDefinition");
public static final Name QUERY = new BasicName(Namespace.URI, "query");
public static final Name VERSION = new BasicName(Namespace.URI, "version");
public static final Name VERSIONED_CHILD = new BasicName(Namespace.URI, "versionedChild");
16 years, 8 months
DNA SVN: r835 - in trunk/dna-jcr/src: main/java/org/jboss/dna/jcr/cache and 2 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-04-16 12:08:24 -0400 (Thu, 16 Apr 2009)
New Revision: 835
Added:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/cache/NewNodeInfo.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/cache/NewNodeInfoTest.java
Modified:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrItem.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrProperty.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/cache/ChangedNodeInfo.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/cache/ImmutableNodeInfo.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/cache/NodeInfo.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/cache/PropertyInfo.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrItemTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/cache/ChangedNodeInfoTest.java
Log:
DNA-362 AbstractJcrItem.isNew and isModified Are Not Implemented
Applied the patch, but rather than have ChangedNodeInfo contain a boolean that says whether its new, there is now a NewNodeInfo (that extends ChangedNodeInfo) that IMO makes it more obvious that this is a new node and clears up the places in SessionCache that instantiate it.
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrItem.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrItem.java 2009-04-16 15:31:14 UTC (rev 834)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrItem.java 2009-04-16 16:08:24 UTC (rev 835)
@@ -82,26 +82,6 @@
/**
* {@inheritDoc}
*
- * @return <code>false</code>
- * @see javax.jcr.Item#isModified()
- */
- public final boolean isModified() {
- return false;
- }
-
- /**
- * {@inheritDoc}
- *
- * @return <code>false</code>
- * @see javax.jcr.Item#isNew()
- */
- public final boolean isNew() {
- return false;
- }
-
- /**
- * {@inheritDoc}
- *
* @see javax.jcr.Item#isSame(javax.jcr.Item)
*/
public boolean isSame( Item otherItem ) throws RepositoryException {
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java 2009-04-16 15:31:14 UTC (rev 834)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java 2009-04-16 16:08:24 UTC (rev 835)
@@ -1448,6 +1448,34 @@
/**
* {@inheritDoc}
*
+ * @see javax.jcr.Item#isModified()
+ */
+ public final boolean isModified() {
+ try {
+ return nodeInfo().isModified();
+ }
+ catch (RepositoryException re) {
+ throw new IllegalStateException(re);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Item#isNew()
+ */
+ public final boolean isNew() {
+ try {
+ return nodeInfo().isNew();
+ }
+ catch (RepositoryException re) {
+ throw new IllegalStateException(re);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
* @throws UnsupportedOperationException always
* @see javax.jcr.Node#merge(java.lang.String, boolean)
*/
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrProperty.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrProperty.java 2009-04-16 15:31:14 UTC (rev 834)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrProperty.java 2009-04-16 16:08:24 UTC (rev 835)
@@ -154,6 +154,34 @@
/**
* {@inheritDoc}
*
+ * @see javax.jcr.Item#isModified()
+ */
+ public final boolean isModified() {
+ try {
+ return propertyInfo().isModified();
+ }
+ catch (RepositoryException re) {
+ throw new IllegalStateException(re);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Item#isNew()
+ */
+ public final boolean isNew() {
+ try {
+ return propertyInfo().isNew();
+ }
+ catch (RepositoryException re) {
+ throw new IllegalStateException(re);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
* @return false
* @see javax.jcr.Item#isNode()
*/
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java 2009-04-16 15:31:14 UTC (rev 834)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java 2009-04-16 16:08:24 UTC (rev 835)
@@ -77,6 +77,7 @@
import org.jboss.dna.jcr.cache.EmptyChildren;
import org.jboss.dna.jcr.cache.ImmutableChildren;
import org.jboss.dna.jcr.cache.ImmutableNodeInfo;
+import org.jboss.dna.jcr.cache.NewNodeInfo;
import org.jboss.dna.jcr.cache.NodeInfo;
import org.jboss.dna.jcr.cache.PropertyInfo;
import com.google.common.base.ReferenceType;
@@ -728,7 +729,8 @@
Property dnaProp = propertyFactory.create(name, objValue);
// Create the property info ...
- PropertyInfo newProperty = new PropertyInfo(id, definition.getId(), propertyType, dnaProp, definition.isMultiple());
+ PropertyInfo newProperty = new PropertyInfo(id, definition.getId(), propertyType, dnaProp, definition.isMultiple(),
+ existing == null, existing != null);
// Finally update the cached information and record the change ...
node.setProperty(newProperty, factories());
@@ -841,7 +843,8 @@
Property dnaProp = propertyFactory.create(name, objValues);
// Create the property info ...
- PropertyInfo newProperty = new PropertyInfo(id, definition.getId(), propertyType, dnaProp, definition.isMultiple());
+ PropertyInfo newProperty = new PropertyInfo(id, definition.getId(), propertyType, dnaProp, definition.isMultiple(),
+ existing == null, existing != null);
// Finally update the cached information and record the change ...
node.setProperty(newProperty, factories());
@@ -1040,7 +1043,7 @@
JcrPropertyDefinition defn = (JcrPropertyDefinition)propertyDefinition;
org.jboss.dna.graph.property.Property uuidProperty = propertyFactory.create(JcrLexicon.UUID, desiredUuid);
PropertyInfo propInfo = new PropertyInfo(propId, defn.getId(), PropertyType.STRING, uuidProperty,
- defn.isMultiple());
+ defn.isMultiple(), true, false);
properties.put(JcrLexicon.UUID, propInfo);
}
@@ -1052,7 +1055,8 @@
false);
PropertyDefinitionId primaryTypeDefinitionId = primaryTypeDefn.getId();
PropertyInfo primaryTypeInfo = new PropertyInfo(new PropertyId(desiredUuid, primaryTypeProp.getName()),
- primaryTypeDefinitionId, PropertyType.NAME, primaryTypeProp, false);
+ primaryTypeDefinitionId, PropertyType.NAME, primaryTypeProp, false,
+ true, false);
properties.put(primaryTypeProp.getName(), primaryTypeInfo);
// Create the property info for the "dna:nodeDefinition" child property ...
@@ -1065,15 +1069,13 @@
PropertyDefinitionId nodeDefnDefinitionId = nodeDefnDefn.getId();
PropertyInfo nodeDefinitionInfo = new PropertyInfo(new PropertyId(desiredUuid, nodeDefinitionProp.getName()),
nodeDefnDefinitionId, PropertyType.STRING, nodeDefinitionProp,
- true);
+ true, true, false);
properties.put(nodeDefinitionProp.getName(), nodeDefinitionInfo);
}
// Now create the child node info, putting it in the changed map (and not the cache map!) ...
- NodeInfo info = new ImmutableNodeInfo(location, primaryTypeName, null, definition.getId(), node.getUuid(), null,
- properties);
- ChangedNodeInfo changedInfo = new ChangedNodeInfo(info);
- changedNodes.put(desiredUuid, changedInfo);
+ NewNodeInfo newInfo = new NewNodeInfo(location, primaryTypeName, definition.getId(), node.getUuid(), properties);
+ changedNodes.put(desiredUuid, newInfo);
// ---------------------------------------
// Now record the changes to the store ...
@@ -1741,7 +1743,7 @@
// Record the property in the node information ...
PropertyId propId = new PropertyId(uuid, name);
JcrPropertyDefinition defn = (JcrPropertyDefinition)propertyDefinition;
- PropertyInfo propInfo = new PropertyInfo(propId, defn.getId(), propertyType, dnaProp, defn.isMultiple());
+ PropertyInfo propInfo = new PropertyInfo(propId, defn.getId(), propertyType, dnaProp, defn.isMultiple(), false, false);
props.put(name, propInfo);
}
@@ -1757,7 +1759,8 @@
false);
PropertyId propId = new PropertyId(uuid, JcrLexicon.UUID);
JcrPropertyDefinition defn = (JcrPropertyDefinition)propertyDefinition;
- PropertyInfo propInfo = new PropertyInfo(propId, defn.getId(), PropertyType.STRING, uuidProperty, defn.isMultiple());
+ PropertyInfo propInfo = new PropertyInfo(propId, defn.getId(), PropertyType.STRING, uuidProperty, defn.isMultiple(),
+ false, false);
props.put(JcrLexicon.UUID, propInfo);
} else {
// Make sure there is NOT a "jcr:uuid" property ...
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/cache/ChangedNodeInfo.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/cache/ChangedNodeInfo.java 2009-04-16 15:31:14 UTC (rev 834)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/cache/ChangedNodeInfo.java 2009-04-16 16:08:24 UTC (rev 835)
@@ -379,4 +379,22 @@
changedProperties.put(name, null);
return changed;
}
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.jcr.cache.NodeInfo#isNew()
+ */
+ public boolean isNew() {
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.jcr.cache.NodeInfo#isModified()
+ */
+ public boolean isModified() {
+ return true;
+ }
}
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/cache/ImmutableNodeInfo.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/cache/ImmutableNodeInfo.java 2009-04-16 15:31:14 UTC (rev 834)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/cache/ImmutableNodeInfo.java 2009-04-16 16:08:24 UTC (rev 835)
@@ -179,4 +179,24 @@
public PropertyInfo getProperty( Name name ) {
return this.properties.get(name);
}
+
+ /**
+ *
+ * {@inheritDoc}
+ * @return {@code false} always as this object represents unmodified nodes only
+ * @see org.jboss.dna.jcr.cache.NodeInfo#isNew()
+ */
+ public boolean isNew() {
+ return false;
+ }
+
+ /**
+ *
+ * {@inheritDoc}
+ * @return {@code false} always as this object represents unmodified nodes only
+ * @see org.jboss.dna.jcr.cache.NodeInfo#isModified()
+ */
+ public boolean isModified() {
+ return false;
+ }
}
Added: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/cache/NewNodeInfo.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/cache/NewNodeInfo.java (rev 0)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/cache/NewNodeInfo.java 2009-04-16 16:08:24 UTC (rev 835)
@@ -0,0 +1,79 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * Unless otherwise indicated, all code in JBoss DNA is licensed
+ * to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.jcr.cache;
+
+import java.util.Map;
+import java.util.UUID;
+import org.jboss.dna.graph.Location;
+import org.jboss.dna.graph.property.Name;
+import org.jboss.dna.jcr.NodeDefinitionId;
+
+/**
+ *
+ */
+public class NewNodeInfo extends ChangedNodeInfo {
+ /**
+ * Create an immutable NodeInfo instance.
+ *
+ * @param originalLocation the original location
+ * @param primaryTypeName the name of the node's primary type
+ * @param definition the definition used when creating the node
+ * @param parent the parent
+ * @param properties the unmodifiable map of properties; may be null if there are no properties
+ */
+ public NewNodeInfo( Location originalLocation,
+ Name primaryTypeName,
+ NodeDefinitionId definition,
+ UUID parent,
+ Map<Name, PropertyInfo> properties ) {
+ super(new ImmutableNodeInfo(originalLocation, primaryTypeName, null, definition, parent, null, properties));
+ }
+
+ /**
+ * {@inheritDoc}
+ * <p>
+ * Always returns true.
+ * </p>
+ *
+ * @see org.jboss.dna.jcr.cache.ChangedNodeInfo#isNew()
+ */
+ @Override
+ public boolean isNew() {
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ * <p>
+ * Always returns false, since a new node is not persisted yet.
+ * </p>
+ *
+ * @see org.jboss.dna.jcr.cache.ChangedNodeInfo#isModified()
+ */
+ @Override
+ public boolean isModified() {
+ return false;
+ }
+
+}
Property changes on: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/cache/NewNodeInfo.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/cache/NodeInfo.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/cache/NodeInfo.java 2009-04-16 15:31:14 UTC (rev 834)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/cache/NodeInfo.java 2009-04-16 16:08:24 UTC (rev 835)
@@ -104,4 +104,23 @@
* @return the property information, or null if this node has no property with the supplied name
*/
public PropertyInfo getProperty( Name name );
+
+ /**
+ * Indicates whether the node represented by this {@link NodeInfo} is new (i.e., does not yet exist in the persistent
+ * repository).
+ *
+ * @return {@code true} if the node represented by this {@link NodeInfo} has not yet been saved to the persistent repository.
+ * @see javax.jcr.Item#isNew()
+ */
+ public boolean isNew();
+
+ /**
+ * Indicates whether the node represented by this {@link NodeInfo} is modified (i.e., exists in the persistent repository with
+ * different child items).
+ *
+ * @return {@code true} if the immediate child items of the node represented by this {@link NodeInfo} have been modified since
+ * the last time the node was saved to the persistent repository
+ * @see javax.jcr.Item#isModified()
+ */
+ public boolean isModified();
}
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/cache/PropertyInfo.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/cache/PropertyInfo.java 2009-04-16 15:31:14 UTC (rev 834)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/cache/PropertyInfo.java 2009-04-16 16:08:24 UTC (rev 835)
@@ -48,17 +48,26 @@
private final Property dnaProperty;
private final int propertyType;
private final boolean multiValued;
+ private final boolean isNew;
+ private final boolean isModified;
public PropertyInfo( PropertyId propertyId,
PropertyDefinitionId definitionId,
int propertyType,
Property dnaProperty,
- boolean multiValued ) {
+ boolean multiValued,
+ boolean isNew,
+ boolean isModified ) {
this.propertyId = propertyId;
this.definitionId = definitionId;
this.propertyType = propertyType;
this.dnaProperty = dnaProperty;
this.multiValued = multiValued;
+ this.isNew = isNew;
+ this.isModified = isModified;
+
+ assert isNew ? !isModified : true;
+ assert isModified ? !isNew : true;
}
/**
@@ -123,6 +132,27 @@
}
/**
+ * Indicates whether this property/value combination is new (i.e., does not yet exist in the persistent repository).
+ *
+ * @return {@code true} if the property has not yet been saved to the persistent repository.
+ * @see javax.jcr.Item#isNew()
+ */
+ public boolean isNew() {
+ return this.isNew;
+ }
+
+ /**
+ * Indicates whether this property/value combination is modified (i.e., exists in the persistent repository with a different
+ * value or values).
+ *
+ * @return {@code true} if the property has been modified since the last time it was saved to the persistent repository
+ * @see javax.jcr.Item#isModified()
+ */
+ public boolean isModified() {
+ return this.isModified;
+ }
+
+ /**
* {@inheritDoc}
*
* @see java.lang.Object#hashCode()
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrItemTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrItemTest.java 2009-04-16 15:31:14 UTC (rev 834)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrItemTest.java 2009-04-16 16:08:24 UTC (rev 835)
@@ -73,6 +73,14 @@
return false;
}
+ public boolean isNew() {
+ return false;
+ }
+
+ public boolean isModified() {
+ return false;
+ }
+
public void refresh( boolean keepChanges ) {
throw new UnsupportedOperationException();
}
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/cache/ChangedNodeInfoTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/cache/ChangedNodeInfoTest.java 2009-04-16 15:31:14 UTC (rev 834)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/cache/ChangedNodeInfoTest.java 2009-04-16 16:08:24 UTC (rev 835)
@@ -151,6 +151,16 @@
}
@Test
+ public void shouldNotBeNew() {
+ assertThat(changes.isNew(), is(false));
+ }
+
+ @Test
+ public void shouldBeModified() {
+ assertThat(changes.isModified(), is(true));
+ }
+
+ @Test
public void shouldHaveLocationFromOriginal() {
assertThat(changes.getOriginalLocation(), is(sameInstance(location)));
}
Added: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/cache/NewNodeInfoTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/cache/NewNodeInfoTest.java (rev 0)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/cache/NewNodeInfoTest.java 2009-04-16 16:08:24 UTC (rev 835)
@@ -0,0 +1,672 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * Unless otherwise indicated, all code in JBoss DNA is licensed
+ * to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.jcr.cache;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.hamcrest.core.IsNull.nullValue;
+import static org.hamcrest.core.IsSame.sameInstance;
+import static org.jboss.dna.jcr.cache.IsNodeInfoWithChildrenHavingNames.hasChildren;
+import static org.jboss.dna.jcr.cache.IsNodeInfoWithChildrenHavingUuids.hasChildren;
+import static org.junit.Assert.assertThat;
+import static org.junit.matchers.JUnitMatchers.hasItems;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.stub;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import org.jboss.dna.graph.ExecutionContext;
+import org.jboss.dna.graph.JcrLexicon;
+import org.jboss.dna.graph.Location;
+import org.jboss.dna.graph.property.Name;
+import org.jboss.dna.graph.property.PathFactory;
+import org.jboss.dna.graph.property.Property;
+import org.jboss.dna.graph.property.Path.Segment;
+import org.jboss.dna.jcr.NodeDefinitionId;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class NewNodeInfoTest {
+
+ private ExecutionContext context;
+ private PathFactory pathFactory;
+ private UUID uuid;
+ private Name primaryTypeName;
+ private Name[] requiredPrimaryTypes;
+ private Location location;
+ private NodeDefinitionId definitionId;
+ private Map<Name, PropertyInfo> properties;
+ private ChangedNodeInfo changes;
+
+ @Before
+ public void beforeEach() {
+ context = new ExecutionContext();
+ context.getNamespaceRegistry().register("acme", "http://example.com/acme");
+ pathFactory = context.getValueFactories().getPathFactory();
+
+ // Set up the original ...
+ uuid = UUID.randomUUID();
+ location = Location.create(uuid);
+ primaryTypeName = name("acme:geniusType");
+ requiredPrimaryTypes = new Name[] {name("acme:requiredTypeA"), name("acme:requiredTypeB")};
+ definitionId = new NodeDefinitionId(name("acme:geniusContainerType"), name("acme:geniuses"), requiredPrimaryTypes);
+ properties = new HashMap<Name, PropertyInfo>();
+
+ // Create the changed node representation ...
+ changes = new NewNodeInfo(location, primaryTypeName, definitionId, uuid, properties);
+ }
+
+ protected Name name( String name ) {
+ return context.getValueFactories().getNameFactory().create(name);
+ }
+
+ protected Segment segment( String segment ) {
+ return pathFactory.createSegment(segment);
+ }
+
+ /**
+ * Utility to set a property to the original node representation. This will replace any existing property with the same name.
+ *
+ * @param name the name of the property; may not be null
+ * @return the new property representation; never null
+ */
+ protected PropertyInfo makePropertyInOriginal( String name ) {
+ Name propName = name(name);
+ PropertyInfo propertyInfo = mock(PropertyInfo.class);
+ stub(propertyInfo.getPropertyName()).toReturn(propName);
+ properties.put(propName, propertyInfo);
+ return propertyInfo;
+ }
+
+ /**
+ * Utility to change a property in the changed representation.
+ *
+ * @param name the name of the property to change; may not be null
+ * @return the new property; never null
+ */
+ protected PropertyInfo setPropertyInChanged( String name ) {
+ Name propName = name(name);
+ PropertyInfo propertyInfo = mock(PropertyInfo.class);
+ stub(propertyInfo.getPropertyName()).toReturn(propName);
+ changes.setProperty(propertyInfo, context.getValueFactories());
+ return propertyInfo;
+ }
+
+ protected ChildNode addChildInChanged( String childName ) {
+ ChildNode newChild = changes.addChild(name(childName), UUID.randomUUID(), pathFactory);
+ return newChild;
+ }
+
+ protected void removeChildFromChanged( ChildNode child ) {
+ // Verify that a child node with the supplied UUID is contained.
+ // Note that it may not be the same ChildNode instance if another SNS node with smaller index was removed
+ assertThat(changes.getChildren().getChild(child.getUuid()), is(notNullValue()));
+ // Now remove the child, making sure the result is the same as the next 'getChildren()' call ...
+ assertThat(changes.removeChild(child.getUuid(), pathFactory), is(notNullValue()));
+ // Verify it no longer exists ...
+ assertThat(changes.getChildren().getChild(child.getUuid()), is(nullValue()));
+ }
+
+ @Test
+ public void shouldBeNew() {
+ assertThat(changes.isNew(), is(true));
+ }
+
+ @Test
+ public void shouldNotBeModified() {
+ assertThat(changes.isModified(), is(false));
+ }
+
+ @Test
+ public void shouldInitiallyHaveLocation() {
+ assertThat(changes.getOriginalLocation(), is(sameInstance(location)));
+ }
+
+ @Test
+ public void shouldInitiallyHaveParentUuid() {
+ assertThat(changes.getParent(), is(sameInstance(uuid)));
+ }
+
+ @Test
+ public void shouldInitiallyHavePrimaryTypeName() {
+ assertThat(changes.getPrimaryTypeName(), is(sameInstance(primaryTypeName)));
+ }
+
+ @Test
+ public void shouldInitiallyHaveMixinNoTypeNames() {
+ assertThat(changes.getMixinTypeNames().size(), is(0));
+ }
+
+ @Test
+ public void shouldUpdateMixinTypeNamesWhenSettingJcrMixinTypeProperty() {
+ // Create the DNA property ...
+ Property mixinTypes = context.getPropertyFactory().create(JcrLexicon.MIXIN_TYPES, "dna:type1", "dna:type2");
+
+ // Modify the property ...
+ PropertyInfo newPropertyInfo = mock(PropertyInfo.class);
+ stub(newPropertyInfo.getPropertyName()).toReturn(mixinTypes.getName());
+ stub(newPropertyInfo.getProperty()).toReturn(mixinTypes);
+ PropertyInfo previous = changes.setProperty(newPropertyInfo, context.getValueFactories());
+ assertThat(previous, is(nullValue()));
+
+ // Verify that the mixin types were updated ...
+ assertThat(changes.getProperty(name("jcr:mixinTypes")), is(sameInstance(newPropertyInfo)));
+ assertThat(changes.getMixinTypeNames(), hasItems(name("dna:type2"), name("dna:type1")));
+ }
+
+ @Test
+ public void shouldHaveNodeDefinitionId() {
+ assertThat(changes.getDefinitionId(), is(sameInstance(definitionId)));
+ }
+
+ @Test
+ public void shouldHaveNoChildren() {
+ assertThat(changes.getChildren().size(), is(0));
+ }
+
+ @Test
+ public void shouldHaveChildrenAfterAddingChild() {
+ assertThat(changes.getChildren().size(), is(0));
+
+ // Add child ...
+ ChildNode childA1 = addChildInChanged("childA");
+ assertThat(changes.getChildren().size(), is(1));
+ assertThat(changes.getChildren(), hasChildren(segment("childA")));
+
+ // Add more children ...
+ ChildNode childB1 = addChildInChanged("childB");
+ ChildNode childA2 = addChildInChanged("childA");
+ ChildNode childA3 = addChildInChanged("childA");
+
+ // Verify that all children are there in the proper order ...
+ assertThat(changes.getChildren().size(), is(4));
+ assertThat(changes.getChildren(), hasChildren(segment("childA[1]"),
+ segment("childB[1]"),
+ segment("childA[2]"),
+ segment("childA[3]")));
+ assertThat(changes.getChildren(), hasChildren(childA1.getUuid(), childB1.getUuid(), childA2.getUuid(), childA3.getUuid()));
+ assertThat(changes.getChildren(), hasItems(childA1, childB1, childA2, childA3));
+ }
+
+ @Test
+ public void shouldHaveChildrenAfterAddingMultipleChildren() {
+ assertThat(changes.getChildren().size(), is(0));
+
+ // Add some children ...
+ ChildNode childA1 = addChildInChanged("childA");
+ ChildNode childB1 = addChildInChanged("childB");
+ ChildNode childA2 = addChildInChanged("childA");
+ assertThat(changes.getChildren().size(), is(3));
+
+ // Add some children in the changed representation ...
+ ChildNode childA3 = addChildInChanged("childA");
+ ChildNode childC1 = addChildInChanged("childC");
+ ChildNode childC2 = addChildInChanged("childC");
+
+ // Verify that all children are there in the proper order ...
+ assertThat(changes.getChildren().size(), is(6));
+ assertThat(changes.getChildren(), hasChildren(segment("childA[1]"),
+ segment("childB[1]"),
+ segment("childA[2]"),
+ segment("childA[3]"),
+ segment("childC[1]"),
+ segment("childC[2]")));
+ assertThat(changes.getChildren(), hasChildren(childA1.getUuid(),
+ childB1.getUuid(),
+ childA2.getUuid(),
+ childA3.getUuid(),
+ childC1.getUuid(),
+ childC2.getUuid()));
+ assertThat(changes.getChildren(), hasItems(childA1, childB1, childA2, childA3, childC1, childC2));
+ }
+
+ @Test
+ public void shouldHaveChildrenAfterAddingMultipleChildrenAndRemovingOthers() {
+ assertThat(changes.getChildren().size(), is(0));
+
+ // Add some children ...
+ ChildNode childA1 = addChildInChanged("childA");
+ ChildNode childB1 = addChildInChanged("childB");
+ ChildNode childA2 = addChildInChanged("childA");
+ assertThat(changes.getChildren().size(), is(3));
+
+ // Add some children in the changed representation ...
+ ChildNode childA3 = addChildInChanged("childA");
+ ChildNode childC1 = addChildInChanged("childC");
+ ChildNode childC2 = addChildInChanged("childC");
+
+ // Delete a child that was added and another that was an original ...
+ removeChildFromChanged(childC1);
+ removeChildFromChanged(childA2);
+
+ // Verify that all children are there in the proper order ...
+ assertThat(changes.getChildren().size(), is(4));
+ assertThat(changes.getChildren(), hasChildren(segment("childA[1]"),
+ segment("childB[1]"),
+ segment("childA[2]"),
+ segment("childC[1]")));
+ assertThat(changes.getChildren(), hasChildren(childA1.getUuid(), childB1.getUuid(), childA3.getUuid(), childC2.getUuid()));
+ }
+
+ @Test
+ public void shouldHaveChildrenAfterAddingMultipleChildrenAndThenRemovingThoseJustAdded() {
+ assertThat(changes.getChildren().size(), is(0));
+
+ // Add some children ...
+ ChildNode childA1 = addChildInChanged("childA");
+ ChildNode childB1 = addChildInChanged("childB");
+ ChildNode childA2 = addChildInChanged("childA");
+ assertThat(changes.getChildren().size(), is(3));
+
+ // Add some children in the changed representation ...
+ ChildNode childA3 = addChildInChanged("childA");
+ ChildNode childC1 = addChildInChanged("childC");
+ ChildNode childC2 = addChildInChanged("childC");
+
+ // Delete a child that was added and another that was an original...
+ removeChildFromChanged(childA3);
+ removeChildFromChanged(childC1); // causes replacement of 'childC2' with lower SNS index
+ removeChildFromChanged(childC2);
+
+ // Verify that all children are there in the proper order ...
+ assertThat(changes.getChildren().size(), is(3));
+ assertThat(changes.getChildren(), hasChildren(segment("childA[1]"), segment("childB[1]"), segment("childA[2]")));
+ assertThat(changes.getChildren(), hasChildren(childA1.getUuid(), childB1.getUuid(), childA2.getUuid()));
+
+ // Do it again, but change the order of delete to delete from the back ...
+
+ // Add some children in the changed representation ...
+ childA3 = addChildInChanged("childA");
+ childC1 = addChildInChanged("childC");
+ childC2 = addChildInChanged("childC");
+
+ // Delete a child that was added and another that was an original ...
+ removeChildFromChanged(childC2);
+ removeChildFromChanged(childC1);
+ removeChildFromChanged(childA3);
+
+ // Verify that all children are there in the proper order ...
+ assertThat(changes.getChildren().size(), is(3));
+ assertThat(changes.getChildren(), hasChildren(segment("childA[1]"), segment("childB[1]"), segment("childA[2]")));
+ assertThat(changes.getChildren(), hasChildren(childA1.getUuid(), childB1.getUuid(), childA2.getUuid()));
+
+ }
+
+ @Test
+ public void shouldHaveChildrenAfterDeletingChild() {
+ assertThat(changes.getChildren().size(), is(0));
+
+ // Add some children ...
+ ChildNode childA1 = addChildInChanged("childA");
+ ChildNode childB1 = addChildInChanged("childB");
+ ChildNode childA2 = addChildInChanged("childA");
+ assertThat(changes.getChildren().size(), is(3));
+
+ // Delete a child that was added and another that was an original ...
+ removeChildFromChanged(childA1);
+
+ // Verify that all children are there in the proper order ...
+ assertThat(changes.getChildren().size(), is(2));
+ assertThat(changes.getChildren(), hasChildren(segment("childB[1]"), segment("childA[1]")));
+ assertThat(changes.getChildren(), hasChildren(childB1.getUuid(), childA2.getUuid()));
+ }
+
+ @Test
+ public void shouldHaveChildrenAfterDeletingMultipleChildren() {
+ assertThat(changes.getChildren().size(), is(0));
+
+ // Add some children ...
+ ChildNode childA1 = addChildInChanged("childA");
+ ChildNode childB1 = addChildInChanged("childB");
+ ChildNode childA2 = addChildInChanged("childA");
+ assertThat(changes.getChildren().size(), is(3));
+
+ // Delete a child that was added and another that was an original ...
+ removeChildFromChanged(childA1);
+ removeChildFromChanged(childA2);
+
+ // Verify that all children are there in the proper order ...
+ assertThat(changes.getChildren().size(), is(1));
+ assertThat(changes.getChildren(), hasChildren(segment("childB[1]")));
+ assertThat(changes.getChildren(), hasChildren(childB1.getUuid()));
+ }
+
+ @Test
+ public void shouldHaveChildrenAfterDeletingAllChildrenFromTheFirsttChildToTheLast() {
+ assertThat(changes.getChildren().size(), is(0));
+
+ // Add some children ...
+ ChildNode childA1 = addChildInChanged("childA");
+ ChildNode childB1 = addChildInChanged("childB");
+ ChildNode childA2 = addChildInChanged("childA");
+ assertThat(changes.getChildren().size(), is(3));
+
+ // Delete all children, from the front to the back ...
+ removeChildFromChanged(childA1); // causes replacement of 'childA2' with lower SNS index
+ removeChildFromChanged(childA2);
+ removeChildFromChanged(childB1);
+
+ // Verify that all children have been removed ...
+ assertThat(changes.getChildren().size(), is(0));
+ }
+
+ @Test
+ public void shouldHaveChildrenAfterDeletingAllChildrenFromTheLastChildToTheFirst() {
+ assertThat(changes.getChildren().size(), is(0));
+
+ // Add some children ...
+ ChildNode childA1 = addChildInChanged("childA");
+ ChildNode childB1 = addChildInChanged("childB");
+ ChildNode childA2 = addChildInChanged("childA");
+ assertThat(changes.getChildren().size(), is(3));
+
+ // Delete all children, from the back to the front ...
+ removeChildFromChanged(childA2);
+ removeChildFromChanged(childB1);
+ removeChildFromChanged(childA1);
+
+ // Verify that all children have been removed ...
+ assertThat(changes.getChildren().size(), is(0));
+ }
+
+ @Test
+ public void shouldHaveChildrenAfterAddingSomeChildrenThenDeletingAllChildrenFromTheFirstChildToTheLast() {
+ assertThat(changes.getChildren().size(), is(0));
+
+ // Add some children ...
+ ChildNode childA1 = addChildInChanged("childA");
+ ChildNode childB1 = addChildInChanged("childB");
+ ChildNode childA2 = addChildInChanged("childA");
+ assertThat(changes.getChildren().size(), is(3));
+
+ // Add some children in the changed representation ...
+ ChildNode childA3 = addChildInChanged("childA");
+ ChildNode childC1 = addChildInChanged("childC");
+ ChildNode childC2 = addChildInChanged("childC");
+
+ // Delete all children, from the front to the back ...
+ removeChildFromChanged(childA3);
+ removeChildFromChanged(childC1); // causes replacement of 'childC2' with lower SNS index
+ removeChildFromChanged(childC2);
+ removeChildFromChanged(childA1); // causes replacement of 'childA2' with lower SNS index
+ removeChildFromChanged(childB1);
+ removeChildFromChanged(childA2);
+
+ // Verify that all children have been removed ...
+ assertThat(changes.getChildren().size(), is(0));
+ }
+
+ @Test
+ public void shouldHaveChildrenAfterAddingSomeChildrenThenDeletingAllChildrenFromTheLastChildToTheFirst() {
+ assertThat(changes.getChildren().size(), is(0));
+
+ // Add some children ...
+ ChildNode childA1 = addChildInChanged("childA");
+ ChildNode childB1 = addChildInChanged("childB");
+ ChildNode childA2 = addChildInChanged("childA");
+ assertThat(changes.getChildren().size(), is(3));
+
+ // Add some children in the changed representation ...
+ ChildNode childA3 = addChildInChanged("childA");
+ ChildNode childC1 = addChildInChanged("childC");
+ ChildNode childC2 = addChildInChanged("childC");
+
+ // Delete all children, from the back to the front ...
+ removeChildFromChanged(childC2);
+ removeChildFromChanged(childC1);
+ removeChildFromChanged(childA3);
+ removeChildFromChanged(childA2);
+ removeChildFromChanged(childB1);
+ removeChildFromChanged(childA1);
+
+ // Verify that all children have been removed ...
+ assertThat(changes.getChildren().size(), is(0));
+ }
+
+ @Test
+ public void shouldHaveChildrenAfterReorderingChildren() {
+
+ }
+
+ @Test
+ @SuppressWarnings( "unused" )
+ public void shouldNotRemoveFromNodeInfoWithNoChildChangesAChildThatMatchesSegmentButNotUuid() {
+ assertThat(changes.getChildren().size(), is(0));
+
+ // Add some children ...
+ ChildNode childA1 = addChildInChanged("childA");
+ ChildNode childB1 = addChildInChanged("childB");
+ ChildNode childA2 = addChildInChanged("childA");
+ assertThat(changes.getChildren().size(), is(3));
+
+ // Create a bogus node that has a new UUID but with the same segment as 'childA3' ...
+ Children before = changes.getChildren();
+ int beforeSize = before.size();
+ assertThat(changes.removeChild(UUID.randomUUID(), pathFactory), is(nullValue()));
+ Children after = changes.getChildren();
+ assertThat(after.size(), is(beforeSize));
+ assertThat(after, is(sameInstance(before)));
+ assertThat(after, is(sameInstance(changes.getChildren())));
+ }
+
+ @Test
+ @SuppressWarnings( "unused" )
+ public void shouldNotRemoveFromNodeInfoWithSomeChildChangesAChildThatMatchesSegmentButNotUuid() {
+ assertThat(changes.getChildren().size(), is(0));
+
+ // Add some children ...
+ ChildNode childA1 = addChildInChanged("childA");
+ ChildNode childB1 = addChildInChanged("childB");
+ ChildNode childA2 = addChildInChanged("childA");
+ assertThat(changes.getChildren().size(), is(3));
+
+ // Add some children in the changed representation ...
+ ChildNode childA3 = addChildInChanged("childA");
+ ChildNode childC1 = addChildInChanged("childC");
+ ChildNode childC2 = addChildInChanged("childC");
+
+ // Create a bogus node that has a new UUID but with the same segment as 'childA3' ...
+ Children before = changes.getChildren();
+ int beforeSize = before.size();
+ assertThat(changes.removeChild(UUID.randomUUID(), pathFactory), is(nullValue()));
+ Children after = changes.getChildren();
+ assertThat(after.size(), is(beforeSize));
+ assertThat(after, is(sameInstance(before)));
+ assertThat(after, is(sameInstance(changes.getChildren())));
+ }
+
+ @Test
+ public void shouldFindPropertyThatHasNotBeenModifiedButIsInOriginal() {
+ PropertyInfo propertyInfo = makePropertyInOriginal("test");
+ assertThat(changes.getProperty(name("test")), is(sameInstance(propertyInfo)));
+ }
+
+ @Test
+ public void shouldFindPropertyThatHasBeenModifiedFromOriginal() {
+ PropertyInfo propertyInfo = makePropertyInOriginal("test");
+ assertThat(changes.getProperty(name("test")), is(sameInstance(propertyInfo)));
+
+ // Modify the property ...
+ PropertyInfo newPropertyInfo = mock(PropertyInfo.class);
+ stub(newPropertyInfo.getPropertyName()).toReturn(name("test"));
+ PropertyInfo previous = changes.setProperty(newPropertyInfo, context.getValueFactories());
+ assertThat(previous, is(sameInstance(propertyInfo)));
+
+ // Verify we can find the new property ...
+ assertThat(changes.getProperty(name("test")), is(sameInstance(newPropertyInfo)));
+ }
+
+ @Test
+ public void shouldNotFindPropertyThatHasBeenDeletedFromOriginal() {
+ PropertyInfo propertyInfo = makePropertyInOriginal("test");
+ assertThat(changes.getProperty(name("test")), is(sameInstance(propertyInfo)));
+
+ // Delete the property ...
+ PropertyInfo previous = changes.removeProperty(name("test"));
+ assertThat(previous, is(sameInstance(propertyInfo)));
+
+ // Verify we can not find the new property ...
+ assertThat(changes.getProperty(name("test")), is(nullValue()));
+ }
+
+ @Test
+ public void shouldNotFindPropertyThatIsNotInOriginal() {
+ assertThat(changes.getProperty(name("test")), is(nullValue()));
+
+ makePropertyInOriginal("test");
+ assertThat(changes.getProperty(name("nonExistant")), is(nullValue()));
+ }
+
+ @Test
+ public void shouldFindAllPropertyNamesWhenChangedNodeHasNoChangedProperties() {
+ PropertyInfo propA = makePropertyInOriginal("propA");
+ PropertyInfo propB = makePropertyInOriginal("propB");
+ PropertyInfo propC = makePropertyInOriginal("propC");
+ PropertyInfo propD = makePropertyInOriginal("propD");
+ Set<Name> names = changes.getPropertyNames();
+ assertThat(names.size(), is(4));
+ assertThat(names, hasItems(propA.getPropertyName(),
+ propB.getPropertyName(),
+ propC.getPropertyName(),
+ propD.getPropertyName()));
+ }
+
+ @Test
+ public void shouldFindAllPropertyNamesWhenChangedNodeHasDeletedAllProperties() {
+ PropertyInfo propA = makePropertyInOriginal("propA");
+ PropertyInfo propB = makePropertyInOriginal("propB");
+ PropertyInfo propC = makePropertyInOriginal("propC");
+ PropertyInfo propD = makePropertyInOriginal("propD");
+ // Remove all properties ...
+ assertThat(changes.removeProperty(propA.getPropertyName()), is(sameInstance(propA)));
+ assertThat(changes.removeProperty(propB.getPropertyName()), is(sameInstance(propB)));
+ assertThat(changes.removeProperty(propC.getPropertyName()), is(sameInstance(propC)));
+ assertThat(changes.removeProperty(propD.getPropertyName()), is(sameInstance(propD)));
+ // Now ask for names
+ Set<Name> names = changes.getPropertyNames();
+ assertThat(names.size(), is(0));
+ }
+
+ @Test
+ public void shouldFindAllPropertyNamesWhenChangedNodeHasDeletedSomeProperties() {
+ PropertyInfo propA = makePropertyInOriginal("propA");
+ PropertyInfo propB = makePropertyInOriginal("propB");
+ PropertyInfo propC = makePropertyInOriginal("propC");
+ PropertyInfo propD = makePropertyInOriginal("propD");
+ // Remove some properties ...
+ assertThat(changes.removeProperty(propB.getPropertyName()), is(sameInstance(propB)));
+ assertThat(changes.removeProperty(propD.getPropertyName()), is(sameInstance(propD)));
+ // Now ask for names
+ Set<Name> names = changes.getPropertyNames();
+ assertThat(names.size(), is(2));
+ assertThat(names, hasItems(propA.getPropertyName(), propC.getPropertyName()));
+ }
+
+ @Test
+ @SuppressWarnings( "unused" )
+ public void shouldFindAllPropertyNamesWhenChangedNodeHasChangedSomeProperties() {
+ PropertyInfo propA = makePropertyInOriginal("propA");
+ PropertyInfo propB = makePropertyInOriginal("propB");
+ PropertyInfo propC = makePropertyInOriginal("propC");
+ PropertyInfo propD = makePropertyInOriginal("propD");
+ // Change some properties ...
+ PropertyInfo propB2 = setPropertyInChanged("propB");
+ PropertyInfo propC2 = setPropertyInChanged("propC");
+ // Now ask for names
+ Set<Name> names = changes.getPropertyNames();
+ assertThat(names.size(), is(4));
+ assertThat(names, hasItems(propA.getPropertyName(),
+ propB2.getPropertyName(),
+ propC2.getPropertyName(),
+ propD.getPropertyName()));
+ }
+
+ @Test
+ @SuppressWarnings( "unused" )
+ public void shouldFindAllPropertyNamesWhenChangedNodeHasAddedSomeProperties() {
+ PropertyInfo propA = makePropertyInOriginal("propA");
+ PropertyInfo propB = makePropertyInOriginal("propB");
+ PropertyInfo propC = makePropertyInOriginal("propC");
+ PropertyInfo propD = makePropertyInOriginal("propD");
+ // Add some properties ...
+ PropertyInfo propE = setPropertyInChanged("propE");
+ PropertyInfo propF = setPropertyInChanged("propF");
+ PropertyInfo propG = setPropertyInChanged("propG");
+ // Now ask for names
+ Set<Name> names = changes.getPropertyNames();
+ assertThat(names.size(), is(7));
+ assertThat(names, hasItems(propA.getPropertyName(),
+ propB.getPropertyName(),
+ propC.getPropertyName(),
+ propD.getPropertyName(),
+ propE.getPropertyName(),
+ propF.getPropertyName()));
+ }
+
+ @Test
+ @SuppressWarnings( "unused" )
+ public void shouldFindAllPropertyNamesWhenChangedNodeHasChangedAndDeletedAndAddedSomeProperties() {
+ PropertyInfo propA = makePropertyInOriginal("propA");
+ PropertyInfo propB = makePropertyInOriginal("propB");
+ PropertyInfo propC = makePropertyInOriginal("propC");
+ PropertyInfo propD = makePropertyInOriginal("propD");
+ // Change some properties ...
+ PropertyInfo propB2 = setPropertyInChanged("propB");
+ PropertyInfo propC2 = setPropertyInChanged("propC");
+ // Add some properties ...
+ PropertyInfo propE = setPropertyInChanged("propE");
+ // Remove some properties ...
+ assertThat(changes.removeProperty(propB2.getPropertyName()), is(sameInstance(propB2)));
+ assertThat(changes.removeProperty(propD.getPropertyName()), is(sameInstance(propD)));
+ // Now ask for names
+ Set<Name> names = changes.getPropertyNames();
+ assertThat(names.size(), is(3));
+ assertThat(names, hasItems(propA.getPropertyName(), propC2.getPropertyName(), propE.getPropertyName()));
+ }
+
+ @Test
+ @SuppressWarnings( "unused" )
+ public void shouldFindAllPropertyNamesWhenChangedNodeHasChangedAndDeletedAllProperties() {
+ PropertyInfo propA = makePropertyInOriginal("propA");
+ PropertyInfo propB = makePropertyInOriginal("propB");
+ PropertyInfo propC = makePropertyInOriginal("propC");
+ PropertyInfo propD = makePropertyInOriginal("propD");
+ // Change some properties ...
+ PropertyInfo propB2 = setPropertyInChanged("propB");
+ PropertyInfo propC2 = setPropertyInChanged("propC");
+ // Remove all properties ...
+ assertThat(changes.removeProperty(propA.getPropertyName()), is(sameInstance(propA)));
+ assertThat(changes.removeProperty(propB2.getPropertyName()), is(sameInstance(propB2)));
+ assertThat(changes.removeProperty(propC2.getPropertyName()), is(sameInstance(propC2)));
+ assertThat(changes.removeProperty(propD.getPropertyName()), is(sameInstance(propD)));
+ // Now ask for names
+ Set<Name> names = changes.getPropertyNames();
+ assertThat(names.size(), is(0));
+ }
+
+}
Property changes on: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/cache/NewNodeInfoTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
16 years, 8 months
DNA SVN: r834 - trunk/dna-jcr/src/main/java/org/jboss/dna/jcr.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-04-16 11:31:14 -0400 (Thu, 16 Apr 2009)
New Revision: 834
Modified:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java
Log:
DNA-361 SessionCache Throws Wrong Exception Type For Invalid Item State
Applied the patch (removing the duplicate lines from a previous patch).
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java 2009-04-16 15:26:06 UTC (rev 833)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java 2009-04-16 15:31:14 UTC (rev 834)
@@ -336,7 +336,7 @@
try {
operations.execute();
} catch (org.jboss.dna.graph.property.PathNotFoundException e) {
- throw new PathNotFoundException(e.getLocalizedMessage(), e);
+ throw new InvalidItemStateException(e.getLocalizedMessage(), e);
} catch (RuntimeException e) {
throw new RepositoryException(e.getLocalizedMessage(), e);
}
@@ -442,7 +442,7 @@
changedNodes.keySet().removeAll(uuidsUnderBranch);
deletedNodes.keySet().removeAll(uuidsUnderBranch);
} catch (org.jboss.dna.graph.property.PathNotFoundException e) {
- throw new PathNotFoundException(e.getLocalizedMessage(), e);
+ throw new InvalidItemStateException(e.getLocalizedMessage(), e);
} catch (RuntimeException e) {
throw new RepositoryException(e.getLocalizedMessage(), e);
}
16 years, 8 months
DNA SVN: r833 - in trunk/dna-jcr/src: test/java/org/jboss/dna/jcr and 1 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-04-16 11:26:06 -0400 (Thu, 16 Apr 2009)
New Revision: 833
Added:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrContentHandler.java
Modified:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrTckTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/TestLexicon.java
trunk/dna-jcr/src/test/resources/repositoryForTckTests.xml
trunk/dna-jcr/src/test/resources/repositoryStubImpl.properties
Log:
DNA-360 JcrSession.importXml and getContentHandler Are Not Implemented
Applied the patch, which implements Session.importXml and getContentHandler. SerializationTest was commented back out (relative to the patch), since it tests the similar methods in Workspace, and these are not yet implemented.
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java 2009-04-16 14:53:11 UTC (rev 832)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java 2009-04-16 15:26:06 UTC (rev 833)
@@ -915,6 +915,31 @@
String primaryNodeTypeName )
throws ItemExistsException, PathNotFoundException, VersionException, ConstraintViolationException, LockException,
RepositoryException {
+ return this.addNode(relPath, primaryNodeTypeName, null);
+ }
+
+ /**
+ * Adds the a new node with the given primary type (if specified) at the given relative path with the given UUID (if
+ * specified).
+ *
+ * @param relPath the at which the new node should be created
+ * @param primaryNodeTypeName the desired primary type for the new node; null value indicates that the default primary type
+ * from the appropriate definition for this node should be used
+ * @param desiredUuid the UUID (for the jcr.uuid property) of this node; may be null
+ * @return the newly created node
+ * @throws ItemExistsException if an item at the specified path already exists and same-name siblings are not allowed.
+ * @throws PathNotFoundException if the specified path implies intermediary nodes that do not exist.
+ * @throws VersionException not thrown at this time, but included for compatibility with the specification
+ * @throws ConstraintViolationException if the change would violate a node type or implementation-specific constraint.
+ * @throws LockException not thrown at this time, but included for compatibility with the specification
+ * @throws RepositoryException if another error occurs
+ * @see #addNode(String, String)
+ */
+ final AbstractJcrNode addNode( String relPath,
+ String primaryNodeTypeName,
+ UUID desiredUuid )
+ throws ItemExistsException, PathNotFoundException, VersionException, ConstraintViolationException, LockException,
+ RepositoryException {
// Determine the path ...
NodeEditor editor = null;
Path path = null;
@@ -976,7 +1001,7 @@
}
// Create the child ...
- ChildNode child = editor.createChild(childName, null, childPrimaryTypeName);
+ ChildNode child = editor.createChild(childName, desiredUuid, childPrimaryTypeName);
return cache.findJcrNode(child.getUuid());
}
Added: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrContentHandler.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrContentHandler.java (rev 0)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrContentHandler.java 2009-04-16 15:26:06 UTC (rev 833)
@@ -0,0 +1,465 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.jcr;
+
+import java.io.ByteArrayInputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Stack;
+import java.util.UUID;
+import javax.jcr.ImportUUIDBehavior;
+import javax.jcr.ItemExistsException;
+import javax.jcr.Node;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.nodetype.ConstraintViolationException;
+import net.jcip.annotations.NotThreadSafe;
+import org.jboss.dna.common.text.TextDecoder;
+import org.jboss.dna.common.text.XmlNameEncoder;
+import org.jboss.dna.common.util.Base64;
+import org.jboss.dna.graph.property.NamespaceRegistry;
+import org.jboss.dna.graph.property.Path;
+import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+/**
+ * Content handler that provides SAX-based event handling that maps incoming documents to the repository based on the
+ * functionality described in section 7.3 of the JCR 1.0.1 specification.
+ * <p>
+ * Each content handler is only intended to be used once and discarded. This class is <b>NOT</b> thread-safe.
+ * </p>
+ *
+ * @see JcrSession#getImportContentHandler(String, int)
+ * @see JcrWorkspace#getImportContentHandler(String, int)
+ */
+@NotThreadSafe
+class JcrContentHandler extends DefaultHandler {
+
+ /**
+ * Encoder to properly escape XML names.
+ *
+ * @see XmlNameEncoder
+ */
+ protected static final TextDecoder SYSTEM_VIEW_NAME_DECODER = new XmlNameEncoder();
+
+ protected static final TextDecoder DOCUMENT_VIEW_NAME_DECODER = new JcrDocumentViewExporter.JcrDocumentViewPropertyEncoder();
+
+ protected final JcrSession session;
+ protected final int uuidBehavior;
+ protected final SaveMode saveMode;
+
+ protected final String primaryTypeName;
+ protected final String mixinTypesName;
+ protected final String uuidName;
+
+ private AbstractJcrNode currentNode;
+ private ContentHandler delegate;
+
+ enum SaveMode {
+ WORKSPACE,
+ SESSION
+ }
+
+ JcrContentHandler( JcrSession session,
+ Path parentPath,
+ int uuidBehavior,
+ SaveMode saveMode ) throws PathNotFoundException, RepositoryException {
+ assert session != null;
+ assert parentPath != null;
+ assert uuidBehavior == ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW
+ || uuidBehavior == ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING
+ || uuidBehavior == ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING
+ || uuidBehavior == ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW;
+
+ this.session = session;
+ this.currentNode = (AbstractJcrNode)session.getNode(parentPath);
+ this.uuidBehavior = uuidBehavior;
+ this.saveMode = saveMode;
+
+ this.primaryTypeName = JcrLexicon.PRIMARY_TYPE.getString(this.session.namespaces());
+ this.mixinTypesName = JcrLexicon.MIXIN_TYPES.getString(this.session.namespaces());
+ this.uuidName = JcrLexicon.UUID.getString(this.session.namespaces());
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.xml.sax.ContentHandler#characters(char[], int, int)
+ */
+ @Override
+ public void characters( char[] ch,
+ int start,
+ int length ) throws SAXException {
+ assert this.delegate != null;
+ delegate.characters(ch, start, length);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.xml.sax.ContentHandler#endElement(java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
+ public void endElement( String uri,
+ String localName,
+ String name ) throws SAXException {
+ assert this.delegate != null;
+ delegate.endElement(uri, localName, name);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
+ */
+ @Override
+ public void startElement( String uri,
+ String localName,
+ String name,
+ Attributes atts ) throws SAXException {
+ checkDelegate(uri);
+ assert this.delegate != null;
+
+ delegate.startElement(uri, localName, name, atts);
+ }
+
+ private void checkDelegate( String namespaceUri ) {
+ if (delegate != null) return;
+
+ if (JcrSvLexicon.Namespace.URI.equals(namespaceUri)) {
+ this.delegate = new SystemViewContentHandler(this.currentNode);
+ } else {
+ this.delegate = new DocumentViewContentHandler(this.currentNode);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.xml.sax.ContentHandler#startPrefixMapping(java.lang.String, java.lang.String)
+ */
+ @Override
+ public void startPrefixMapping( String prefix,
+ String uri ) throws SAXException {
+ try {
+ // Read from the workspace's DNA registry, as its semantics are more friendly
+ NamespaceRegistry registry = session.workspace().context().getNamespaceRegistry();
+
+ String existingUri = registry.getNamespaceForPrefix(prefix);
+
+ if (existingUri != null) {
+ if (existingUri.equals(uri)) {
+ // prefix/uri mapping is already in registry
+ return;
+ }
+
+ throw new RepositoryException("Prefix " + prefix + " is already permanently mapped");
+ }
+
+ // Register through the JCR workspace to ensure consistency
+ session.getWorkspace().getNamespaceRegistry().registerNamespace(prefix, uri);
+ } catch (RepositoryException re) {
+ throw new EnclosingSAXException(re);
+ }
+ }
+
+ class EnclosingSAXException extends SAXException {
+
+ /**
+ */
+ private static final long serialVersionUID = -1044992767566435542L;
+
+ /**
+ * @param e
+ */
+ EnclosingSAXException( Exception e ) {
+ super(e);
+
+ }
+
+ }
+
+ private class SystemViewContentHandler extends DefaultHandler {
+ private Stack<AbstractJcrNode> parentStack;
+
+ private final String svNameName;
+ private final String svTypeName;
+
+ private String currentNodeName;
+ private String currentPropName;
+ private int currentPropType;
+
+ private StringBuffer valueBuffer;
+ private Map<String, List<Value>> currentProps;
+
+ /**
+ * @param currentNode
+ */
+ SystemViewContentHandler( AbstractJcrNode currentNode ) {
+ super();
+ this.parentStack = new Stack<AbstractJcrNode>();
+ this.parentStack.push(currentNode);
+
+ this.currentProps = new HashMap<String, List<Value>>();
+ this.valueBuffer = new StringBuffer();
+
+ this.svNameName = JcrSvLexicon.NAME.getString(session.namespaces());
+ this.svTypeName = JcrSvLexicon.TYPE.getString(session.namespaces());
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String,
+ * org.xml.sax.Attributes)
+ */
+ @Override
+ public void startElement( String uri,
+ String localName,
+ String name,
+ Attributes atts ) throws SAXException {
+ if ("node".equals(localName)) {
+ if (currentNodeName != null) {
+ addNodeIfPending();
+ }
+
+ currentNodeName = atts.getValue(SYSTEM_VIEW_NAME_DECODER.decode(svNameName));
+ } else if ("property".equals(localName)) {
+ currentPropName = atts.getValue(SYSTEM_VIEW_NAME_DECODER.decode(svNameName));
+ currentPropType = PropertyType.valueFromName(atts.getValue(svTypeName));
+ currentProps.put(currentPropName, new ArrayList<Value>());
+ } else if (!"value".equals(localName)) {
+ throw new IllegalStateException("Unexpected element '" + name + "' in system view");
+ }
+ }
+
+ private void addNodeIfPending() throws SAXException {
+ if (currentNodeName != null) {
+ try {
+ AbstractJcrNode parentNode = parentStack.peek();
+
+ UUID uuid = null;
+ List<Value> rawUuid = currentProps.get(uuidName);
+
+ if (rawUuid != null) {
+ assert rawUuid.size() == 1;
+ uuid = UUID.fromString(rawUuid.get(0).getString());
+ }
+
+ AbstractJcrNode newNode = parentNode.addNode(currentNodeName,
+ currentProps.get(primaryTypeName).get(0).getString(),
+ uuid);
+
+ for (Map.Entry<String, List<Value>> entry : currentProps.entrySet()) {
+ if (entry.getKey().equals(primaryTypeName)) {
+ continue;
+ }
+
+ if (entry.getKey().equals(mixinTypesName)) {
+ for (Value value : entry.getValue()) {
+ newNode.addMixin(value.getString());
+ }
+ continue;
+ }
+
+ if (entry.getKey().equals(uuidName)) {
+ continue;
+ }
+
+ List<Value> values = entry.getValue();
+
+ if (values.size() == 1) {
+ newNode.setProperty(entry.getKey(), values.get(0));
+ } else {
+ newNode.setProperty(entry.getKey(), values.toArray(new Value[values.size()]));
+ }
+ }
+
+ parentStack.push(newNode);
+ currentProps.clear();
+ } catch (RepositoryException re) {
+ throw new EnclosingSAXException(re);
+ }
+ }
+ }
+
+ @Override
+ public void endElement( String uri,
+ String localName,
+ String name ) throws SAXException {
+ if ("node".equals(localName)) {
+ addNodeIfPending();
+ currentNodeName = null;
+ parentStack.pop();
+ } else if ("value".equals(localName)) {
+ String s = valueBuffer.toString();
+ try {
+ if (currentPropType == PropertyType.BINARY) {
+ ByteArrayInputStream is = new ByteArrayInputStream(Base64.decode(s, Base64.URL_SAFE));
+ currentProps.get(currentPropName).add(session.getValueFactory().createValue(is));
+ } else {
+ currentProps.get(currentPropName).add(session.getValueFactory().createValue(SYSTEM_VIEW_NAME_DECODER.decode(s),
+ currentPropType));
+ }
+ } catch (RepositoryException re) {
+ throw new EnclosingSAXException(re);
+ }
+ valueBuffer = new StringBuffer();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.xml.sax.ContentHandler#characters(char[], int, int)
+ */
+ @Override
+ public void characters( char[] ch,
+ int start,
+ int length ) {
+ valueBuffer.append(ch, start, length);
+
+ }
+ }
+
+ private class DocumentViewContentHandler extends DefaultHandler {
+ private Stack<AbstractJcrNode> parentStack;
+
+ /**
+ * @param currentNode
+ */
+ DocumentViewContentHandler( AbstractJcrNode currentNode ) {
+ super();
+ this.parentStack = new Stack<AbstractJcrNode>();
+ parentStack.push(currentNode);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String,
+ * org.xml.sax.Attributes)
+ */
+ @Override
+ public void startElement( String uri,
+ String localName,
+ String name,
+ Attributes atts ) throws SAXException {
+ try {
+ String primaryTypeName = atts.getValue(JcrContentHandler.this.primaryTypeName);
+ String rawUuid = atts.getValue(uuidName);
+ UUID uuid = (rawUuid != null ? UUID.fromString(rawUuid) : null);
+ AbstractJcrNode parentNode = parentStack.peek();
+
+ if (uuid != null) {
+ AbstractJcrNode existingNodeWithUuid = (AbstractJcrNode)session.getNodeByUUID(rawUuid);
+ if (existingNodeWithUuid != null) {
+ switch (uuidBehavior) {
+ case ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING:
+ parentNode = (AbstractJcrNode)existingNodeWithUuid.getParent();
+ existingNodeWithUuid.remove();
+ break;
+ case ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW:
+ uuid = UUID.randomUUID();
+ break;
+ case ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING:
+ if (existingNodeWithUuid.path().isAtOrAbove(parentStack.firstElement().path())) {
+ throw new ConstraintViolationException();
+ }
+ existingNodeWithUuid.remove();
+ break;
+ case ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW:
+ throw new ItemExistsException();
+ }
+ }
+ }
+
+ name = DOCUMENT_VIEW_NAME_DECODER.decode(name);
+ AbstractJcrNode currentNode = parentNode.addNode(name, primaryTypeName, uuid);
+
+ for (int i = 0; i < atts.getLength(); i++) {
+ if (JcrContentHandler.this.primaryTypeName.equals(atts.getQName(i))) {
+ continue;
+ }
+
+ if (mixinTypesName.equals(atts.getQName(i))) {
+ currentNode.addMixin(atts.getValue(i));
+ continue;
+ }
+
+ if (uuidName.equals(atts.getQName(i))) {
+ continue;
+ }
+
+ // We may want to use the workspace context here so that we only use the permanent namespace mappings
+ // Name propName = session.executionContext.getValueFactories().getNameFactory().create(atts.getQName(i));
+ // String value = DOCUMENT_VIEW_NAME_DECODER.decode(atts.getValue(i));
+ String value = atts.getValue(i);
+ String propertyName = DOCUMENT_VIEW_NAME_DECODER.decode(atts.getQName(i));
+ currentNode.setProperty(propertyName, value);
+ }
+
+ parentStack.push(currentNode);
+ } catch (RepositoryException re) {
+ throw new EnclosingSAXException(re);
+ }
+
+ }
+
+ @Override
+ public void endElement( String uri,
+ String localName,
+ String name ) {
+ parentStack.pop();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.xml.sax.ContentHandler#characters(char[], int, int)
+ */
+ @Override
+ public void characters( char[] ch,
+ int start,
+ int length ) throws SAXException {
+ try {
+ NamespaceRegistry namespaces = session.getExecutionContext().getNamespaceRegistry();
+ Node parentNode = parentStack.peek();
+ Node currentNode = parentNode.addNode(JcrLexicon.XMLTEXT.getString(namespaces),
+ JcrNtLexicon.UNSTRUCTURED.getString(namespaces));
+ String s = new String(ch, start, length);
+ currentNode.setProperty(JcrLexicon.XMLCHARACTERS.getString(namespaces), s);
+
+ } catch (RepositoryException re) {
+ throw new EnclosingSAXException(re);
+ }
+ }
+ }
+}
Property changes on: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrContentHandler.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java 2009-04-16 14:53:11 UTC (rev 832)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java 2009-04-16 15:26:06 UTC (rev 833)
@@ -23,6 +23,7 @@
*/
package org.jboss.dna.jcr;
+import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.security.AccessControlException;
@@ -32,7 +33,9 @@
import java.util.Set;
import java.util.UUID;
import javax.jcr.Credentials;
+import javax.jcr.InvalidSerializedDataException;
import javax.jcr.Item;
+import javax.jcr.ItemExistsException;
import javax.jcr.ItemNotFoundException;
import javax.jcr.NamespaceException;
import javax.jcr.Node;
@@ -46,6 +49,7 @@
import javax.jcr.ValueFactory;
import javax.jcr.ValueFormatException;
import javax.jcr.Workspace;
+import javax.jcr.nodetype.ConstraintViolationException;
import javax.security.auth.Subject;
import javax.security.auth.login.LoginContext;
import javax.security.auth.login.LoginException;
@@ -60,9 +64,15 @@
import org.jboss.dna.graph.property.Path;
import org.jboss.dna.graph.property.ValueFactories;
import org.jboss.dna.graph.property.basic.LocalNamespaceRegistry;
+import org.jboss.dna.jcr.JcrContentHandler.EnclosingSAXException;
+import org.jboss.dna.jcr.JcrContentHandler.SaveMode;
import org.jboss.dna.jcr.JcrNamespaceRegistry.Behavior;
import org.xml.sax.ContentHandler;
+import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+import org.xml.sax.XMLReader;
+import org.xml.sax.helpers.XMLReaderFactory;
/**
* @author John Verhaeg
@@ -355,12 +365,13 @@
/**
* {@inheritDoc}
*
- * @throws UnsupportedOperationException always
* @see javax.jcr.Session#getImportContentHandler(java.lang.String, int)
*/
public ContentHandler getImportContentHandler( String parentAbsPath,
- int uuidBehavior ) {
- throw new UnsupportedOperationException();
+ int uuidBehavior ) throws PathNotFoundException, RepositoryException {
+ Path parentPath = this.executionContext.getValueFactories().getPathFactory().create(parentAbsPath);
+
+ return new JcrContentHandler(this, parentPath, uuidBehavior, SaveMode.SESSION);
}
/**
@@ -595,13 +606,29 @@
/**
* {@inheritDoc}
*
- * @throws UnsupportedOperationException always
* @see javax.jcr.Session#importXML(java.lang.String, java.io.InputStream, int)
*/
public void importXML( String parentAbsPath,
InputStream in,
- int uuidBehavior ) {
- throw new UnsupportedOperationException();
+ int uuidBehavior ) throws IOException, InvalidSerializedDataException, RepositoryException {
+
+ try {
+ XMLReader parser = XMLReaderFactory.createXMLReader();
+ parser.setContentHandler(getImportContentHandler(parentAbsPath, uuidBehavior));
+ parser.parse(new InputSource(in));
+ } catch (EnclosingSAXException ese) {
+ Exception cause = ese.getException();
+ if (cause instanceof ItemExistsException) {
+ throw (ItemExistsException)cause;
+ } else if (cause instanceof ConstraintViolationException) {
+ throw (ConstraintViolationException)cause;
+ }
+ throw new RepositoryException(cause);
+ } catch (SAXParseException se) {
+ throw new InvalidSerializedDataException(se);
+ } catch (SAXException se) {
+ throw new RepositoryException(se);
+ }
}
/**
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrTckTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrTckTest.java 2009-04-16 14:53:11 UTC (rev 832)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrTckTest.java 2009-04-16 15:26:06 UTC (rev 833)
@@ -27,11 +27,14 @@
import java.net.URI;
import java.security.AccessControlContext;
import java.security.AccessController;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
import java.util.Collections;
+import java.util.List;
import java.util.Map;
import java.util.Properties;
import javax.jcr.Credentials;
-import javax.jcr.Repository;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.apache.jackrabbit.test.JCRTestSuite;
@@ -50,6 +53,7 @@
import org.apache.jackrabbit.test.api.SetPropertyDoubleTest;
import org.apache.jackrabbit.test.api.SetPropertyInputStreamTest;
import org.apache.jackrabbit.test.api.SetPropertyLongTest;
+import org.apache.jackrabbit.test.api.SetPropertyNodeTest;
import org.apache.jackrabbit.test.api.SetPropertyStringTest;
import org.apache.jackrabbit.test.api.SetPropertyValueTest;
import org.apache.jackrabbit.test.api.SetValueBinaryTest;
@@ -69,9 +73,11 @@
import org.apache.jackrabbit.test.api.WorkspaceCopyBetweenWorkspacesReferenceableTest;
import org.apache.jackrabbit.test.api.WorkspaceCopyBetweenWorkspacesSameNameSibsTest;
import org.apache.jackrabbit.test.api.WorkspaceCopyBetweenWorkspacesTest;
-import org.jboss.dna.graph.DnaLexicon;
+import org.apache.jackrabbit.test.api.WorkspaceCopyVersionableTest;
+import org.apache.jackrabbit.test.api.WorkspaceMoveVersionableTest;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.Graph;
+import org.jboss.dna.graph.JcrMixLexicon;
import org.jboss.dna.graph.JcrNtLexicon;
import org.jboss.dna.graph.Location;
import org.jboss.dna.graph.connector.RepositoryConnection;
@@ -202,7 +208,7 @@
addTestSuite(SetPropertyDoubleTest.class);
addTestSuite(SetPropertyInputStreamTest.class);
addTestSuite(SetPropertyLongTest.class);
- // addTestSuite(SetPropertyNodeTest.class);
+ addTestSuite(SetPropertyNodeTest.class);
addTestSuite(SetPropertyStringTest.class);
addTestSuite(SetPropertyValueTest.class);
addTestSuite(SetPropertyConstraintViolationExceptionTest.class);
@@ -228,16 +234,16 @@
// addTestSuite(WorkspaceCopyReferenceableTest.class);
// addTestSuite(WorkspaceCopySameNameSibsTest.class);
// addTestSuite(WorkspaceCopyTest.class);
- // addTestSuite(WorkspaceCopyVersionableTest.class);
+ addTestSuite(WorkspaceCopyVersionableTest.class);
// addTestSuite(WorkspaceMoveReferenceableTest.class);
// addTestSuite(WorkspaceMoveSameNameSibsTest.class);
// addTestSuite(WorkspaceMoveTest.class);
- // addTestSuite(WorkspaceMoveVersionableTest.class);
- //
+ addTestSuite(WorkspaceMoveVersionableTest.class);
+
addTestSuite(RepositoryLoginTest.class);
// addTestSuite(ImpersonateTest.class);
// addTestSuite(CheckPermissionTest.class);
- //
+
// addTestSuite(DocumentViewImportTest.class);
// addTestSuite(SerializationTest.class);
@@ -257,7 +263,7 @@
// addTest(org.apache.jackrabbit.test.api.observation.TestAll.suite());
// addTest(org.apache.jackrabbit.test.api.version.TestAll.suite());
// addTest(org.apache.jackrabbit.test.api.lock.TestAll.suite());
- // addTest(org.apache.jackrabbit.test.api.util.TestAll.suite());
+ addTest(org.apache.jackrabbit.test.api.util.TestAll.suite());
}
}
@@ -265,11 +271,11 @@
* Concrete implementation of {@link RepositoryStub} based on DNA-specific configuration.
*/
public static class InMemoryRepositoryStub extends RepositoryStub {
- private Repository repository;
- protected RepositoryConnection connection;
+ private JcrRepository repository;
+ protected InMemoryRepositorySource source;
protected AccessControlContext accessControlContext = AccessController.getContext();
- private Credentials credentials = new Credentials() {
+ private Credentials superUserCredentials = new Credentials() {
private static final long serialVersionUID = 1L;
@SuppressWarnings( "unused" )
@@ -278,17 +284,29 @@
}
};
- protected ExecutionContext executionContext = new ExecutionContext() {
+ private Credentials readWriteCredentials = new Credentials() {
+ private static final long serialVersionUID = 1L;
- @Override
- public ExecutionContext create( AccessControlContext accessControlContext ) {
- return executionContext;
+ @SuppressWarnings( "unused" )
+ public AccessControlContext getAccessControlContext() {
+ return accessControlContext;
}
};
+ private Credentials readOnlyCredentials = new Credentials() {
+ private static final long serialVersionUID = 1L;
+
+ @SuppressWarnings( "unused" )
+ public AccessControlContext getAccessControlContext() {
+ return accessControlContext;
+ }
+ };
+
+ protected ExecutionContext executionContext = new ExecutionContext();
+
protected RepositoryConnectionFactory connectionFactory = new RepositoryConnectionFactory() {
public RepositoryConnection createConnection( String sourceName ) {
- return connection;
+ return source.getConnection();
}
};
@@ -296,29 +314,27 @@
super(env);
// Create the in-memory (DNA) repository
- InMemoryRepositorySource source = new InMemoryRepositorySource();
+ source = new InMemoryRepositorySource();
// Various calls will fail if you do not set a non-null name for the source
source.setName("TestRepositorySource");
+ // Make sure the path to the namespaces exists ...
+ Graph graph = Graph.create(source.getName(), connectionFactory, executionContext);
+ graph.create("/jcr:system").and().create("/jcr:system/dna:namespaces");
+
// Wrap a connection to the in-memory (DNA) repository in a (JCR) repository
Map<Options, String> options = Collections.singletonMap(Options.PROJECT_NODE_TYPES, "false");
- connection = source.getConnection();
+
repository = new JcrRepository(executionContext.create(accessControlContext), connectionFactory, source.getName(),
null, options);
+ RepositoryNodeTypeManager nodeTypes = repository.getRepositoryTypeManager();
- // Make sure the path to the namespaces exists ...
- Graph graph = Graph.create(source.getName(), connectionFactory, executionContext);
- graph.create("/jcr:system").and().create("/jcr:system/dna:namespaces");
-
// Set up some sample nodes in the graph to match the expected test configuration
try {
+ nodeTypes.registerNodeTypes(new TckTestNodeTypeSource(executionContext, nodeTypes));
- // TODO: Should there be an easier way to define these since they will be needed for all JCR repositories?
- executionContext.getNamespaceRegistry().register(DnaLexicon.Namespace.PREFIX, DnaLexicon.Namespace.URI);
- executionContext.getNamespaceRegistry().register(JcrLexicon.Namespace.PREFIX, JcrLexicon.Namespace.URI);
- executionContext.getNamespaceRegistry().register(JcrNtLexicon.Namespace.PREFIX, JcrNtLexicon.Namespace.URI);
- executionContext.getNamespaceRegistry().register(JcrSvLexicon.Namespace.PREFIX, JcrSvLexicon.Namespace.URI);
+ executionContext.getNamespaceRegistry().register(TestLexicon.Namespace.PREFIX, TestLexicon.Namespace.URI);
Path destinationPath = executionContext.getValueFactories().getPathFactory().create("/");
GraphImporter importer = new GraphImporter(graph);
@@ -341,9 +357,7 @@
*/
@Override
public Credentials getSuperuserCredentials() {
- // TODO: Why must we override this method? The default TCK implementation just returns a particular instance of
- // SimpleCredentials.
- return credentials;
+ return superUserCredentials;
}
/**
@@ -353,9 +367,7 @@
*/
@Override
public Credentials getReadOnlyCredentials() {
- // TODO: Why must we override this method? The default TCK implementation just returns a particular instance of
- // SimpleCredentials.
- return credentials;
+ return readOnlyCredentials;
}
/**
@@ -365,9 +377,7 @@
*/
@Override
public Credentials getReadWriteCredentials() {
- // TODO: Why must we override this method? The default TCK implementation just returns a particular instance of
- // SimpleCredentials.
- return credentials;
+ return readWriteCredentials;
}
/**
@@ -376,10 +386,88 @@
* @see org.apache.jackrabbit.test.RepositoryStub#getRepository()
*/
@Override
- public Repository getRepository() {
+ public JcrRepository getRepository() {
return repository;
}
}
+ static class TckTestNodeTypeSource extends AbstractJcrNodeTypeSource {
+ /** The list of node types. */
+ private final List<JcrNodeType> nodeTypes;
+
+ TckTestNodeTypeSource( ExecutionContext context,
+ RepositoryNodeTypeManager nodeTypeManager ) {
+ super(null);
+
+ nodeTypes = new ArrayList<JcrNodeType>();
+
+ JcrNodeType base = nodeTypeManager.getNodeType(JcrNtLexicon.BASE);
+
+ if (base == null) {
+ String baseTypeName = JcrNtLexicon.BASE.getString(context.getNamespaceRegistry());
+ String namespaceTypeName = TestLexicon.NO_SAME_NAME_SIBS.getString(context.getNamespaceRegistry());
+ throw new IllegalStateException(JcrI18n.supertypeNotFound.text(baseTypeName, namespaceTypeName));
+ }
+
+ JcrNodeType referenceable = nodeTypeManager.getNodeType(JcrMixLexicon.REFERENCEABLE);
+
+ if (referenceable == null) {
+ String baseTypeName = JcrMixLexicon.REFERENCEABLE.getString(context.getNamespaceRegistry());
+ String namespaceTypeName = TestLexicon.REFERENCEABLE_UNSTRUCTURED.getString(context.getNamespaceRegistry());
+ throw new IllegalStateException(JcrI18n.supertypeNotFound.text(baseTypeName, namespaceTypeName));
+ }
+
+ JcrNodeType unstructured = nodeTypeManager.getNodeType(JcrNtLexicon.UNSTRUCTURED);
+
+ if (unstructured == null) {
+ String baseTypeName = JcrNtLexicon.UNSTRUCTURED.getString(context.getNamespaceRegistry());
+ String namespaceTypeName = TestLexicon.REFERENCEABLE_UNSTRUCTURED.getString(context.getNamespaceRegistry());
+ throw new IllegalStateException(JcrI18n.supertypeNotFound.text(baseTypeName, namespaceTypeName));
+ }
+
+ // Stubbing in child node and property definitions for now
+ JcrNodeType noSameNameSibs = new JcrNodeType(
+ context,
+ NO_NODE_TYPE_MANAGER,
+ TestLexicon.NO_SAME_NAME_SIBS,
+ Arrays.asList(new JcrNodeType[] {base}),
+ NO_PRIMARY_ITEM_NAME,
+ Arrays.asList(new JcrNodeDefinition[] {new JcrNodeDefinition(
+ context,
+ null,
+ ALL_NODES,
+ OnParentVersionBehavior.VERSION.getJcrValue(),
+ false,
+ false,
+ false,
+ false,
+ JcrNtLexicon.UNSTRUCTURED,
+ new JcrNodeType[] {base}),}),
+ NO_PROPERTIES, NOT_MIXIN, UNORDERABLE_CHILD_NODES);
+
+ JcrNodeType referenceableUnstructured = new JcrNodeType(
+ context,
+ NO_NODE_TYPE_MANAGER,
+ TestLexicon.REFERENCEABLE_UNSTRUCTURED,
+ Arrays.asList(new JcrNodeType[] {unstructured, referenceable}),
+ NO_PRIMARY_ITEM_NAME, NO_CHILD_NODES, NO_PROPERTIES,
+ NOT_MIXIN, UNORDERABLE_CHILD_NODES);
+
+ nodeTypes.addAll(Arrays.asList(new JcrNodeType[] {referenceableUnstructured, noSameNameSibs}));
+
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.jcr.JcrNodeTypeSource#getNodeTypes()
+ */
+ @Override
+ public Collection<JcrNodeType> getDeclaredNodeTypes() {
+ return nodeTypes;
+ }
+
+ }
+
}
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/TestLexicon.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/TestLexicon.java 2009-04-16 14:53:11 UTC (rev 832)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/TestLexicon.java 2009-04-16 15:26:06 UTC (rev 833)
@@ -46,5 +46,8 @@
public static final Name CONSTRAINED_PATH = new BasicName(Namespace.URI, "constrainedPath");
public static final Name CONSTRAINED_REFERENCE = new BasicName(Namespace.URI, "constrainedReference");
public static final Name CONSTRAINED_STRING = new BasicName(Namespace.URI, "constrainedString");
-
+
+ public static final Name REFERENCEABLE_UNSTRUCTURED = new BasicName(Namespace.URI, "referenceableUnstructured");
+ public static final Name NO_SAME_NAME_SIBS = new BasicName(Namespace.URI, "noSameNameSibs");
+
}
Modified: trunk/dna-jcr/src/test/resources/repositoryForTckTests.xml
===================================================================
--- trunk/dna-jcr/src/test/resources/repositoryForTckTests.xml 2009-04-16 14:53:11 UTC (rev 832)
+++ trunk/dna-jcr/src/test/resources/repositoryForTckTests.xml 2009-04-16 15:26:06 UTC (rev 833)
@@ -28,7 +28,8 @@
xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
xmlns:dna="http://www.jboss.org/dna/1.0"
jcr:primaryType="nt:unstructured">
- <nt:unstructured jcr:name="node1" prop1="<foo&foo>" >
+ <nt:unstructured jcr:name="serializationNode" />
+ <nt:unstructured jcr:name="node1" prop1="<foo&foo>">
<!--
This stanza checks for the jcr:xmltext special case for export as per JCR 1.0.1 section 6.4.2.3
-->
Modified: trunk/dna-jcr/src/test/resources/repositoryStubImpl.properties
===================================================================
--- trunk/dna-jcr/src/test/resources/repositoryStubImpl.properties 2009-04-16 14:53:11 UTC (rev 832)
+++ trunk/dna-jcr/src/test/resources/repositoryStubImpl.properties 2009-04-16 15:26:06 UTC (rev 833)
@@ -7,5 +7,30 @@
javax.jcr.tck.propertyname1=prop1
javax.jcr.tck.propertyname2=prop2
javax.jcr.tck.workspacename=
-javax.jcr.tck.nodetype=nt:unstructured
+javax.jcr.tck.nodetype=dnatest\:referenceableUnstructured
javax.jcr.tck.nodetypenochildren=dna:namespace
+javax.jcr.tck.sourceFolderName=source
+javax.jcr.tck.targetFolderName=target
+javax.jcr.tck.rootNodeName=rootNode
+javax.jcr.tck.propertySkipped=propertySkipped
+javax.jcr.tck.propertyValueMayChange=propertyValueMayChange
+javax.jcr.tck.nodeTypesTestNode=nodeTypesTestNode
+javax.jcr.tck.mixinTypeTestNode=mixinTypeTestNode
+javax.jcr.tck.propertyTypesTestNode=propertyTypesTestNode
+javax.jcr.tck.sameNameChildrenTestNode=sameNameChildrenTestNode
+javax.jcr.tck.multiValuePropertiesTestNode=multiValuePropertiesTestNode
+javax.jcr.tck.referenceableNodeTestNode=referenceableNodeTestNode
+javax.jcr.tck.orderChildrenTestNode=orderChildrenTestNode
+javax.jcr.tck.namespaceTestNode=namespaceTestNode
+javax.jcr.tck.sameNameSibsFalseChildNodeDefinition=dnatest\:noSameNameSibs
+javax.jcr.tck.stringTestProperty=stringTestProperty
+javax.jcr.tck.binaryTestProperty=binaryTestProperty
+javax.jcr.tck.dateTestProperty=dateTestProperty
+javax.jcr.tck.longTestProperty=longTestProperty
+javax.jcr.tck.doubleTestProperty=doubleTestProperty
+javax.jcr.tck.booleanTestProperty=booleanTestProperty
+javax.jcr.tck.nameTestProperty=nameTestProperty
+javax.jcr.tck.pathTestProperty=pathTestProperty
+javax.jcr.tck.referenceTestProperty=referenceTestProperty
+javax.jcr.tck.multiValueTestProperty=multiValueTestProperty
+javax.jcr.tck.NodeTest.testAddNodeItemExistsException.nodetype=dnatest\:noSameNameSibs
\ No newline at end of file
16 years, 8 months
DNA SVN: r832 - trunk/dna-jcr/src/main/java/org/jboss/dna/jcr.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-04-16 10:53:11 -0400 (Thu, 16 Apr 2009)
New Revision: 832
Modified:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java
Log:
DNA-359 Session.refresh and Node.refresh Methods Not Supported
Applied the patch that implements the Session.refresh and Node.refresh by adding two SessionCache.refresh methods (one to refresh all contents, the other to refresh only those items below a branch).
There is one case that the patch doesn't handle (well), and that is when a node is removed from a branch, refreshing that branch will not refresh the removed node. This needs to be addressed, and will be described in the issue.
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java 2009-04-16 14:11:21 UTC (rev 831)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java 2009-04-16 14:53:11 UTC (rev 832)
@@ -1597,11 +1597,10 @@
/**
* {@inheritDoc}
*
- * @throws UnsupportedOperationException always
* @see javax.jcr.Item#refresh(boolean)
*/
- public void refresh( boolean keepChanges ) {
- throw new UnsupportedOperationException();
+ public void refresh( boolean keepChanges ) throws RepositoryException {
+ this.cache.refresh(this.nodeUuid, keepChanges);
}
/**
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java 2009-04-16 14:11:21 UTC (rev 831)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java 2009-04-16 14:53:11 UTC (rev 832)
@@ -665,6 +665,7 @@
* @see javax.jcr.Session#refresh(boolean)
*/
public void refresh( boolean keepChanges ) {
+ this.cache.refresh(keepChanges);
}
/**
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java 2009-04-16 14:11:21 UTC (rev 831)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java 2009-04-16 14:53:11 UTC (rev 832)
@@ -34,6 +34,7 @@
import java.util.Map;
import java.util.Queue;
import java.util.Set;
+import java.util.Stack;
import java.util.UUID;
import javax.jcr.InvalidItemStateException;
import javax.jcr.Item;
@@ -228,6 +229,103 @@
}
/**
+ * Refreshes (removes the cached state) for all cached nodes.
+ * <p>
+ * If {@code keepChanges == true}, modified nodes will not have their state refreshed.
+ * </p>
+ *
+ * @param keepChanges indicates whether changed nodes should be kept or refreshed from the repository.
+ */
+ public void refresh( boolean keepChanges ) {
+ if (keepChanges) {
+ // Keep the pending operations
+ Set<UUID> retainedSet = new HashSet<UUID>(this.changedNodes.size() + this.deletedNodes.size());
+ retainedSet.addAll(this.changedNodes.keySet());
+ retainedSet.addAll(this.deletedNodes.keySet());
+
+ // Removed any cached nodes not already in the changed or deleted set
+ this.cachedNodes.keySet().retainAll(retainedSet);
+ } else {
+ // Throw out the old pending operations
+ this.requests.clear();
+ this.changedNodes.clear();
+ this.cachedNodes.clear();
+ this.deletedNodes.clear();
+ }
+
+ }
+
+ /**
+ * Refreshes (removes the cached state) for the node with the given UUID and any of its descendants.
+ * <p>
+ * If {@code keepChanges == true}, modified nodes will not have their state refreshed.
+ * </p>
+ *
+ * @param nodeUuid the UUID of the node that is to be saved; may not be null
+ * @param keepChanges indicates whether changed nodes should be kept or refreshed from the repository.
+ * @throws RepositoryException if any error resulting while saving the changes to the repository
+ */
+ public void refresh( UUID nodeUuid,
+ boolean keepChanges ) throws RepositoryException {
+ // Find the path of the given node ...
+ Path path = getPathFor(nodeUuid);
+
+ // Build the set of affected node UUIDs
+ Set<UUID> nodesUnderBranch = new HashSet<UUID>();
+ Stack<UUID> nodesToVisit = new Stack<UUID>();
+
+ nodesToVisit.add(nodeUuid);
+ while (!nodesToVisit.isEmpty()) {
+ UUID uuid = nodesToVisit.pop();
+ nodesUnderBranch.add(uuid);
+
+ NodeInfo nodeInfo = cachedNodes.get(uuid);
+ // Newly added nodes will be changedNodes but not cachedNodes
+ if (nodeInfo == null) nodeInfo = changedNodes.get(uuid);
+
+ if (nodeInfo != null) {
+ for (ChildNode childNode : nodeInfo.getChildren()) {
+ nodesToVisit.add(childNode.getUuid());
+ }
+ }
+ }
+
+ if (keepChanges) {
+ // Keep the pending operations
+ for (UUID uuid : nodesUnderBranch) {
+ // getPathFor can (and will) add entries to cachedNodes - hence the existence of nodesToCheck
+ if (getPathFor(uuid).isDecendantOf(path)) {
+ if (!this.changedNodes.containsKey(uuid) && !this.deletedNodes.containsKey(uuid)) {
+ this.cachedNodes.remove(uuid);
+ }
+ }
+ }
+ } else {
+ this.cachedNodes.keySet().removeAll(nodesUnderBranch);
+ this.changedNodes.keySet().removeAll(nodesUnderBranch);
+ this.deletedNodes.keySet().removeAll(nodesUnderBranch);
+
+ // Throw out the old pending operations
+ if (operations.isExecuteRequired()) {
+
+ // Make sure the builder has finished all the requests ...
+ this.requestBuilder.finishPendingRequest();
+
+ // Remove all of the enqueued requests for this branch ...
+ for (Iterator<Request> iter = this.requests.iterator(); iter.hasNext();) {
+ Request request = iter.next();
+ assert request instanceof ChangeRequest;
+ ChangeRequest change = (ChangeRequest)request;
+ if (change.changes(workspaceName, path)) {
+ iter.remove();
+ }
+ }
+ }
+ }
+
+ }
+
+ /**
* Save any changes that have been accumulated by this session.
*
* @throws RepositoryException if any error resulting while saving the changes to the repository
@@ -263,7 +361,7 @@
}
/**
- * Save any changes to the identified node or its decendants. The supplied node may not have been deleted or created in this
+ * Save any changes to the identified node or its descendants. The supplied node may not have been deleted or created in this
* session since the last save operation.
*
* @param nodeUuid the UUID of the node that is to be saved; may not be null
@@ -313,6 +411,22 @@
return;
}
+ /*
+ * branchUuids contains all the roots of the changes, but there may be further changes under the roots (e.g., a
+ * newly created node will have it's parent's UUID in branchUuids, but not the new node's uuid.
+ */
+ Set<UUID> uuidsUnderBranch = new HashSet<UUID>();
+ for (UUID branchUuid : branchUuids) {
+ uuidsUnderBranch.add(branchUuid);
+ ChangedNodeInfo changedNode = changedNodes.get(branchUuid);
+ if (changedNode != null) {
+ for (ChildNode childNode : changedNode.getChildren()) {
+ uuidsUnderBranch.add(childNode.getUuid());
+ }
+ }
+
+ }
+
// Now execute the branch ...
Graph.Batch branchBatch = store.batch(new BatchRequestBuilder(branchRequests));
try {
@@ -324,11 +438,9 @@
this.operations = store.batch(this.requestBuilder);
// Remove all the cached, changed or deleted items that were just saved ...
- for (UUID changedUuid : branchUuids) {
- cachedNodes.remove(changedUuid);
- changedNodes.remove(changedUuid);
- deletedNodes.remove(changedUuid);
- }
+ cachedNodes.keySet().removeAll(uuidsUnderBranch);
+ changedNodes.keySet().removeAll(uuidsUnderBranch);
+ deletedNodes.keySet().removeAll(uuidsUnderBranch);
} catch (org.jboss.dna.graph.property.PathNotFoundException e) {
throw new PathNotFoundException(e.getLocalizedMessage(), e);
} catch (RuntimeException e) {
@@ -402,7 +514,7 @@
if (info == null) return null; // no such property on this node
if (DnaLexicon.NODE_DEFINITON.equals(info.getPropertyName())) return null;
-
+
// Now create the appropriate JCR Property object ...
return createAndCacheJcrPropertyFor(info);
}
16 years, 8 months
DNA SVN: r831 - trunk/dna-jcr/src/main/java/org/jboss/dna/jcr.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-04-16 10:11:21 -0400 (Thu, 16 Apr 2009)
New Revision: 831
Modified:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaLexicon.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrBuiltinNodeTypeSource.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java
Log:
DNA-357 Hide dna:nodeDefinition Property from Users
Applied both patches. The first hides the "dna:nodeDefinition" property from the JCR layer (meaning it might exist in the graph layer, but won't appear as properties of JCR nodes). The second patch adds to "nt:base" a property definition for a "dna:nodeDefinition" property that is protected and not mandatory (nor autocreated). The spec is not clear as to whether a JCR implementation can add properties to "nt:base" (the required supertype of all node types), the spec is clear that an implementation can add properties to any of the built-in node types through mixins. Therefore, the second patch actually adds this new definition to "nt:base" by having "nt:base" extend the new "dna:defined" mixin, which has the new "dna:nodeDefinition" property definition.
Because the "dna:nodeDefinition" is protected, JCR clients will not be allowed to define another property with this name, nor will they be able to set the property (using a residual definition) to any value. All this validation is done through the normal process, requiring no code specific to "dna:nodeDefinition". Nicely done!
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaLexicon.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaLexicon.java 2009-04-16 13:58:49 UTC (rev 830)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaLexicon.java 2009-04-16 14:11:21 UTC (rev 831)
@@ -31,6 +31,7 @@
*/
public class DnaLexicon extends org.jboss.dna.graph.DnaLexicon {
+ public static final Name DEFINED = new BasicName(Namespace.URI, "defined");
public static final Name NAMESPACE = new BasicName(Namespace.URI, "namespace");
public static final Name NODE_DEFINITON = new BasicName(Namespace.URI, "nodeDefinition");
public static final Name NODE_TYPES = new BasicName(Namespace.URI, "nodeTypes");
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrBuiltinNodeTypeSource.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrBuiltinNodeTypeSource.java 2009-04-16 13:58:49 UTC (rev 830)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrBuiltinNodeTypeSource.java 2009-04-16 14:11:21 UTC (rev 831)
@@ -57,8 +57,28 @@
// Value trueValue = new JcrValue(context.getValueFactories(), null, PropertyType.BOOLEAN, Boolean.TRUE);
Value ntBaseValue = new JcrValue(context.getValueFactories(), null, PropertyType.NAME, JcrNtLexicon.BASE);
+ JcrNodeType defined = new JcrNodeType(
+ context,
+ NO_NODE_TYPE_MANAGER,
+ DnaLexicon.DEFINED,
+ NO_SUPERTYPES,
+ DnaLexicon.NODE_DEFINITON,
+ NO_CHILD_NODES,
+ Arrays.asList(new JcrPropertyDefinition[] {new JcrPropertyDefinition(
+ context,
+ null,
+ DnaLexicon.NODE_DEFINITON,
+ OnParentVersionBehavior.INITIALIZE.getJcrValue(),
+ false,
+ false,
+ true,
+ NO_DEFAULT_VALUES,
+ PropertyType.STRING,
+ NO_CONSTRAINTS,
+ false),}),
+ IS_A_MIXIN, UNORDERABLE_CHILD_NODES);
// Stubbing in child node and property definitions for now
- JcrNodeType base = new JcrNodeType(context, NO_NODE_TYPE_MANAGER, JcrNtLexicon.BASE, NO_SUPERTYPES, NO_PRIMARY_ITEM_NAME,
+ JcrNodeType base = new JcrNodeType(context, NO_NODE_TYPE_MANAGER, JcrNtLexicon.BASE, Arrays.asList(new JcrNodeType[] {defined}), NO_PRIMARY_ITEM_NAME,
NO_CHILD_NODES, Arrays.asList(new JcrPropertyDefinition[] {
new JcrPropertyDefinition(context, null, JcrLexicon.PRIMARY_TYPE,
OnParentVersionBehavior.COMPUTE.getJcrValue(), true,
@@ -565,7 +585,7 @@
// NOT_MIXIN, UNORDERABLE_CHILD_NODES);
// Disabling version-related types until DNA supports versioning, as per section 4.11 of the 1.0.1 specification
- nodeTypes.addAll(Arrays.asList(new JcrNodeType[] {base, unstructured, childNodeDefinition, file, folder, frozenNode,
+ nodeTypes.addAll(Arrays.asList(new JcrNodeType[] {defined, base, unstructured, childNodeDefinition, file, folder, frozenNode,
hierarchyNode, linkedFile, nodeType, propertyDefinition, query, resource, nodeType /*, version, versionHistory,
versionLabels, versionedChild */}));
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java 2009-04-16 13:58:49 UTC (rev 830)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java 2009-04-16 14:11:21 UTC (rev 831)
@@ -401,6 +401,8 @@
PropertyInfo info = findPropertyInfo(propertyId); // throws PathNotFoundException if node not there
if (info == null) return null; // no such property on this node
+ if (DnaLexicon.NODE_DEFINITON.equals(info.getPropertyName())) return null;
+
// Now create the appropriate JCR Property object ...
return createAndCacheJcrPropertyFor(info);
}
@@ -411,7 +413,9 @@
Set<Name> propertyNames = info.getPropertyNames();
Collection<AbstractJcrProperty> result = new ArrayList<AbstractJcrProperty>(propertyNames.size());
for (Name propertyName : propertyNames) {
- result.add(findJcrProperty(new PropertyId(nodeUuid, propertyName)));
+ if (!DnaLexicon.NODE_DEFINITON.equals(propertyName)) {
+ result.add(findJcrProperty(new PropertyId(nodeUuid, propertyName)));
+ }
}
return result;
}
16 years, 8 months
DNA SVN: r830 - trunk/dna-jcr/src/main/java/org/jboss/dna/jcr.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-04-16 09:58:49 -0400 (Thu, 16 Apr 2009)
New Revision: 830
Modified:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java
Log:
DNA-356 Need to Throw ItemExistsException if addNode Call Fails Due to SNS
Added a patch that changes SessionCache.NodeEditor.addNode(...) to throw an ItemExistsException if the node cannot be added because an item at the specified path already exists and same-name siblings are not allowed, per the specification (see the JIRA issue for the details). An additional lookup of the child node definition is performed, but this isn't a problem since it is already an error case and the extra work is justified to provide more useful information in the exception.
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java 2009-04-15 22:42:18 UTC (rev 829)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java 2009-04-16 13:58:49 UTC (rev 830)
@@ -37,6 +37,7 @@
import java.util.UUID;
import javax.jcr.InvalidItemStateException;
import javax.jcr.Item;
+import javax.jcr.ItemExistsException;
import javax.jcr.ItemNotFoundException;
import javax.jcr.Node;
import javax.jcr.PathNotFoundException;
@@ -842,7 +843,7 @@
if (desiredUuid == null) desiredUuid = UUID.randomUUID();
// Verify that this node accepts a child of the supplied name (given any existing SNS nodes) ...
- int numSns = node.getChildren().getCountOfSameNameSiblingsWithName(name);
+ int numSns = node.getChildren().getCountOfSameNameSiblingsWithName(name) + 1;
JcrNodeDefinition definition = nodeTypes().findChildNodeDefinition(node.getPrimaryTypeName(),
node.getMixinTypeNames(),
name,
@@ -851,6 +852,21 @@
true);
// Make sure there was a valid child node definition ...
if (definition == null) {
+
+ // Check if the definition would have worked with less SNS
+ definition = nodeTypes().findChildNodeDefinition(node.getPrimaryTypeName(),
+ node.getMixinTypeNames(),
+ name,
+ primaryTypeName,
+ numSns - 1,
+ true);
+ if (definition != null) {
+ // Only failed because there was no SNS definition - throw ItemExistsException per 7.1.4 of 1.0.1 spec
+ Path pathForChild = pathFactory.create(getPathFor(node), name, numSns + 1);
+ String msg = JcrI18n.noSnsDefinitionForNode.text(pathForChild, workspaceName());
+ throw new ItemExistsException(msg);
+ }
+ // Didn't work for other reasons - throw ConstraintViolationException
Path pathForChild = pathFactory.create(getPathFor(node), name, numSns + 1);
String msg = JcrI18n.nodeDefinitionCouldNotBeDeterminedForNode.text(pathForChild, workspaceName());
throw new ConstraintViolationException(msg);
16 years, 8 months