jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1400935 - in /jackrabbit/trunk: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/ jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commo...
Date Mon, 22 Oct 2012 16:15:01 GMT
Author: jukka
Date: Mon Oct 22 16:15:00 2012
New Revision: 1400935

URL: http://svn.apache.org/viewvc?rev=1400935&view=rev
Log:
JCR-3447: InternalValueFactory should use the DataStore whenever available

Further simplify code by making the Internal/QValue fields immutable (final)
and replacing the store() method with a simpler isInDataStore() checker.
This is OK since all (large) binary InternalValues should now already
be in the data store.

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleWriter.java
    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

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleWriter.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleWriter.java?rev=1400935&r1=1400934&r2=1400935&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleWriter.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleWriter.java
Mon Oct 22 16:15:00 2012
@@ -30,7 +30,6 @@ import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
 
 import org.apache.commons.io.IOUtils;
-import org.apache.jackrabbit.core.data.DataStore;
 import org.apache.jackrabbit.core.id.NodeId;
 import org.apache.jackrabbit.core.value.InternalValue;
 import org.apache.jackrabbit.core.persistence.util.NodePropBundle.ChildNodeEntry;
@@ -208,27 +207,20 @@ class BundleWriter {
                 case PropertyType.BINARY:
                     try {
                         long size = val.getLength();
-                        DataStore dataStore = binding.dataStore;
-                        if (dataStore != null) {
-                            int maxMemorySize = dataStore.getMinRecordLength() - 1;
-                            if (size < maxMemorySize) {
-                                writeSmallBinary(val, state, i);
-                            } else {
-                                out.writeInt(BundleBinding.BINARY_IN_DATA_STORE);
-                                val.store(dataStore);
-                                writeString(val.toString());
-                            }
-                            break;
-                        }
-                        // special handling required for binary value:
-                        // spool binary value to file in blob store
-                        if (size < 0) {
+                        if (val.isInDataStore()) {
+                            out.writeInt(BundleBinding.BINARY_IN_DATA_STORE);
+                            writeString(val.toString());
+                        } else if (binding.dataStore != null) {
+                            writeSmallBinary(val, state, i);
+                        } else if (size < 0) {
                             log.warn("Blob has negative size. Potential loss of data. "
                                     + "id={} idx={}", state.getId(), String.valueOf(i));
                             out.writeInt(0);
                             values[i] = InternalValue.create(new byte[0]);
                             val.discard();
                         } else if (size > binding.getMinBlobSize()) {
+                            // special handling required for binary value:
+                            // spool binary value to file in blob store
                             out.writeInt(BundleBinding.BINARY_IN_BLOB_STORE);
                             String blobId = state.getBlobId(i);
                             if (blobId == null) {

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=1400935&r1=1400934&r2=1400935&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
Mon Oct 22 16:15:00 2012
@@ -25,7 +25,6 @@ import java.math.BigDecimal;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.Calendar;
-import java.util.TimeZone;
 
 import javax.jcr.Binary;
 import javax.jcr.PropertyType;
@@ -324,9 +323,7 @@ public class InternalValue extends Abstr
      * @return the created value
      */
     public static InternalValue createDate(String value) {
-        InternalValue iv = new InternalValue(Calendar.getInstance(TimeZone.getTimeZone("GMT+00:00")));
-        iv.val = value;
-        return iv;
+        return new InternalValue(value, PropertyType.DATE);
     }
 
     /**
@@ -643,23 +640,8 @@ public class InternalValue extends Abstr
         }
     }
 
-    /**
-     * Store a value in the data store. This will store temporary files or in-memory objects
-     * in the data store.
-     *
-     * @param dataStore the data store
-     * @throws RepositoryException
-     */
-    public void store(DataStore dataStore) throws RepositoryException {
-        assert dataStore != null;
-        assert type == PropertyType.BINARY;
-        BLOBFileValue v = (BLOBFileValue) val;
-        if (v instanceof BLOBInDataStore) {
-            // already in the data store, OK
-            return;
-        }
-        // store it in the data store
-        val = BLOBInDataStore.getInstance(dataStore, getStream());
+    public boolean isInDataStore() {
+        return val instanceof BLOBInDataStore;
     }
 
     //-------------------------------------------------------------< QValue >---

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=1400935&r1=1400934&r2=1400935&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
Mon Oct 22 16:15:00 2012
@@ -45,7 +45,7 @@ public abstract class AbstractQValue imp
 
     private static final long serialVersionUID = 6976433831974695272L;
 
-    protected Object val;
+    protected final Object val;
     protected final int type;
 
     /**
@@ -60,7 +60,7 @@ public abstract class AbstractQValue imp
         if (value == null) {
             throw new IllegalArgumentException("null value");
         }
-        val = value;
+        this.val = value;
         this.type = type;
     }
 
@@ -77,10 +77,13 @@ public abstract class AbstractQValue imp
         if (value == null) {
             throw new IllegalArgumentException("null value");
         }
-        if (!(type == PropertyType.STRING || type == PropertyType.REFERENCE || type == PropertyType.WEAKREFERENCE))
{
+        if (!(type == PropertyType.STRING
+                || type == PropertyType.DATE // JCR-3083
+                || type == PropertyType.REFERENCE
+                || type == PropertyType.WEAKREFERENCE)) {
             throw new IllegalArgumentException();
         }
-        val = value;
+        this.val = value;
         this.type = type;
     }
 



Mime
View raw message