jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r408647 - in /jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core: ./ state/ state/util/ state/xml/ value/
Date Mon, 22 May 2006 12:32:39 GMT
Author: stefan
Date: Mon May 22 05:32:39 2006
New Revision: 408647

URL: http://svn.apache.org/viewvc?rev=408647&view=rev
Log:
JCR-428 BLOBFileValues might be discarded to early

Modified:
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/PropertyImpl.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/ItemState.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/PropertyState.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/util/Serializer.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/xml/XMLPersistenceManager.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/value/BLOBFileValue.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/PropertyImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/PropertyImpl.java?rev=408647&r1=408646&r2=408647&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/PropertyImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/PropertyImpl.java
Mon May 22 05:32:39 2006
@@ -293,7 +293,8 @@
             for (int i = 0; i < oldValues.length; i++) {
                 InternalValue old = oldValues[i];
                 if (old != null && old.getType() == PropertyType.BINARY) {
-                    // discard eventual temporary data before overriding
+                    // make sure temporarily allocated data is discarded
+                    // before overwriting it
                     ((BLOBFileValue) old.internalValue()).discard();
                 }
             }

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/ItemState.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/ItemState.java?rev=408647&r1=408646&r2=408647&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/ItemState.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/ItemState.java
Mon May 22 05:32:39 2006
@@ -150,7 +150,7 @@
     /**
      * Pull state information from overlayed state.
      */
