jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1135599 - in /jackrabbit/sandbox/spi2microkernel/src: main/java/org/apache/jackrabbit/spi2microkernel/util/Values.java test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java
Date Tue, 14 Jun 2011 14:23:36 GMT
Author: mduerig
Date: Tue Jun 14 14:23:36 2011
New Revision: 1135599

URL: http://svn.apache.org/viewvc?rev=1135599&view=rev
Log:
spi2microkernel prototype (WIP)
started implementing value types. Way to go still...

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=1135599&r1=1135598&r2=1135599&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
Tue Jun 14 14:23:36 2011
@@ -40,7 +40,13 @@ public final class Values {
     private static final Map<Class<?>, ValueFactory> VALUE_FACTORIES = new HashMap<Class<?>,
ValueFactory>() {{
         put(String.class, new ValueFactory() {
             public QValue create(Object value) throws RepositoryException {
-                return FACTORY.create((String) value, PropertyType.STRING);
+                // todo refactor, clean up, implement value types
+                if ("F:NAN".equals(value)) {
+                    return FACTORY.create(Double.NaN);
+                }
+                else {
+                    return FACTORY.create((String) value, PropertyType.STRING);
+                }
             }
         });
         put(Boolean.class, new ValueFactory() {
@@ -84,23 +90,27 @@ public final class Values {
     }
 
     public static String create(QValue value) throws RepositoryException {
+        // todo implement value types
         switch(value.getType()) {
-            case PropertyType.STRING:
+            case PropertyType.STRING:    // S: (String)
                 return JsonBuilder.quote(JsonBuilder.escape(value.getString()));
 
-            case PropertyType.LONG:
-            case PropertyType.DOUBLE:
-            case PropertyType.BOOLEAN:
-            case PropertyType.DECIMAL:
+            case PropertyType.DOUBLE:    // F: (Float)
+                if (Double.isNaN(value.getDouble())) {
+                    return "\"F:NAN\"";
+                }
+            case PropertyType.LONG:      // I: (Integer)
+            case PropertyType.BOOLEAN:   // L: (Logical)
+            case PropertyType.DECIMAL:   // D: (Decimal)
                 return value.getString();
 
-            case PropertyType.DATE:
-            case PropertyType.BINARY:
-            case PropertyType.NAME:
-            case PropertyType.PATH:
-            case PropertyType.REFERENCE:
-            case PropertyType.WEAKREFERENCE:
-            case PropertyType.URI:
+            case PropertyType.DATE:      // C: (Calendar)
+            case PropertyType.BINARY:    // Y: (binarY)
+            case PropertyType.NAME:      // N: (Name)
+            case PropertyType.PATH:      // P: (Path)
+            case PropertyType.REFERENCE: // R: (Reference)
+            case PropertyType.WEAKREFERENCE:  // W: (Weakreference)
+            case PropertyType.URI:       // U: (Uri)
             default:  // todo implement support for the other value types
                 throw new UnsupportedRepositoryOperationException("Cannot handle value of
type " +
                         PropertyType.nameFromValue(value.getType()));

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=1135599&r1=1135598&r2=1135599&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
Tue Jun 14 14:23:36 2011
@@ -326,6 +326,21 @@ public class RepositoryTest {
     }
 
     @Test
+    public void setDoubleNaNProperty() throws RepositoryException {
+        Node parentNode = getNode(testPath);
+        addProperty(parentNode, "NaN", getSession().getValueFactory().createValue(Double.NaN));
+
+        Session session2 = getRepository().login();
+        try {
+            Property property2 = session2.getProperty(testPath + "/NaN");
+            assertTrue(Double.isNaN(property2.getDouble()));
+        }
+        finally {
+            session2.logout();
+        }
+    }
+
+    @Test
     public void setMultiValuedProperty() throws RepositoryException {
         Node parentNode = getNode(testPath);
         Value[] values = new Value[2];



Mime
View raw message