jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r784058 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core: data/ nodetype/ persistence/bundle/util/ persistence/db/ persistence/mem/ persistence/obj/ persistence/util/ persistence/xml/ query/lucene/ value/
Date Fri, 12 Jun 2009 10:20:06 GMT
Author: thomasm
Date: Fri Jun 12 10:20:06 2009
New Revision: 784058

URL: http://svn.apache.org/viewvc?rev=784058&view=rev
Log:
JCR-2144 InternalValue refactoring

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/GarbageCollector.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/ValueConstraint.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/BundleBinding.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/db/DatabasePersistenceManager.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/mem/InMemPersistenceManager.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/obj/ObjectPersistenceManager.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/Serializer.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/xml/XMLPersistenceManager.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NodeIndexer.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBFileValue.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInDataStore.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInMemory.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInResource.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInTempFile.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBValue.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BinaryValueImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/GarbageCollector.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/GarbageCollector.java?rev=784058&r1=784057&r2=784058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/GarbageCollector.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/GarbageCollector.java
Fri Jun 12 10:20:06 2009
@@ -86,7 +86,7 @@
 
     private final Session[] sessionList;
     private final SessionListener sessionListener;
-    
+
     private final AtomicBoolean closed = new AtomicBoolean();
 
     private boolean persistenceManagerScan;
@@ -108,7 +108,7 @@
         this.pmList = list;
         this.persistenceManagerScan = list != null;
         this.sessionList = sessionList;