-    protected void pull() {
+    void pull() {
         if (overlayedState != null) {
             copy(overlayedState);
             // sync modification count

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/PropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/PropertyState.java?rev=408647&r1=408646&r2=408647&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/PropertyState.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/PropertyState.java
Mon May 22 05:32:39 2006
@@ -108,30 +108,6 @@
         }
     }
 
-    /**
-     * {@inheritDoc}
-     */
-    protected void pull() {
-        super.pull();
-        if (overlayedState != null && type == PropertyType.BINARY) {
-            // special treatment for blobfile values. un-temp them
-            for (int i=0; i<values.length; i++) {
-                if (values[i].internalValue() instanceof BLOBFileValue) {
-                    BLOBFileValue old = (BLOBFileValue) values[i].internalValue();
-                    BLOBFileValue val = old.copy();
-                    if (old != val) {
-                        // only override if 'copy' returned a new instance
-                        try {
-                            values[i] = InternalValue.create(val, null);
-                        } catch (RepositoryException e) {
-                            // ignore
-                        }
-                    }
-                }
-           }
-        }
-    }
-
     //-------------------------------------------------------< public methods >
     /**
      * Determines if this item state represents a node.
@@ -348,7 +324,7 @@
                         public void close() {
                             // nop
                         }
-                    });
+                    }, false);
                 } else {
                     values[i] = InternalValue.valueOf(in.readUTF(), type);
                 }

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/util/Serializer.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/util/Serializer.java?rev=408647&r1=408646&r2=408647&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/util/Serializer.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/util/Serializer.java
Mon May 22 05:32:39 2006
@@ -218,7 +218,7 @@
                 } else {
                     in = blobStore.get(blobId);
                     try {
-                        values[i] = InternalValue.create(in);
+                        values[i] = InternalValue.create(in, false);
                     } finally {
                         try {
                             in.close();
@@ -291,7 +291,7 @@
                 } else {
                     InputStream is = blobStore.get(s);
                     try {
-                        val = InternalValue.create(is);
+                        val = InternalValue.create(is, false);
                     } finally {
                         try {
                             is.close();

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/xml/XMLPersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/xml/XMLPersistenceManager.java?rev=408647&r1=408646&r2=408647&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/xml/XMLPersistenceManager.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/xml/XMLPersistenceManager.java
Mon May 22 05:32:39 2006
@@ -321,7 +321,7 @@
                             } else {
                                 InputStream in = blobStore.get(content);
                                 try {
-                                    values.add(InternalValue.create(in));
+                                    values.add(InternalValue.create(in, false));
                                 } finally {
                                     try {
                                         in.close();
@@ -660,7 +660,7 @@
                                 } else {
                                     in = blobStore.get(blobId);
                                     try {
-                                        values[i] = InternalValue.create(in);
+                                        values[i] = InternalValue.create(in, false);
                                     } finally {
                                         try {
                                             in.close();

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/value/BLOBFileValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/value/BLOBFileValue.java?rev=408647&r1=408646&r2=408647&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/value/BLOBFileValue.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/value/BLOBFileValue.java
Mon May 22 05:32:39 2006
@@ -82,7 +82,9 @@
     private final File file;
 
     /**
-     * flag indicating if this instance is backed by a temporarily allocated resource/buffer
+     * flag indicating if this instance represents a <i>temporary</i> value
+     * whose dynamically allocated resources can be explicitly freed on
+     * {@link #discard()}.
      */
     private final boolean temp;
 
@@ -97,11 +99,6 @@
     private final FileSystemResource fsResource;
 
     /**
-     * underlying blob file value
-     */
-    private final BLOBFileValue blob;
-
-    /**
      * converted text
      */
     private String text = null;
@@ -111,12 +108,37 @@
      * <code>InputStream</code>. The contents of the stream is spooled
      * to a temporary file or to a byte buffer if its size is smaller than
      * {@link #MAX_BUFFER_SIZE}.
+     * <p/>
+     * The new instance represents a <i>temporary</i> value whose dynamically
+     * allocated resources will be freed explicitly on {@link #discard()}.
      *
      * @param in stream to be represented as a <code>BLOBFileValue</code> instance
      * @throws IOException if an error occurs while reading from the stream or
      *                     writing to the temporary file
      */
     public BLOBFileValue(InputStream in) throws IOException {
+        this(in, true);
+    }
+
+    /**
+     * Creates a new <code>BLOBFileValue</code> instance from an
+     * <code>InputStream</code>. The contents of the stream is spooled
+     * to a temporary file or to a byte buffer if its size is smaller than
+     * {@link #MAX_BUFFER_SIZE}.
+     * <p/>
+     * The <code>temp</code> parameter governs whether dynamically allocated
+     * resources will be freed explicitly on {@link #discard()}. Note that any
+     * dynamically allocated resources (temp file/buffer) will be freed
+     * implicitly once this instance has been gc'ed.
+     *
+     * @param in stream to be represented as a <code>BLOBFileValue</code> instance
+     * @param temp flag indicating whether this instance represents a
+     *             <i>temporary</i> value whose resources can be explicitly freed
+     *             on {@link #discard()}.
+     * @throws IOException if an error occurs while reading from the stream or
+     *                     writing to the temporary file
+     */
+    public BLOBFileValue(InputStream in, boolean temp) throws IOException {
         byte[] spoolBuffer = new byte[0x2000];
         int read;
         int len = 0;
@@ -156,9 +178,7 @@
         // init vars
         file = spoolFile;
         fsResource = null;
-        blob = null;
-        // this instance is backed by a temporarily allocated resource/buffer
-        temp = true;
+        this.temp = temp;
     }
 
     /**
@@ -172,7 +192,6 @@
         buffer = bytes;
         file = null;
         fsResource = null;
-        blob = null;
         // this instance is not backed by a temporarily allocated buffer
         temp = false;
     }
@@ -194,7 +213,6 @@
         this.file = file;
         // this instance is backed by a 'real' file; set virtual fs resource to null
         fsResource = null;
-        blob = null;
         // this instance is not backed by temporarily allocated resource/buffer
         temp = false;
     }
@@ -220,28 +238,11 @@
         this.fsResource = fsResource;
         // set 'real' file to null
         file = null;
-        blob = null;
         // this instance is not backed by temporarily allocated resource/buffer
         temp = false;
     }
 
     /**
-     * Creates a new <code>BLOBFileValue</code> instance from a existing blob.
-     *
-     * @param blob the existing blob
-     */
-    public BLOBFileValue(BLOBFileValue blob) {
-        // this instance is backed by a blob
-        this.blob = blob;
-        // set 'real' file to null
-        file = null;
-        fsResource = null;
-        // this instance is not backed by temporarily allocated resource/buffer
-        temp = false;
-    }
-
-
-    /**
      * Returns the length of this <code>BLOBFileValue</code>.
      *
      * @return The length, in bytes, of this <code>BLOBFileValue</code>,
@@ -262,8 +263,6 @@
             } catch (FileSystemException fse) {
                 return -1;
             }
-        } else if (blob != null) {
-            return blob.getLength();
         } else {
             // this instance is backed by an in-memory buffer
             return buffer.length;
@@ -287,8 +286,6 @@
         if (file != null) {
             // this instance is backed by a temp file
             file.delete();
-        } else if (blob != null) {
-            blob.discard();
         } else if (buffer != null) {
             // this instance is backed by an in-memory buffer
             buffer = EMPTY_BYTE_ARRAY;
@@ -335,8 +332,6 @@
                 // ignore
                 log.warn("Error while deleting BLOBFileValue: " + fse.getMessage());
             }
-        } else if (blob != null) {
-            blob.delete(pruneEmptyParentDirs);
         } else {
             // this instance is backed by an in-memory buffer
             buffer = EMPTY_BYTE_ARRAY;
@@ -353,11 +348,6 @@
      * @throws IOException         if an error occurs while while spooling
      */
     public void spool(OutputStream out) throws RepositoryException, IOException {
-        if (blob != null) {
-            blob.spool(out);
-            return;
-        }
-
         InputStream in;
         if (file != null) {
             // this instance is backed by a 'real' file
@@ -389,7 +379,6 @@
             try {
                 in.close();
             } catch (IOException ignore) {
-                // ignore
             }
         }
     }
@@ -411,8 +400,6 @@
         } else if (fsResource != null) {
             // this instance is backed by a resource in the virtual file system
             return fsResource.toString();
-        } else if (blob != null) {
-            return blob.toString();
         } else {
             // this instance is backed by an in-memory buffer
             return buffer.toString();
@@ -430,7 +417,6 @@
             BLOBFileValue other = (BLOBFileValue) obj;
             return ((file == null ? other.file == null : file.equals(other.file))
                     && (fsResource == null ? other.fsResource == null : fsResource.equals(other.fsResource))
-                    && (blob == null ? other.blob == null : blob.equals(other.blob))
                     && Arrays.equals(buffer, other.buffer));
         }
         return false;
@@ -497,8 +483,6 @@
                 throw new RepositoryException("file backing binary value not found",
                         fnfe);
             }
-        } else if (blob != null) {
-            return blob.getStream();
         } else if (fsResource != null) {
             // this instance is backed by a resource in the virtual file system
             try {
@@ -560,14 +544,4 @@
             RepositoryException {
         return Boolean.valueOf(getString()).booleanValue();
     }
-
-    /**
-     * Creates a copy of this blob file value that has the 'temporary' field
-     * cleared. if the 'temp' flag is not set, <code>this</code> is returned.
-     *
-     * @return a new value based on this one.
-     */
-    public BLOBFileValue copy() {
-        return temp ? new BLOBFileValue(this) : this;
-    }
-}
\ No newline at end of file
+}

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java?rev=408647&r1=408646&r2=408647&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java
Mon May 22 05:32:39 2006
@@ -234,6 +234,16 @@
 
     /**
      * @param value
+     * @param temp
+     * @return
+     * @throws IOException
+     */
+    public static InternalValue create(InputStream value, boolean temp) throws IOException
{
+        return new InternalValue(new BLOBFileValue(value, temp));
+    }
+
+    /**
+     * @param value
      * @return
      * @throws IOException
      */



Mime
View raw message