incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jus...@apache.org
Subject svn commit: r1304366 - in /sling/trunk/bundles/jcr/resource/src: main/java/org/apache/sling/jcr/resource/ test/java/org/apache/sling/jcr/resource/internal/
Date Fri, 23 Mar 2012 14:22:41 GMT
Author: justin
Date: Fri Mar 23 14:22:41 2012
New Revision: 1304366

URL: http://svn.apache.org/viewvc?rev=1304366&view=rev
Log:
SLING-2446 - adding support for BigDecimal values in JcrPropertyMap

Modified:
    sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrPropertyMap.java
    sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrResourceUtil.java
    sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrPropertyMapTest.java

Modified: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrPropertyMap.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrPropertyMap.java?rev=1304366&r1=1304365&r2=1304366&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrPropertyMap.java
(original)
+++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrPropertyMap.java
Fri Mar 23 14:22:41 2012
@@ -22,6 +22,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.Serializable;
 import java.lang.reflect.Array;
+import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Collection;
@@ -425,6 +426,9 @@ public class JcrPropertyMap
         } else if (Double.class == type) {
             return (T) Double.valueOf(jcrValue.getDouble());
 
+        } else if (BigDecimal.class == type) {
+            return (T) jcrValue.getDecimal();
+
         } else if (Boolean.class == type) {
             return (T) Boolean.valueOf(jcrValue.getBoolean());
 

Modified: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrResourceUtil.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrResourceUtil.java?rev=1304366&r1=1304365&r2=1304366&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrResourceUtil.java
(original)
+++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrResourceUtil.java
Fri Mar 23 14:22:41 2012
@@ -55,6 +55,8 @@ public class JcrResourceUtil {
     /** Converts a JCR Value to a corresponding Java Object */
     public static Object toJavaObject(Value value) throws RepositoryException {
         switch (value.getType()) {
+            case PropertyType.DECIMAL:
+                return value.getDecimal();
             case PropertyType.BINARY:
                 return new LazyInputStream(value);
             case PropertyType.BOOLEAN:

Modified: sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrPropertyMapTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrPropertyMapTest.java?rev=1304366&r1=1304365&r2=1304366&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrPropertyMapTest.java
(original)
+++ sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrPropertyMapTest.java
Fri Mar 23 14:22:41 2012
@@ -20,6 +20,7 @@ package org.apache.sling.jcr.resource.in
 
 import java.io.ByteArrayInputStream;
 import java.io.InputStream;
+import java.math.BigDecimal;
 import java.util.Calendar;
 import java.util.Date;
 import java.util.Iterator;
@@ -72,6 +73,7 @@ public class JcrPropertyMapTest extends 
         testValue(rootNode, 5L);
         testValue(rootNode, 1.4D);
         testValue(rootNode, true);
+        testValue(rootNode, BigDecimal.TEN);
     }
 
     public void testTypeByClass() throws Exception {
@@ -89,6 +91,8 @@ public class JcrPropertyMapTest extends 
         testValue(rootNode, cal, Calendar.class);
         testValue(rootNode, cal, Date.class);
         testValue(rootNode, cal, Long.class);
+
+        testValue(rootNode, BigDecimal.TEN, BigDecimal.class);
     }
 
     public void testTypeByDefaultValue() throws Exception {
@@ -111,6 +115,8 @@ public class JcrPropertyMapTest extends 
         testValue(rootNode, cal, refCal);
         testValue(rootNode, cal, refDate);
         testValue(rootNode, cal, refTime);
+
+        testValue(rootNode, BigDecimal.TEN, BigDecimal.ONE);
     }
 
     public void testDefaultValue() throws Exception {
@@ -132,6 +138,8 @@ public class JcrPropertyMapTest extends 
         testDefaultValue(rootNode, refCal);
         testDefaultValue(rootNode, refDate);
         testDefaultValue(rootNode, refTime);
+
+        testDefaultValue(rootNode, BigDecimal.TEN);
     }
 
     public void testProperty() throws Exception {
@@ -248,6 +256,8 @@ public class JcrPropertyMapTest extends 
             jcrValue = fac.createValue(((Double) value).doubleValue());
         } else if (value instanceof Long) {
             jcrValue = fac.createValue(((Long) value).longValue());
+        } else if (value instanceof BigDecimal) {
+            jcrValue = fac.createValue((BigDecimal) value);
         } else {
             fail("Cannot create JCR value from " + value);
             return null;



Mime
View raw message