jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1147253 - in /jackrabbit/sandbox/spi2microkernel/src: main/java/org/apache/jackrabbit/spi2microkernel/util/ItemInfos.java test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java
Date Fri, 15 Jul 2011 17:09:21 GMT
Author: mduerig
Date: Fri Jul 15 17:09:21 2011
New Revision: 1147253

URL: http://svn.apache.org/viewvc?rev=1147253&view=rev
Log:
spi2microkernel (WIP)
- workaround to JCR-2992: set type of empty multi valued property to String

Modified:
    jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/ItemInfos.java
    jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java

Modified: jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/ItemInfos.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/ItemInfos.java?rev=1147253&r1=1147252&r2=1147253&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/ItemInfos.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/ItemInfos.java
Fri Jul 15 17:09:21 2011
@@ -34,6 +34,7 @@ import org.apache.jackrabbit.spi.commons
 import org.json.simple.parser.JSONParser;
 import org.json.simple.parser.ParseException;
 
+import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
 import java.io.IOException;
 import java.util.Iterator;
@@ -165,6 +166,7 @@ public final class ItemInfos {
         private Name name;
         private String currentKey;
         private boolean isObjectEmpty;
+        private boolean isArrayEmpty;
         private NodeInfoBuilder nodeInfoBuilder;
         private PropertyInfoBuilder propertyInfoBuilder;
 
@@ -238,6 +240,7 @@ public final class ItemInfos {
                 }
 
                 if (propertyInfoBuilder == null) {
+                    // Single valued property
                     nodeInfoBuilder.createPropertyInfo()
                         .setName(Paths.stringToName(currentKey))
                         .addValue(Values.objectToValue(value, binaryHandler))
@@ -246,6 +249,8 @@ public final class ItemInfos {
                     return !infoListener.done();
                 }
                 else {
+                    // Multi valued property
+                    isArrayEmpty = false;
                     propertyInfoBuilder.addValue(Values.objectToValue(value, binaryHandler));
                     return true;
                 }
@@ -257,6 +262,7 @@ public final class ItemInfos {
 
         @Override
         public boolean startArray() throws ParseException, IOException {
+            isArrayEmpty = true;
             propertyInfoBuilder = nodeInfoBuilder.createPropertyInfo()
                 .setName(Paths.stringToName(currentKey))
                 .setMultivalued(true);
@@ -267,6 +273,10 @@ public final class ItemInfos {
         @Override
         public boolean endArray() throws ParseException, IOException {
             try {
+                if (isArrayEmpty) {
+                    // xxx workaround for JCR-2992: set to string. This seems to be accepted
by clients. 
+                    propertyInfoBuilder.setType(PropertyType.STRING);
+                }
                 propertyInfoBuilder.build();
                 propertyInfoBuilder = null;
                 return !infoListener.done();

Modified: jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java?rev=1147253&r1=1147252&r2=1147253&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java
Fri Jul 15 17:09:21 2011
@@ -311,6 +311,7 @@ public class RepositoryTest {
         try {
             Property property = session2.getProperty(testPath + "/multi string");
             assertTrue(property.isMultiple());
+            assertEquals(PropertyType.STRING, property.getType());
             Value[] values2 = property.getValues();
             assertEquals(values.length, values2.length);
             assertEquals(values[0], values2[0]);
@@ -341,6 +342,7 @@ public class RepositoryTest {
         try {
             Property property = session2.getProperty(testPath + "/multi long");
             assertTrue(property.isMultiple());
+            assertEquals(PropertyType.LONG, property.getType());
             Value[] values2 = property.getValues();
             assertEquals(values.length, values2.length);
             assertEquals(values[0], values2[0]);
@@ -372,6 +374,7 @@ public class RepositoryTest {
         try {
             Property property = session2.getProperty(testPath + "/multi double");
             assertTrue(property.isMultiple());
+            assertEquals(PropertyType.DOUBLE, property.getType());
             Value[] values2 = property.getValues();
             assertEquals(values.length, values2.length);
             assertEquals(values[0], values2[0]);
@@ -402,6 +405,7 @@ public class RepositoryTest {
         try {
             Property property = session2.getProperty(testPath + "/multi boolean");
             assertTrue(property.isMultiple());
+            assertEquals(PropertyType.BOOLEAN, property.getType());
             Value[] values2 = property.getValues();
             assertEquals(values.length, values2.length);
             assertEquals(values[0], values2[0]);
@@ -432,6 +436,7 @@ public class RepositoryTest {
         try {
             Property property = session2.getProperty(testPath + "/multi decimal");
             assertTrue(property.isMultiple());
+            assertEquals(PropertyType.DECIMAL, property.getType());
             Value[] values2 = property.getValues();
             assertEquals(values.length, values2.length);
             assertEquals(values[0], values2[0]);
@@ -464,6 +469,7 @@ public class RepositoryTest {
         try {
             Property property = session2.getProperty(testPath + "/multi date");
             assertTrue(property.isMultiple());
+            assertEquals(PropertyType.DATE, property.getType());
             Value[] values2 = property.getValues();
             assertEquals(values.length, values2.length);
             assertEquals(values[0], values2[0]);
@@ -494,6 +500,7 @@ public class RepositoryTest {
         try {
             Property property = session2.getProperty(testPath + "/multi uri");
             assertTrue(property.isMultiple());
+            assertEquals(PropertyType.URI, property.getType());
             Value[] values2 = property.getValues();
             assertEquals(values.length, values2.length);
             assertEquals(values[0], values2[0]);
@@ -524,6 +531,7 @@ public class RepositoryTest {
         try {
             Property property = session2.getProperty(testPath + "/multi name");
             assertTrue(property.isMultiple());
+            assertEquals(PropertyType.NAME, property.getType());
             Value[] values2 = property.getValues();
             assertEquals(values.length, values2.length);
             assertEquals(values[0], values2[0]);
@@ -554,6 +562,7 @@ public class RepositoryTest {
         try {
             Property property = session2.getProperty(testPath + "/multi path");
             assertTrue(property.isMultiple());
+            assertEquals(PropertyType.PATH, property.getType());
             Value[] values2 = property.getValues();
             assertEquals(values.length, values2.length);
             assertEquals(values[0], values2[0]);
@@ -600,6 +609,7 @@ public class RepositoryTest {
         try {
             Property property = session2.getProperty(testPath + "/multi binary");
             assertTrue(property.isMultiple());
+            assertEquals(PropertyType.BINARY, property.getType());
             Value[] values2 = property.getValues();
             assertEquals(values.length, values2.length);
             assertEquals(values[0], values2[0]);
@@ -638,6 +648,7 @@ public class RepositoryTest {
         try {
             Property property = session2.getProperty(testPath + "/multi reference");
             assertTrue(property.isMultiple());
+            assertEquals(PropertyType.REFERENCE, property.getType());
             Value[] values2 = property.getValues();
             assertEquals(values.length, values2.length);
             assertEquals(values[0], values2[0]);
@@ -676,6 +687,7 @@ public class RepositoryTest {
         try {
             Property property = session2.getProperty(testPath + "/multi weak reference");
             assertTrue(property.isMultiple());
+            assertEquals(PropertyType.WEAKREFERENCE, property.getType());
             Value[] values2 = property.getValues();
             assertEquals(values.length, values2.length);
             assertEquals(values[0], values2[0]);
@@ -686,7 +698,7 @@ public class RepositoryTest {
         }
     }
 
-    @Ignore // todo set element type, but see JCR-2992
+    @Ignore // todo set element type correctly , but see JCR-2992
     @Test
     public void addEmptyMultiValuedProperty() throws RepositoryException {
         Node parentNode = getNode(testPath);
@@ -708,6 +720,27 @@ public class RepositoryTest {
         }
     }
 
+    @Test  // todo set element type correctly , but see JCR-2992
+    public void addEmptyMultiValuedProperty_JCR_2992_WorkaroundTest() throws RepositoryException
{
+        Node parentNode = getNode(testPath);
+        Value[] values = new Value[0];
+
+        parentNode.setProperty("multi empty", values, PropertyType.BOOLEAN);
+        parentNode.getSession().save();
+
+        Session session2 = getRepository().login();
+        try {
+            Property property = session2.getProperty(testPath + "/multi empty");
+            assertTrue(property.isMultiple());
+            assertEquals(PropertyType.STRING, property.getType());
+            Value[] values2 = property.getValues();
+            assertEquals(0, values2.length);
+        }
+        finally {
+            session2.logout();
+        }
+    }
+
     @Test
     public void addMultiValuedStringWithNull() throws RepositoryException {
         Node parentNode = getNode(testPath);



Mime
View raw message