jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r178432 - in /incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core: PropertyImpl.java state/obj/ObjectPersistenceManager.java state/xml/XMLPersistenceManager.java value/BLOBFileValue.java
Date Wed, 25 May 2005 13:04:01 GMT
Author: stefan
Date: Wed May 25 06:04:00 2005
New Revision: 178432

URL: http://svn.apache.org/viewcvs?rev=178432&view=rev
Log:
BLOBFileValue: added new method: discard() and provided cleaner semantics

Modified:
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/PropertyImpl.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/obj/ObjectPersistenceManager.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/xml/XMLPersistenceManager.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/value/BLOBFileValue.java

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/PropertyImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/PropertyImpl.java?rev=178432&r1=178431&r2=178432&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/PropertyImpl.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/PropertyImpl.java Wed May
25 06:04:00 2005
@@ -264,7 +264,8 @@
                 if (old != null && old.getType() == PropertyType.BINARY) {
                     // BINARY value
                     BLOBFileValue blob = (BLOBFileValue) old.internalValue();
-                    blob.delete();
+                    blob.discard();
+                    blob = null; // gc hint
                 }
             }
         }

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/obj/ObjectPersistenceManager.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/obj/ObjectPersistenceManager.java?rev=178432&r1=178431&r2=178432&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/obj/ObjectPersistenceManager.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/obj/ObjectPersistenceManager.java
Wed May 25 06:04:00 2005
@@ -310,10 +310,8 @@
                 // replace value instance with value
                 // backed by resource in blob store and delete temp file
                 values[i] = InternalValue.create(blobStore.get(blobId));
-                if (blobVal.isTempFile()) {
-                    blobVal.delete();
-                    blobVal = null; // gc hint
-                }
+                blobVal.discard();
+                blobVal = null; // gc hint
             } else {
                 /**
                  * because writeUTF(String) has a size limit of 65k,

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/xml/XMLPersistenceManager.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/xml/XMLPersistenceManager.java?rev=178432&r1=178431&r2=178432&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/xml/XMLPersistenceManager.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/xml/XMLPersistenceManager.java
Wed May 25 06:04:00 2005
@@ -640,10 +640,8 @@
                                 // replace value instance with value
                                 // backed by internal file and delete temp file
                                 values[i] = InternalValue.create(internalBlobFile);
-                                if (blobVal.isTempFile()) {
-                                    blobVal.delete();
-                                    blobVal = null; // gc hint
-                                }
+                                blobVal.discard();
+                                blobVal = null; // gc hint
                             } else {
                                 writer.write(Text.encodeIllegalXMLCharacters(val.toString()));
                             }

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/value/BLOBFileValue.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/value/BLOBFileValue.java?rev=178432&r1=178431&r2=178432&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/value/BLOBFileValue.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/value/BLOBFileValue.java
Wed May 25 06:04:00 2005
@@ -39,7 +39,7 @@
 
 /**
  * <code>BLOBFileValue</code> represents a binary <code>Value</code>
that
- * is backed by a file. Unlike <code>BinaryValue</code> it has no
+ * is backed by a resource or . Unlike <code>BinaryValue</code> it has no
  * state, i.e. the <code>getStream()</code> method always returns a fresh
  * <code>InputStream</code> instance.
  */
@@ -71,9 +71,9 @@
     private final File file;
 
     /**
-     * flag indicating if this instance is backed by a temp file
+     * flag indicating if this instance is backed by a temporarily allocated resource/buffer
      */
-    private final boolean tmpFile;
+    private final boolean temp;
 
     /**
      * buffer for small-sized data
@@ -141,20 +141,24 @@
         // init vars
         file = spoolFile;
         fsResource = null;
-        tmpFile = true;
+        // this instance is backed by a temporarily allocated resource/buffer
+        temp = true;
     }
 
     /**
      * Creates a new <code>BLOBFileValue</code> instance from a
      * <code>byte[]</code> array.
      *
-     * @param bytes byte buffer to be represented as a <code>BLOBFileValue</code>
instance
+     * @param bytes byte array to be represented as a <code>BLOBFileValue</code>
+     * instance
      */
     public BLOBFileValue(byte[] bytes) {
-        this.buffer = bytes;
-        this.file = null;
-        this.fsResource = null;
-        this.tmpFile = true;
+        buffer = new byte[bytes.length];
+        System.arraycopy(bytes, 0, buffer, 0, bytes.length);
+        file = null;
+        fsResource = null;
+        // this instance is backed by a temporarily allocated buffer
+        temp = true;
     }
 
     /**
@@ -174,8 +178,8 @@
         this.file = file;
         // this instance is backed by a 'real' file; set virtual fs resource to null
         fsResource = null;
-
-        tmpFile = false;
+        // this instance is not backed by temporarily allocated resource/buffer
+        temp = false;
     }
 
     /**
@@ -199,8 +203,8 @@
         this.fsResource = fsResource;
         // set 'real' file to null
         file = null;
-
-        tmpFile = false;
+        // this instance is not backed by temporarily allocated resource/buffer
+        temp = false;
     }
 
     /**
@@ -258,26 +262,45 @@
     }
 
     /**
-     * Returns <code>true</code> it this <code>BLOBFileValue</code>
is backed
-     * by a temporary file.
+     * 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.
      *
-     * @return <code>true</code> it this <code>BLOBFileValue</code>
is backed
-     *         by a temporary file.
+     * @see #delete()
+     * @see #delete(boolean)
      */
-    public boolean isTempFile() {
-        return tmpFile;
+    public void discard() {
+        if (!temp) {
+            // do nothing if this instance is not backed by temporarily
+            // allocated resource/buffer
+            return;
+        }
+        if (file != null) {
+            // this instance is backed by a temp file
+            file.delete();
+        } else if (buffer != null) {
+            // this instance is backed by a in-memory buffer
+            buffer = EMPTY_BYTE_ARRAY;
+        }
     }
 
     /**
-     * Deletes the file backing this <code>BLOBFileValue</code>.
+     * Deletes the persistent resource backing this <code>BLOBFileValue</code>.
      * Same as <code>{@link #delete(false)}</code>.
+     * <p/>
+     * If this <code>BLOBFileValue</code> is <i>not</i> backed by
a persistent
+     * resource calling this method will have no effect.
+     *
+     * @see #discard()
      */
     public void delete() {
-        delete(false);
+        if (!temp) {
+            delete(false);
+        }
     }
 
     /**
-     * Deletes the file backing this <code>BLOBFileValue</code>.
+     * Deletes the persistent resource backing this <code>BLOBFileValue</code>.
      *
      * @param pruneEmptyParentDirs if <code>true</code>, empty parent directories
      *                             will automatically be deleted



Mime
View raw message