-        
+
         // Auto-close if the main session logs out
         this.sessionListener = new SessionListener() {
             public void loggedOut(SessionImpl session) {
@@ -231,6 +231,8 @@
                         PropertyState ps = pm.load(pid);
                         if (ps.getType() == PropertyType.BINARY) {
                             for (InternalValue v : ps.getValues()) {
+                                // getLength will update the last modified date
+                                // if the persistence manager scan is running
                                 v.getLength();
                             }
                         }
@@ -264,7 +266,7 @@
 
     /**
      * Delete all unused items in the data store.
-     * 
+     *
      * @return the number of deleted items
      */
     public int deleteUnused() throws RepositoryException {
@@ -287,7 +289,7 @@
 
     /**
      * Get the data store if one is used.
-     * 
+     *
      * @return the data store, or null
      */
     public DataStore getDataStore() {
@@ -358,13 +360,13 @@
          *
          * We can't use node path for this, UUIDs are required as nodes could be
          * moved around.
-         * 
-         * This mechanism requires that all data stores update the last modified 
+         *
+         * This mechanism requires that all data stores update the last modified
          * date when calling addRecord and that record already exists.
          *
          */
     }
-    
+
     /**
      * Cleanup resources used internally by this instance.
      */

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/ValueConstraint.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/ValueConstraint.java?rev=784058&r1=784057&r2=784058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/ValueConstraint.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/ValueConstraint.java
Fri Jun 12 10:20:06 2009
@@ -16,7 +16,6 @@
  */
 package org.apache.jackrabbit.core.nodetype;
 
-import org.apache.jackrabbit.core.value.BLOBFileValue;
 import org.apache.jackrabbit.core.value.InternalValue;
 import org.apache.jackrabbit.spi.commons.conversion.MalformedPathException;
 import org.apache.jackrabbit.spi.commons.conversion.NameException;
@@ -353,8 +352,7 @@
                 return;
 
             case PropertyType.BINARY:
-                BLOBFileValue blob = value.getBLOBFileValue();
-                long length = blob.getLength();
+                long length = value.getLength();
                 if (length != -1) {
                     check(length);
                 } else {

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/BundleBinding.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/BundleBinding.java?rev=784058&r1=784057&r2=784058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/BundleBinding.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/BundleBinding.java
Fri Jun 12 10:20:06 2009
@@ -25,7 +25,6 @@
 import org.apache.jackrabbit.core.PropertyId;
 import org.apache.jackrabbit.core.util.StringIndex;
 import org.apache.jackrabbit.core.value.InternalValue;
-import org.apache.jackrabbit.core.value.BLOBFileValue;
 import org.apache.jackrabbit.core.data.DataStore;
 import org.apache.jackrabbit.core.nodetype.NodeDefId;
 import org.apache.jackrabbit.core.nodetype.PropDefId;
@@ -608,76 +607,76 @@
             InternalValue val = values[i];
             switch (state.getType()) {
                 case PropertyType.BINARY:
-                    BLOBFileValue blobVal = val.getBLOBFileValue();
-                    if (InternalValue.USE_DATA_STORE && dataStore != null) {
-                        if (blobVal.isSmall()) {
-                            writeSmallBinary(out, blobVal, state, i);
-                        } else {
-                            out.writeInt(BINARY_IN_DATA_STORE);
-                            try {
+                    try {
+                        long size = val.getLength();
+                        if (InternalValue.USE_DATA_STORE && dataStore != null) {
+                            int maxMemorySize = dataStore.getMinRecordLength() - 1;
+                            if (size < maxMemorySize) {
+                                writeSmallBinary(out, val, state, i);
+                            } else {
+                                out.writeInt(BINARY_IN_DATA_STORE);
                                 val.store(dataStore);
-                            } catch (RepositoryException e) {
-                                String msg = "Error while storing blob. id="
-                                    + state.getId() + " idx=" + i + " size=" + val.getBLOBFileValue().getLength();
-                                log.error(msg, e);
-                                throw new IOException(msg);
+                                out.writeUTF(val.toString());
                             }
-                            out.writeUTF(val.toString());
+                            break;
                         }
-                        break;
-                    }
-                    // special handling required for binary value:
-                    // spool binary value to file in blob store
-                    long size = blobVal.getLength();
-                    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]);
-                        blobVal.discard();
-                    } else if (size > minBlobSize) {
-                        out.writeInt(BINARY_IN_BLOB_STORE);
-                        String blobId = state.getBlobId(i);
-                        if (blobId == null) {
-                            try {
-                                InputStream in = blobVal.getStream();
+                        // special handling required for binary value:
+                        // spool binary value to file in blob store
+                        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 > minBlobSize) {
+                            out.writeInt(BINARY_IN_BLOB_STORE);
+                            String blobId = state.getBlobId(i);
+                            if (blobId == null) {
                                 try {
-                                    blobId = blobStore.createId(state.getId(), i);
-                                    blobStore.put(blobId, in, size);
-                                    state.setBlobId(blobId, i);
-                                } finally {
-                                    IOUtils.closeQuietly(in);
+                                    InputStream in = val.getStream();
+                                    try {
+                                        blobId = blobStore.createId(state.getId(), i);
+                                        blobStore.put(blobId, in, size);
+                                        state.setBlobId(blobId, i);
+                                    } finally {
+                                        IOUtils.closeQuietly(in);
+                                    }
+                                } catch (Exception e) {
+                                    String msg = "Error while storing blob. id="
+                                            + state.getId() + " idx=" + i + " size=" + size;
+                                    log.error(msg, e);
+                                    throw new IOException(msg);
                                 }
-                            } catch (Exception e) {
-                                String msg = "Error while storing blob. id="
-                                        + state.getId() + " idx=" + i + " size=" + size;
-                                log.error(msg, e);
-                                throw new IOException(msg);
-                            }
-                            try {
-                                // replace value instance with value
-                                // backed by resource in blob store and delete temp file
-                                if (blobStore instanceof ResourceBasedBLOBStore) {
-                                    values[i] = InternalValue.create(((ResourceBasedBLOBStore)
blobStore).getResource(blobId));
-                                } else {
-                                    values[i] = InternalValue.create(blobStore.get(blobId));
+                                try {
+                                    // replace value instance with value
+                                    // backed by resource in blob store and delete temp file
+                                    if (blobStore instanceof ResourceBasedBLOBStore) {
+                                        values[i] = InternalValue.create(((ResourceBasedBLOBStore)
blobStore).getResource(blobId));
+                                    } else {
+                                        values[i] = InternalValue.create(blobStore.get(blobId));
+                                    }
+                                } catch (Exception e) {
+                                    log.error("Error while reloading blob. truncating. id="
+                                            + state.getId() + " idx=" + i + " size=" + size,
e);
+                                    values[i] = InternalValue.create(new byte[0]);
                                 }
-                            } catch (Exception e) {
-                                log.error("Error while reloading blob. truncating. id="
-                                        + state.getId() + " idx=" + i + " size=" + size,
e);
-                                values[i] = InternalValue.create(new byte[0]);
+                                val.discard();
                             }
-                            blobVal.discard();
+                            // store id of blob as property value
+                            out.writeUTF(blobId);   // value
+                        } else {
+                            // delete evt. blob
+                            byte[] data = writeSmallBinary(out, val, state, i);
+                            // replace value instance with value
+                            // backed by resource in blob store and delete temp file
+                            values[i] = InternalValue.create(data);
+                            val.discard();
                         }
-                        // store id of blob as property value
-                        out.writeUTF(blobId);   // value
-                    } else {
-                        // delete evt. blob
-                        byte[] data = writeSmallBinary(out, blobVal, state, i);
-                        // replace value instance with value
-                        // backed by resource in blob store and delete temp file
-                        values[i] = InternalValue.create(data);
-                        blobVal.discard();
+                    } catch (RepositoryException e) {
+                        String msg = "Error while storing blob. id="
+                            + state.getId() + " idx=" + i + " value=" + val;
+                        log.error(msg, e);
+                        throw new IOException(msg);
                     }
                     break;
                 case PropertyType.DOUBLE:
@@ -744,25 +743,25 @@
      * @return the data
      * @throws IOException if the data could not be read
      */
-    private byte[] writeSmallBinary(DataOutputStream out, BLOBFileValue blobVal, NodePropBundle.PropertyEntry
state, int i) throws IOException {
-        int size = (int) blobVal.getLength();
-        out.writeInt(size);
-        byte[] data = new byte[size];
+    private byte[] writeSmallBinary(DataOutputStream out, InternalValue value, NodePropBundle.PropertyEntry
state, int i) throws IOException {
         try {
+            int size = (int) value.getLength();
+            out.writeInt(size);
+            byte[] data = new byte[size];
             DataInputStream in =
-                new DataInputStream(blobVal.getStream());
+                new DataInputStream(value.getStream());
             try {
                 in.readFully(data);
             } finally {
                 IOUtils.closeQuietly(in);
             }
+            out.write(data, 0, data.length);
+            return data;
         } catch (Exception e) {
             String msg = "Error while storing blob. id="
-                    + state.getId() + " idx=" + i + " size=" + size;
+                    + state.getId() + " idx=" + i + " value=" + value;
             log.error(msg, e);
             throw new IOException(msg);
         }
-        out.write(data, 0, data.length);
-        return data;
     }
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/db/DatabasePersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/db/DatabasePersistenceManager.java?rev=784058&r1=784057&r2=784058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/db/DatabasePersistenceManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/db/DatabasePersistenceManager.java
Fri Jun 12 10:20:06 2009
@@ -34,7 +34,6 @@
 import org.apache.jackrabbit.core.state.NodeReferencesId;
 import org.apache.jackrabbit.core.state.NodeState;
 import org.apache.jackrabbit.core.state.PropertyState;
-import org.apache.jackrabbit.core.value.BLOBFileValue;
 import org.apache.jackrabbit.core.value.InternalValue;
 import org.apache.jackrabbit.util.Text;
 import org.slf4j.Logger;
@@ -534,9 +533,7 @@
                 InternalValue val = values[i];
                 if (val != null) {
                     if (val.getType() == PropertyType.BINARY) {
-                        BLOBFileValue blobVal = val.getBLOBFileValue();
-                        // delete internal resource representation of BLOB value
-                        blobVal.delete(true);
+                        val.deleteBinaryResource();
                         // also remove from BLOBStore
                         String blobId = blobStore.createId(state.getPropertyId(), i);
                         try {

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/mem/InMemPersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/mem/InMemPersistenceManager.java?rev=784058&r1=784057&r2=784058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/mem/InMemPersistenceManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/mem/InMemPersistenceManager.java
Fri Jun 12 10:20:06 2009
@@ -34,7 +34,6 @@
 import org.apache.jackrabbit.core.state.PropertyState;
 import org.apache.jackrabbit.core.persistence.util.FileSystemBLOBStore;
 import org.apache.jackrabbit.core.persistence.util.Serializer;
-import org.apache.jackrabbit.core.value.BLOBFileValue;
 import org.apache.jackrabbit.core.value.InternalValue;
 import org.apache.jackrabbit.spi.Name;
 import org.slf4j.Logger;
@@ -482,11 +481,7 @@
         if (values != null) {
             for (InternalValue val : values) {
                 if (val != null) {
-                    if (val.getType() == PropertyType.BINARY) {
-                        BLOBFileValue blobVal = val.getBLOBFileValue();
-                        // delete blob file and prune empty parent folders
-                        blobVal.delete(true);
-                    }
+                    val.deleteBinaryResource();
                 }
             }
         }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/obj/ObjectPersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/obj/ObjectPersistenceManager.java?rev=784058&r1=784057&r2=784058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/obj/ObjectPersistenceManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/obj/ObjectPersistenceManager.java
Fri Jun 12 10:20:06 2009
@@ -34,7 +34,6 @@
 import org.apache.jackrabbit.core.state.NodeReferencesId;
 import org.apache.jackrabbit.core.state.NodeState;
 import org.apache.jackrabbit.core.state.PropertyState;
-import org.apache.jackrabbit.core.value.BLOBFileValue;
 import org.apache.jackrabbit.core.value.InternalValue;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -410,11 +409,7 @@
             for (int i = 0; i < values.length; i++) {
                 InternalValue val = values[i];
                 if (val != null) {
-                    if (val.getType() == PropertyType.BINARY) {
-                        BLOBFileValue blobVal = val.getBLOBFileValue();
-                        // delete blob file and prune empty parent folders
-                        blobVal.delete(true);
-                    }
+                    val.deleteBinaryResource();
                 }
             }
         }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/Serializer.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/Serializer.java?rev=784058&r1=784057&r2=784058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/Serializer.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/Serializer.java
Fri Jun 12 10:20:06 2009
@@ -26,7 +26,6 @@
 import org.apache.jackrabbit.core.state.NodeState;
 import org.apache.jackrabbit.core.state.PropertyState;
 import org.apache.jackrabbit.core.state.ChildNodeEntry;
-import org.apache.jackrabbit.core.value.BLOBFileValue;
 import org.apache.jackrabbit.core.value.InternalValue;
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.uuid.UUID;
@@ -97,14 +96,14 @@
         c = state.getPropertyNames();
         out.writeInt(c.size()); // count
         for (Iterator<Name> iter = c.iterator(); iter.hasNext();) {
-            Name propName = (Name) iter.next();
+            Name propName = iter.next();
             out.writeUTF(propName.toString());   // name
         }
         // child nodes (list of name/uuid pairs)
         Collection<ChildNodeEntry> collChildren = state.getChildNodeEntries();
         out.writeInt(collChildren.size()); // count
         for (Iterator<ChildNodeEntry> iter = collChildren.iterator(); iter.hasNext();)
{
-            ChildNodeEntry entry = (ChildNodeEntry) iter.next();
+            ChildNodeEntry entry = iter.next();
             out.writeUTF(entry.getName().toString());   // name
             out.write(entry.getId().getUUID().getRawBytes());    // uuid
         }
@@ -196,11 +195,10 @@
             if (state.getType() == PropertyType.BINARY) {
                 // special handling required for binary value:
                 // put binary value in BLOB store
-                BLOBFileValue blobVal = val.getBLOBFileValue();
-                InputStream in = blobVal.getStream();
+                InputStream in = val.getStream();
                 String blobId = blobStore.createId(state.getPropertyId(), i);
                 try {
-                    blobStore.put(blobId, in, blobVal.getLength());
+                    blobStore.put(blobId, in, val.getLength());
                 } finally {
                     IOUtils.closeQuietly(in);
                 }
@@ -223,7 +221,7 @@
                         IOUtils.closeQuietly(in);
                     }
                 }
-                blobVal.discard();
+                val.discard();
             } else {
                 /**
                  * because writeUTF(String) has a size limit of 65k,

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/xml/XMLPersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/xml/XMLPersistenceManager.java?rev=784058&r1=784057&r2=784058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/xml/XMLPersistenceManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/xml/XMLPersistenceManager.java
Fri Jun 12 10:20:06 2009
@@ -39,7 +39,6 @@
 import org.apache.jackrabbit.core.persistence.util.FileSystemBLOBStore;
 import org.apache.jackrabbit.core.persistence.util.ResourceBasedBLOBStore;
 import org.apache.jackrabbit.core.util.DOMWalker;
-import org.apache.jackrabbit.core.value.BLOBFileValue;
 import org.apache.jackrabbit.core.value.InternalValue;
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.NameFactory;
@@ -672,11 +671,10 @@
                             if (type == PropertyType.BINARY) {
                                 // special handling required for binary value:
                                 // put binary value in BLOB store
-                                BLOBFileValue blobVal = val.getBLOBFileValue();
-                                InputStream in = blobVal.getStream();
+                                InputStream in = val.getStream();
                                 String blobId = blobStore.createId(state.getPropertyId(),
i);
                                 try {
-                                    blobStore.put(blobId, in, blobVal.getLength());
+                                    blobStore.put(blobId, in, val.getLength());
                                 } finally {
                                     IOUtils.closeQuietly(in);
                                 }
@@ -703,7 +701,7 @@
                                         }
                                     }
                                 }
-                                blobVal.discard();
+                                val.discard();
                             } else {
                                 writer.write(Text.encodeIllegalXMLCharacters(val.toString()));
                             }
@@ -760,11 +758,7 @@
             for (int i = 0; i < values.length; i++) {
                 InternalValue val = values[i];
                 if (val != null) {
-                    if (val.getType() == PropertyType.BINARY) {
-                        BLOBFileValue blobVal = val.getBLOBFileValue();
-                        // delete blob file and prune empty parent folders
-                        blobVal.delete(true);
-                    }
+                    val.deleteBinaryResource();
                 }
             }
         }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NodeIndexer.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NodeIndexer.java?rev=784058&r1=784057&r2=784058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NodeIndexer.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NodeIndexer.java
Fri Jun 12 10:20:06 2009
@@ -24,7 +24,6 @@
 import org.apache.jackrabbit.core.state.NodeState;
 import org.apache.jackrabbit.core.state.PropertyState;
 import org.apache.jackrabbit.core.state.ChildNodeEntry;
-import org.apache.jackrabbit.core.value.BLOBFileValue;
 import org.apache.jackrabbit.core.value.InternalValue;
 import org.apache.jackrabbit.extractor.TextExtractor;
 import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
@@ -298,7 +297,7 @@
         switch (value.getType()) {
             case PropertyType.BINARY:
                 if (isIndexed(name)) {
-                    addBinaryValue(doc, fieldName, value.getBLOBFileValue());
+                    addBinaryValue(doc, fieldName, value);
                 }
                 break;
             case PropertyType.BOOLEAN:
@@ -409,7 +408,7 @@
      */
     protected void addBinaryValue(Document doc,
                                   String fieldName,
-                                  Object internalValue) {
+                                  InternalValue internalValue) {
         // 'check' if node is of type nt:resource
         try {
             String jcrData = mappings.getPrefix(Name.NS_JCR_URI) + ":data";
@@ -429,8 +428,7 @@
                     encoding = encodingValue.getString();
                 }
 
-                InputStream stream =
-                        ((BLOBFileValue) internalValue).getStream();
+                InputStream stream = internalValue.getStream();
                 Reader reader = extractor.extractText(stream, type, encoding);
                 doc.add(createFulltextField(reader));
             }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBFileValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBFileValue.java?rev=784058&r1=784057&r2=784058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBFileValue.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBFileValue.java
Fri Jun 12 10:20:06 2009
@@ -36,7 +36,7 @@
  * This interface is for Jackrabbit-internal use only. Applications should
  * use <code>javax.jcr.ValueFactory</code> to create binary values.
  */
-public abstract class BLOBFileValue implements Binary {
+abstract class BLOBFileValue implements Binary {
 
     /**
      * Returns a String representation of this value.
@@ -72,22 +72,13 @@
     }
 
     /**
-     * Returns the length of this <code>BLOBFileValue</code>.
-     *
-     * @return The length, in bytes, of this <code>BLOBFileValue</code>,
-     *         or -1L if the length can't be determined.
-     * @throws IOException
-     */
-    public abstract long getLength();
-
-    /**
      * Frees temporarily allocated resources such as temporary file, buffer, etc.
      * If this <code>BLOBFileValue</code> is backed by a persistent resource
      * calling this method will have no effect.
      *
      * @see #delete(boolean)
      */
-    public abstract void discard();
+    abstract void discard();
 
     /**
      * Deletes the persistent resource backing this <code>BLOBFileValue</code>.
@@ -95,7 +86,7 @@
      * @param pruneEmptyParentDirs if <code>true</code>, empty parent directories
      *                             will automatically be deleted
      */
-    public abstract void delete(boolean pruneEmptyParentDirs);
+    abstract void delete(boolean pruneEmptyParentDirs);
 
     /**
      * Checks if this object is immutable.
@@ -105,30 +96,13 @@
      */
     abstract boolean isImmutable();
 
-    /**
-     * {@inheritDoc}
-     */
     public abstract boolean equals(Object obj);
 
-    /**
-     * {@inheritDoc}
-     */
     public abstract String toString();
 
-    /**
-     * {@inheritDoc}
-     */
     public abstract int hashCode();
 
     /**
-     * Check if the value is small (contains a low number of bytes) and should
-     * be stored inline.
-     *
-     * @return true if the value is small
-     */
-    public abstract boolean isSmall();
-
-    /**
      * Get the data identifier if one is available.
      *
      * @return the data identifier or null
@@ -138,14 +112,10 @@
     }
 
     //-----------------------------------------------------< javax.jcr.Binary >
-    /**
-     * {@inheritDoc}
-     */
+    public abstract long getSize();
+
     public abstract InputStream getStream() throws RepositoryException;
 
-    /**
-     * {@inheritDoc}
-     */
     public int read(byte[] b, long position) throws IOException, RepositoryException {
         InputStream in = getStream();
         try {
@@ -156,10 +126,6 @@
         }
     }
 
-    public long getSize() throws RepositoryException {
-        return getLength();
-    }
-
     public void dispose() {
         discard();
     }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInDataStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInDataStore.java?rev=784058&r1=784057&r2=784058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInDataStore.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInDataStore.java
Fri Jun 12 10:20:06 2009
@@ -53,15 +53,15 @@
         this.identifier = identifier;
     }
 
-    public void delete(boolean pruneEmptyParentDirs) {
+    void delete(boolean pruneEmptyParentDirs) {
         // do nothing
     }
 
-    public void discard() {
+    void discard() {
         // do nothing
     }
 
-    public DataIdentifier getDataIdentifier() {
+    DataIdentifier getDataIdentifier() {
         return identifier;
     }
 
@@ -88,11 +88,11 @@
         return 0;
     }
 
-    public long getLength() {
+    public long getSize() {
         try {
             return getDataRecord().getLength();
         } catch (DataStoreException e) {
-            log.warn("getLength for " + identifier + " failed", e);
+            log.warn("getSize for " + identifier + " failed", e);
             return -1;
         }
     }
@@ -135,8 +135,4 @@
         return store.getRecord(identifier);
     }
 
-    public boolean isSmall() {
-        return false;
-    }
-
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInMemory.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInMemory.java?rev=784058&r1=784057&r2=784058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInMemory.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInMemory.java
Fri Jun 12 10:20:06 2009
@@ -117,19 +117,13 @@
         return BLOBInMemory.getInstance(data);
     }
 
-    /**
-     * {@inheritDoc}
-     */
-    public void delete(boolean pruneEmptyParentDirs) {
+    void delete(boolean pruneEmptyParentDirs) {
         // do nothing
         // this object could still be referenced
         // the data will be garbage collected
     }
 
-    /**
-     * {@inheritDoc}
-     */
-    public void discard() {
+    void discard() {
         // do nothing
         // this object could still be referenced
         // the data will be garbage collected
@@ -139,24 +133,15 @@
         return true;
     }
 
-    /**
-     * {@inheritDoc}
-     */
-    public long getLength() {
+    public long getSize() {
         return data.length;
     }
 
-    /**
-     * {@inheritDoc}
-     */
     public InputStream getStream() {
         return new ByteArrayInputStream(data);
     }
 
-    /**
-     * {@inheritDoc}
-     */
-    public String getString() throws RepositoryException {
+    String getString() throws RepositoryException {
         try {
             return new String(data, "UTF-8");
         } catch (UnsupportedEncodingException e) {
@@ -164,9 +149,6 @@
         }
     }
 
-    /**
-     * {@inheritDoc}
-     */
     public String toString() {
         StringBuilder buff = new StringBuilder(PREFIX.length() + 2 * data.length);
         buff.append(PREFIX);
@@ -179,9 +161,6 @@
         return buff.toString();
     }
 
-    /**
-     * {@inheritDoc}
-     */
     public boolean equals(Object obj) {
         if (this == obj) {
             return true;
@@ -204,8 +183,4 @@
         return 0;
     }
 
-    public boolean isSmall() {
-        return true;
-    }
-
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInResource.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInResource.java?rev=784058&r1=784057&r2=784058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInResource.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInResource.java
Fri Jun 12 10:20:06 2009
@@ -82,10 +82,7 @@
         return new BLOBInResource(fsResource);
     }
 
-    /**
-     * {@inheritDoc}
-     */
-    public void delete(boolean pruneEmptyParentDirs) {
+    void delete(boolean pruneEmptyParentDirs) {
         try {
             fsResource.delete(pruneEmptyParentDirs);
         } catch (FileSystemException fse) {
@@ -95,10 +92,7 @@
 
     }
 
-    /**
-     * {@inheritDoc}
-     */
-    public void discard() {
+    void discard() {
         // this instance is not backed by temporarily allocated resource/buffer
     }
 
@@ -107,16 +101,10 @@
         return false;
     }
 
-    /**
-     * {@inheritDoc}
-     */
-    public long getLength() {
+    public long getSize() {
         return length;
     }
 
-    /**
-     * {@inheritDoc}
-     */
     public InputStream getStream() throws RepositoryException {
         try {
             return fsResource.getInputStream();
@@ -126,16 +114,10 @@
         }
     }
 
-    /**
-     * {@inheritDoc}
-     */
     public String toString() {
         return PREFIX +  fsResource.toString();
     }
 
-    /**
-     * {@inheritDoc}
-     */
     public boolean equals(Object obj) {
         if (this == obj) {
             return true;
@@ -158,11 +140,4 @@
         return 0;
     }
 
-    /**
-     * {@inheritDoc}
-     */
-    public boolean isSmall() {
-        return false;
-    }
-
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInTempFile.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInTempFile.java?rev=784058&r1=784057&r2=784058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInTempFile.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInTempFile.java
Fri Jun 12 10:20:06 2009
@@ -105,19 +105,13 @@
         return new BLOBInTempFile(file, temp);
     }
 
-    /**
-     * {@inheritDoc}
-     */
-    public void delete(boolean pruneEmptyParentDirs) {
+    void delete(boolean pruneEmptyParentDirs) {
         file.delete();
         length = -1;
         file = null;
     }
 
-    /**
-     * {@inheritDoc}
-     */
-    public void discard() {
+    void discard() {
         if (temp) {
             delete(true);
         }
@@ -128,16 +122,10 @@
         return false;
     }
 
-    /**
-     * {@inheritDoc}
-     */
-    public long getLength() {
+    public long getSize() {
         return length;
     }
 
-    /**
-     * {@inheritDoc}
-     */
     public InputStream getStream() throws IllegalStateException, RepositoryException {
         try {
             return new LazyFileInputStream(file);
@@ -146,16 +134,10 @@
         }
     }
 
-    /**
-     * {@inheritDoc}
-     */
     public String toString() {
         return PREFIX + file.toString();
     }
 
-    /**
-     * {@inheritDoc}
-     */
     public boolean equals(Object obj) {
         if (this == obj) {
             return true;
@@ -178,16 +160,6 @@
         return 0;
     }
 
-    /**
-     * {@inheritDoc}
-     */
-    public boolean isSmall() {
-        return false;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
     public int read(byte[] b, long position) throws IOException, RepositoryException {
         RandomAccessFile raf = new RandomAccessFile(file, "r");
         try {

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBValue.java?rev=784058&r1=784057&r2=784058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBValue.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBValue.java
Fri Jun 12 10:20:06 2009
@@ -205,13 +205,7 @@
         temp = false;
     }
 
-    /**
-     * Returns the length of this <code>BLOBFileValue</code>.
-     *
-     * @return The length, in bytes, of this <code>BLOBFileValue</code>,
-     *         or -1L if the length can't be determined.
-     */
-    public long getLength() {
+    public long getSize() {
         if (file != null) {
             // this instance is backed by a 'real' file
             if (file.exists()) {
@@ -239,7 +233,7 @@
      *
      * @see #delete(boolean)
      */
-    public void discard() {
+    void discard() {
         if (!temp) {
             // do nothing if this instance is not backed by temporarily
             // allocated resource/buffer
@@ -260,7 +254,7 @@
      * @param pruneEmptyParentDirs if <code>true</code>, empty parent directories
      *                             will automatically be deleted
      */
-    public void delete(boolean pruneEmptyParentDirs) {
+    void delete(boolean pruneEmptyParentDirs) {
         if (file != null) {
             // this instance is backed by a 'real' file
             file.delete();
@@ -313,9 +307,6 @@
         }
     }
 
-    /**
-     * {@inheritDoc}
-     */
     public boolean equals(Object obj) {
         if (this == obj) {
             return true;
@@ -340,16 +331,6 @@
         return 0;
     }
 
-    /**
-     * {@inheritDoc}
-     */
-    public boolean isSmall() {
-        return false;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
     public InputStream getStream() throws RepositoryException {
         // always return a 'fresh' stream
         if (file != null) {
@@ -373,9 +354,6 @@
         }
     }
 
-    /**
-     * {@inheritDoc}
-     */
     public int read(byte[] b, long position) throws IOException, RepositoryException {
         if (file != null) {
             // this instance is backed by a temp file

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BinaryValueImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BinaryValueImpl.java?rev=784058&r1=784057&r2=784058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BinaryValueImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BinaryValueImpl.java
Fri Jun 12 10:20:06 2009
@@ -38,9 +38,6 @@
         this.blob = blob;
     }
 
-    /**
-     * {@inheritDoc}
-     */
     public String getContentIdentity() {
         DataIdentifier id = blob.getDataIdentifier();
         return id == null ? null : id.toString();

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=784058&r1=784057&r2=784058&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
Fri Jun 12 10:20:06 2009
@@ -121,15 +121,6 @@
                 InternalValue result;
                 if (USE_DATA_STORE) {
                     BLOBFileValue blob = null;
-                    if (value instanceof QValueValue) {
-                        QValueValue qvv = (QValueValue) value;
-                        QValue qv = qvv.getQValue();
-                        if (qv instanceof InternalValue) {
-                            InternalValue iv = (InternalValue) qv;
-
-                            iv.getBLOBFileValue();
-                        }
-                    }
                     if (value instanceof BinaryValueImpl) {
                         BinaryValueImpl bin = (BinaryValueImpl) value;
                         DataIdentifier identifier = bin.getDataIdentifier();
@@ -271,7 +262,7 @@
      * @param value
      * @return the created value
      */
-    public static InternalValue create(URI value) {
+    static InternalValue create(URI value) {
         return new InternalValue(value);
     }
 
@@ -399,18 +390,6 @@
     }
 
     /**
-     * @param values
-     * @return the created value
-     */
-    public static InternalValue[] create(String[] values) {
-        InternalValue[] ret = new InternalValue[values.length];
-        for (int i = 0; i < values.length; i++) {
-            ret[i] = new InternalValue(values[i]);
-        }
-        return ret;
-    }
-
-    /**
      * @param value
      * @return the created value
      */
@@ -437,7 +416,7 @@
 
     //----------------------------------------------------< conversions, etc. >
 
-    public BLOBFileValue getBLOBFileValue() {
+    BLOBFileValue getBLOBFileValue() {
         assert val != null && type == PropertyType.BINARY;
         return (BLOBFileValue) val;
     }
@@ -655,7 +634,7 @@
      * @param dataStore the data store
      * @throws RepositoryException
      */
-    public void store(DataStore dataStore) throws RepositoryException, IOException {
+    public void store(DataStore dataStore) throws RepositoryException {
         assert USE_DATA_STORE;
         assert dataStore != null;
         assert type == PropertyType.BINARY;
@@ -663,14 +642,9 @@
         if (v instanceof BLOBInDataStore) {
             // already in the data store, OK
             return;
-        } else if (v instanceof BLOBInMemory) {
-            if (v.getLength() < dataStore.getMinRecordLength()) {
-                // in memory and does not make sense to store, OK
-                return;
-            }
         }
-        // store the temp file to the data store, or (theoretically) load it in memory
-        val = getBLOBFileValue(dataStore, v.getStream(), false);
+        // store it in the data store
+        val = BLOBInDataStore.getInstance(dataStore, getStream());
     }
 
     //-------------------------------------------------------------< QValue >---
@@ -679,7 +653,7 @@
      */
     public long getLength() throws RepositoryException {
         if (PropertyType.BINARY == type) {
-            return ((BLOBFileValue) val).getLength();
+            return ((BLOBFileValue) val).getSize();
         } else {
             return super.getLength();
         }
@@ -741,4 +715,16 @@
             super.discard();
         }
     }
+
+    /**
+     * Delete persistent binary objects. This method does not delete objects in
+     * the data store.
+     */
+    public void deleteBinaryResource() {
+        if (type == PropertyType.BINARY) {
+            BLOBFileValue bfv = (BLOBFileValue) val;
+            bfv.delete(true);
+        }
+    }
+
 }



Mime
View raw message