Author: rhauch
Date: 2009-04-07 23:06:01 -0400 (Tue, 07 Apr 2009)
New Revision: 813
Modified:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrMultiValueProperty.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrTckTest.java
Log:
DNA-345 JcrMultiValueProperty.setValues(null) Doesn't Remove Property
Applied the patch, and also uncommented a few more TCK unit tests after additional
corrections to the AbstractJcrNode.setProperty implementations.
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-07 22:28:53
UTC (rev 812)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java 2009-04-08 03:06:01
UTC (rev 813)
@@ -672,7 +672,8 @@
JcrNodeDefinition match =
this.cache.nodeTypes().findChildNodeDefinition(mixinCandidateType.getInternalName(),
Collections.<Name>emptyList(),
nodeName,
-
childNode.getPrimaryNodeType().getInternalName(),
+
childNode.getPrimaryNodeType()
+
.getInternalName(),
snsCount,
false);
@@ -996,7 +997,7 @@
throws ValueFormatException, VersionException, LockException,
ConstraintViolationException, RepositoryException {
if (value == null) {
// If there is an existing property, then remove it ...
- return removeExistingSingleValuedProperty(name);
+ return removeExistingValuedProperty(name);
}
return cache.findJcrProperty(editor().setProperty(nameFrom(name),
valueFrom(value)));
@@ -1024,7 +1025,7 @@
throws ValueFormatException, VersionException, LockException,
ConstraintViolationException, RepositoryException {
if (value == null) {
// If there is an existing property, then remove it ...
- return removeExistingSingleValuedProperty(name);
+ return removeExistingValuedProperty(name);
}
return cache.findJcrProperty(editor().setProperty(nameFrom(name),
valueFrom(value)));
}
@@ -1051,7 +1052,7 @@
throws ValueFormatException, VersionException, LockException,
ConstraintViolationException, RepositoryException {
if (value == null) {
// If there is an existing property, then remove it ...
- return removeExistingSingleValuedProperty(name);
+ return removeExistingValuedProperty(name);
}
return cache.findJcrProperty(editor().setProperty(nameFrom(name),
valueFrom(value)));
}
@@ -1066,7 +1067,7 @@
throws ValueFormatException, VersionException, LockException,
ConstraintViolationException, RepositoryException {
if (value == null) {
// If there is an existing property, then remove it ...
- return removeExistingSingleValuedProperty(name);
+ return removeExistingValuedProperty(name);
}
return cache.findJcrProperty(editor().setProperty(nameFrom(name),
valueFrom(PropertyType.STRING, value)));
}
@@ -1082,7 +1083,7 @@
throws ValueFormatException, VersionException, LockException,
ConstraintViolationException, RepositoryException {
if (value == null) {
// If there is an existing property, then remove it ...
- return removeExistingSingleValuedProperty(name);
+ return removeExistingValuedProperty(name);
}
return cache.findJcrProperty(editor().setProperty(nameFrom(name), valueFrom(type,
value)));
}
@@ -1095,6 +1096,10 @@
public final Property setProperty( String name,
String[] values )
throws ValueFormatException, VersionException, LockException,
ConstraintViolationException, RepositoryException {
+ if (values == null) {
+ // If there is an existing property, then remove it ...
+ return removeExistingValuedProperty(name);
+ }
return cache.findJcrProperty(editor().setProperty(nameFrom(name),
valuesFrom(PropertyType.STRING, values)));
}
@@ -1107,6 +1112,10 @@
String[] values,
int type )
throws ValueFormatException, VersionException, LockException,
ConstraintViolationException, RepositoryException {
+ if (values == null) {
+ // If there is an existing property, then remove it ...
+ return removeExistingValuedProperty(name);
+ }
return cache.findJcrProperty(editor().setProperty(nameFrom(name),
valuesFrom(type, values)));
}
@@ -1120,17 +1129,16 @@
throws ValueFormatException, VersionException, LockException,
ConstraintViolationException, RepositoryException {
if (value == null) {
// If there is an existing property, then remove it ...
- return removeExistingSingleValuedProperty(name);
+ return removeExistingValuedProperty(name);
}
return cache.findJcrProperty(editor().setProperty(nameFrom(name),
(JcrValue)value));
}
- protected final Property removeExistingSingleValuedProperty( String name )
+ protected final Property removeExistingValuedProperty( String name )
throws ValueFormatException, VersionException, LockException,
ConstraintViolationException, RepositoryException {
PropertyId id = new PropertyId(nodeUuid, nameFrom(name));
AbstractJcrProperty property = cache.findJcrProperty(id);
if (property != null) {
- assert !property.isMultiple();
property.remove();
return property;
}
@@ -1147,6 +1155,10 @@
Value value,
int type )
throws ValueFormatException, VersionException, LockException,
ConstraintViolationException, RepositoryException {
+ if (value == null) {
+ // If there is an existing property, then remove it ...
+ return removeExistingValuedProperty(name);
+ }
return cache.findJcrProperty(editor().setProperty(nameFrom(name),
((JcrValue)value).asType(type)));
}
@@ -1158,7 +1170,29 @@
public final Property setProperty( String name,
Value[] values )
throws ValueFormatException, VersionException, LockException,
ConstraintViolationException, RepositoryException {
- return cache.findJcrProperty(editor().setProperty(nameFrom(name), values));
+ if (values == null) {
+ // If there is an existing property, then remove it ...
+ return removeExistingValuedProperty(name);
+ }
+ int len = values.length;
+ Value[] newValues = null;
+ if (len == 0) {
+ newValues = JcrMultiValueProperty.EMPTY_VALUES;
+ } else {
+ List<Value> valuesWithDesiredType = new ArrayList<Value>(len);
+ for (int i = 0; i != len; ++i) {
+ Value value = values[i];
+ if (value == null) continue;
+ valuesWithDesiredType.add(value);
+ }
+ if (valuesWithDesiredType.isEmpty()) {
+ newValues = JcrMultiValueProperty.EMPTY_VALUES;
+ } else {
+ newValues = valuesWithDesiredType.toArray(new
Value[valuesWithDesiredType.size()]);
+ }
+ }
+ // Set the value, perhaps to an empty array ...
+ return cache.findJcrProperty(editor().setProperty(nameFrom(name), newValues));
}
/**
@@ -1170,6 +1204,10 @@
Value[] values,
int type )
throws ValueFormatException, VersionException, LockException,
ConstraintViolationException, RepositoryException {
+ if (values == null) {
+ // If there is an existing property, then remove it ...
+ return removeExistingValuedProperty(name);
+ }
int len = values.length;
Value[] newValues = null;
if (len == 0) {
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrMultiValueProperty.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrMultiValueProperty.java 2009-04-07
22:28:53 UTC (rev 812)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrMultiValueProperty.java 2009-04-08
03:06:01 UTC (rev 813)
@@ -184,8 +184,14 @@
*/
public final void setValue( Value[] values )
throws ValueFormatException, VersionException, LockException,
ConstraintViolationException, RepositoryException {
+
+ if (values == null) {
+ this.remove();
+ return;
+ }
+
Value[] newValues = null;
- if (values != null && values.length != 0) {
+ if (values.length != 0) {
int numValues = values.length;
List<Value> valuesList = new ArrayList<Value>(numValues);
ValueFactory<?> factory = null;
@@ -257,8 +263,13 @@
*/
public final void setValue( String[] values )
throws ValueFormatException, VersionException, LockException,
ConstraintViolationException, RepositoryException {
+ if (values == null) {
+ this.remove();
+ return;
+ }
+
Value[] jcrValues = null;
- if (values != null && values.length != 0) {
+ if (values.length != 0) {
int numValues = values.length;
List<Value> valuesList = new ArrayList<Value>(numValues);
jcrValues = new JcrValue[numValues];
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-07 22:28:53 UTC
(rev 812)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrTckTest.java 2009-04-08 03:06:01 UTC
(rev 813)
@@ -57,8 +57,16 @@
import org.apache.jackrabbit.test.api.SetValueDoubleTest;
import org.apache.jackrabbit.test.api.SetValueLongTest;
import org.apache.jackrabbit.test.api.SetValueReferenceTest;
+import org.apache.jackrabbit.test.api.SetValueStringTest;
import org.apache.jackrabbit.test.api.SetValueVersionExceptionTest;
import org.apache.jackrabbit.test.api.ValueFactoryTest;
+import org.apache.jackrabbit.test.api.WorkspaceCloneReferenceableTest;
+import org.apache.jackrabbit.test.api.WorkspaceCloneSameNameSibsTest;
+import org.apache.jackrabbit.test.api.WorkspaceCloneTest;
+import org.apache.jackrabbit.test.api.WorkspaceCloneVersionableTest;
+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.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.Graph;
@@ -182,7 +190,7 @@
addTestSuite(SetValueDoubleTest.class);
addTestSuite(SetValueLongTest.class);
addTestSuite(SetValueReferenceTest.class);
- // addTestSuite(SetValueStringTest.class);
+ addTestSuite(SetValueStringTest.class);
addTestSuite(SetValueConstraintViolationExceptionTest.class);
// addTestSuite(SetValueValueFormatExceptionTest.class);
addTestSuite(SetValueVersionExceptionTest.class);
@@ -207,13 +215,13 @@
addTestSuite(NodeCanAddMixinTest.class);
addTestSuite(NodeRemoveMixinTest.class);
//
- // addTestSuite(WorkspaceCloneReferenceableTest.class);
- // addTestSuite(WorkspaceCloneSameNameSibsTest.class);
- // addTestSuite(WorkspaceCloneTest.class);
- // addTestSuite(WorkspaceCloneVersionableTest.class);
- // addTestSuite(WorkspaceCopyBetweenWorkspacesReferenceableTest.class);
- // addTestSuite(WorkspaceCopyBetweenWorkspacesSameNameSibsTest.class);
- // addTestSuite(WorkspaceCopyBetweenWorkspacesTest.class);
+ addTestSuite(WorkspaceCloneReferenceableTest.class);
+ addTestSuite(WorkspaceCloneSameNameSibsTest.class);
+ addTestSuite(WorkspaceCloneTest.class);
+ addTestSuite(WorkspaceCloneVersionableTest.class);
+ addTestSuite(WorkspaceCopyBetweenWorkspacesReferenceableTest.class);
+ addTestSuite(WorkspaceCopyBetweenWorkspacesSameNameSibsTest.class);
+ addTestSuite(WorkspaceCopyBetweenWorkspacesTest.class);
// addTestSuite(WorkspaceCopyBetweenWorkspacesVersionableTest.class);
// addTestSuite(WorkspaceCopyReferenceableTest.class);
// addTestSuite(WorkspaceCopySameNameSibsTest.class);