jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1136013 - in /jackrabbit/sandbox/spi2microkernel/src: main/java/org/apache/jackrabbit/spi2microkernel/util/Values.java test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java
Date Wed, 15 Jun 2011 12:47:26 GMT
Author: mduerig
Date: Wed Jun 15 12:47:26 2011
New Revision: 1136013

URL: http://svn.apache.org/viewvc?rev=1136013&view=rev
Log:
spi2microkernel prototype (WIP)
value types: date

Modified:
    jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Values.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/Values.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Values.java?rev=1136013&r1=1136012&r2=1136013&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Values.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Values.java
Wed Jun 15 12:47:26 2011
@@ -26,7 +26,6 @@ import org.apache.jackrabbit.spi.commons
 
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
-import java.math.BigDecimal;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -89,7 +88,7 @@ public final class Values {
         put(Double.class, valueFactory);
         put(TYPES[PropertyType.DOUBLE], valueFactory);
 
-        put(Boolean.class, new ValueFactory() {
+        valueFactory = new ValueFactory() {
             public QValue create(Object value) throws RepositoryException {
                 return FACTORY.create((Boolean) value);
             }
@@ -97,29 +96,32 @@ public final class Values {
             public QValue create(String value) throws RepositoryException {
                 return FACTORY.create(value, PropertyType.BOOLEAN);
             }
-        });
+        };
+        put(Boolean.class, valueFactory);
+        put(TYPES[PropertyType.BOOLEAN], valueFactory);
 
         valueFactory = new ValueFactory() {
             public QValue create(Object value) throws RepositoryException {
-                return FACTORY.create((BigDecimal) value);
+                throw new RepositoryException("Invalid value " + value);
             }
 
             public QValue create(String value) throws RepositoryException {
-                return FACTORY.create(value, PropertyType.DECIMAL);   
+                return FACTORY.create(value, PropertyType.DECIMAL);
             }
         };
-        put(BigDecimal.class, valueFactory);
         put(TYPES[PropertyType.DECIMAL], valueFactory);
 
-        put(Integer.class, new ValueFactory() {
+        valueFactory = new ValueFactory() {
             public QValue create(Object value) throws RepositoryException {
-                return FACTORY.create((Integer) value);
+                throw new RepositoryException("Invalid value " + value);
             }
 
             public QValue create(String value) throws RepositoryException {
-                return null; // todo implement create
+                return FACTORY.create(value, PropertyType.DATE);
             }
-        });
+        };
+        put(TYPES[PropertyType.DATE], valueFactory);
+
         // todo handle other value types
     }};
 
@@ -172,8 +174,10 @@ public final class Values {
             case PropertyType.DECIMAL:
                 return typeEncode(type, value.getString());
 
-                // todo implement support for the other value types
             case PropertyType.DATE:
+                return typeEncode(type, value.getString());
+
+                // todo implement support for the other value types
             case PropertyType.BINARY:
             case PropertyType.NAME:
             case PropertyType.PATH:

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=1136013&r1=1136012&r2=1136013&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
Wed Jun 15 12:47:26 2011
@@ -37,6 +37,7 @@ import javax.jcr.RepositoryFactory;
 import javax.jcr.Session;
 import javax.jcr.Value;
 import java.math.BigDecimal;
+import java.util.Calendar;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -382,7 +383,39 @@ public class RepositoryTest {
         }
     }
 
-    @Ignore // todo set element type 
+    @Test
+    public void addDateProperty() throws RepositoryException {
+        Node parentNode = getNode(testPath);
+        addProperty(parentNode, "date", getSession().getValueFactory().createValue(Calendar.getInstance()));
+    }
+
+    @Test
+    public void addMultiValuedDate() throws RepositoryException {
+        Node parentNode = getNode(testPath);
+        Value[] values = new Value[2];
+        Calendar calendar = Calendar.getInstance();
+        values[0] = getSession().getValueFactory().createValue(calendar);
+        calendar.add(Calendar.DAY_OF_MONTH, 1);
+        values[1] = getSession().getValueFactory().createValue(calendar);
+
+        parentNode.setProperty("multi date", values);
+        parentNode.getSession().save();
+
+        Session session2 = getRepository().login();
+        try {
+            Property property = session2.getProperty(testPath + "/multi date");
+            assertTrue(property.isMultiple());
+            Value[] values2 = property.getValues();
+            assertEquals(2, values.length);
+            assertEquals(values[0], values2[0]);
+            assertEquals(values[1], values2[1]);
+        }
+        finally {
+            session2.logout();
+        }
+    }
+
+    @Ignore // todo set element type
     @Test
     public void addEmptyMultiValuedProperty() throws RepositoryException {
         Node parentNode = getNode(testPath);



Mime
View raw message