jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r938969 - in /jackrabbit/trunk: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/ jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/value/ jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2davex/
Date Wed, 28 Apr 2010 12:33:31 GMT
Author: stefan
Date: Wed Apr 28 12:33:30 2010
New Revision: 938969

URL: http://svn.apache.org/viewvc?rev=938969&view=rev
Log:
JCR-2619 improved internal representation of DATE values

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/value/AbstractQValue.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/value/AbstractQValueFactory.java
    jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2davex/QValueFactoryImpl.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java?rev=938969&r1=938968&r2=938969&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java
Wed Apr 28 12:33:30 2010
@@ -442,7 +442,12 @@ public class InternalValue extends Abstr
 
     public Calendar getDate() {
         assert val != null && type == PropertyType.DATE;
-        return (Calendar) val;
+        try {
+            return getCalendar();
+        } catch (RepositoryException ignore) {
+            assert false;
+            return null;
+        }
     }
 
     /**
@@ -509,21 +514,6 @@ public class InternalValue extends Abstr
         }
     }
 
-    //-------------------------------------------< java.lang.Object overrides >
-    /**
-     * Returns the string representation of this internal value.
-     *
-     * @return string representation of this internal value
-     */
-    public String toString() {
-        if (type == PropertyType.DATE) {
-            return ISO8601.format((Calendar) val);
-        } else {
-            return val.toString();
-        }
-    }
-
-
     //-------------------------------------------------------< implementation >
     private InternalValue(String value) {
         super(value, PropertyType.STRING);
@@ -542,7 +532,7 @@ public class InternalValue extends Abstr
     }
 
     private InternalValue(Calendar value) {
-        super(value, PropertyType.DATE);
+        super(value);
     }
 
     private InternalValue(boolean value) {
@@ -659,26 +649,6 @@ public class InternalValue extends Abstr
     }
 
     /**
-     * @see org.apache.jackrabbit.spi.QValue#getString()
-     */
-    public String getString() throws RepositoryException {
-        if (type == PropertyType.BINARY) {
-            InputStream stream = getStream();
-            try {
-                return IOUtils.toString(stream, "UTF-8");
-            } catch (IOException e) {
-                throw new RepositoryException("conversion from stream to string failed",
e);
-            } finally {
-                IOUtils.closeQuietly(stream);
-            }
-        } else if (type == PropertyType.DATE) {
-            return ISO8601.format(((Calendar) val));
-        } else {
-            return toString();
-        }
-    }
-
-    /**
      * @see org.apache.jackrabbit.spi.QValue#getStream()
      */
     public InputStream getStream() throws RepositoryException {

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/value/AbstractQValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/value/AbstractQValue.java?rev=938969&r1=938968&r2=938969&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/value/AbstractQValue.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/value/AbstractQValue.java
Wed Apr 28 12:33:30 2010
@@ -122,7 +122,8 @@ public abstract class AbstractQValue imp
      * is <code>null</code>.
      */
     protected AbstractQValue(Calendar value) {
-        this(value, PropertyType.DATE);
+        val = ISO8601.format(value);
+        type = PropertyType.DATE;
     }
 
     /**
@@ -204,7 +205,7 @@ public abstract class AbstractQValue imp
      */
     public Calendar getCalendar() throws RepositoryException {
         if (type == PropertyType.DATE) {
-            return (Calendar) ((Calendar) val).clone();
+            return ISO8601.parse(getString());
         } else if (type == PropertyType.DOUBLE) {
             Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT+00:00"));
             cal.setTimeInMillis(((Double) val).longValue());
@@ -272,7 +273,7 @@ public abstract class AbstractQValue imp
         } else if (type == PropertyType.LONG) {
             return ((Long) val).doubleValue();
         } else if (type == PropertyType.DATE) {
-            return ((Calendar) val).getTimeInMillis();
+            return getCalendar().getTimeInMillis();
         } else if (type == PropertyType.DECIMAL) {
             return ((BigDecimal) val).doubleValue();
         } else {
@@ -295,7 +296,7 @@ public abstract class AbstractQValue imp
         } else if (type == PropertyType.DECIMAL) {
             return ((BigDecimal) val).longValue();
         } else if (type == PropertyType.DATE) {
-            return ((Calendar) val).getTimeInMillis();
+            return getCalendar().getTimeInMillis();
         } else {
             try {
                 return Long.parseLong(getString());
@@ -346,7 +347,7 @@ public abstract class AbstractQValue imp
                 IOUtils.closeQuietly(stream);
             }
         } else if (type == PropertyType.DATE) {
-            return ISO8601.format(((Calendar) val));
+            return (String) val;
         } else {
             return val.toString();
         }
@@ -407,7 +408,7 @@ public abstract class AbstractQValue imp
     @Override
     public String toString() {
         if (type == PropertyType.DATE) {
-            return ISO8601.format((Calendar) val);
+            return (String) val;
         } else {
             return val.toString();
         }
@@ -430,11 +431,7 @@ public abstract class AbstractQValue imp
             if (type != other.type) {
                 return false;
             }
-            if (PropertyType.DATE == type) {
-                return ISO8601.format((Calendar) val).equals(ISO8601.format((Calendar) other.val));
-            } else {
-                return val.equals(other.val);
-            }
+            return val.equals(other.val);
         }
         return false;
     }
@@ -448,10 +445,6 @@ public abstract class AbstractQValue imp
      */
     @Override
     public int hashCode() {
-        if (PropertyType.DATE == type) {
-            return ISO8601.format((Calendar) val).hashCode();
-        } else {
-            return val.hashCode();
-        }
+        return val.hashCode();
     }
 }

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/value/AbstractQValueFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/value/AbstractQValueFactory.java?rev=938969&r1=938968&r2=938969&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/value/AbstractQValueFactory.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/value/AbstractQValueFactory.java
Wed Apr 28 12:33:30 2010
@@ -129,8 +129,7 @@ public abstract class AbstractQValueFact
         if (value == null) {
             throw new IllegalArgumentException("Cannot create QValue from null value.");
         }
-        // Calendar is not constant, must create a clone
-        return new DefaultQValue((Calendar) value.clone());
+        return new DefaultQValue(value);
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2davex/QValueFactoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2davex/QValueFactoryImpl.java?rev=938969&r1=938968&r2=938969&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2davex/QValueFactoryImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2davex/QValueFactoryImpl.java
Wed Apr 28 12:33:30 2010
@@ -64,6 +64,11 @@ class QValueFactoryImpl extends org.apac
         private static final long serialVersionUID = -5667366239976271493L;
     };
 
+    /**
+     * empty array
+     */
+    private static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
+
     private final ValueLoader loader;
     private final ValueFactory vf;
 
@@ -116,11 +121,6 @@ class QValueFactoryImpl extends org.apac
         private static final long serialVersionUID = 2736654000266713469L;
 
         /**
-         * empty array
-         */
-        private final byte[] EMPTY_BYTE_ARRAY = new byte[0];
-
-        /**
          * max size for keeping tmp data in memory
          */
         private static final int MAX_BUFFER_SIZE = 0x10000;



Mime
View raw message