jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r617383 - in /jackrabbit/branches/1.4/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/value/ test/java/org/apache/jackrabbit/core/data/
Date Fri, 01 Feb 2008 09:12:42 GMT
Author: thomasm
Date: Fri Feb  1 01:12:37 2008
New Revision: 617383

URL: http://svn.apache.org/viewvc?rev=617383&view=rev
Log:
1.4: Merged revision 616442 (JCR-1346, JCR-1351)

Added:
    jackrabbit/branches/1.4/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/CopyValueTest.java
      - copied unchanged from r616442, jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/CopyValueTest.java
Modified:
    jackrabbit/branches/1.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBFileValue.java
    jackrabbit/branches/1.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInDataStore.java
    jackrabbit/branches/1.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInMemory.java
    jackrabbit/branches/1.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInResource.java
    jackrabbit/branches/1.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInTempFile.java
    jackrabbit/branches/1.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBValue.java
    jackrabbit/branches/1.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java
    jackrabbit/branches/1.4/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/TestAll.java

Modified: jackrabbit/branches/1.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBFileValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBFileValue.java?rev=617383&r1=617382&r2=617383&view=diff
==============================================================================
--- jackrabbit/branches/1.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBFileValue.java
(original)
+++ jackrabbit/branches/1.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBFileValue.java
Fri Feb  1 01:12:37 2008
@@ -69,6 +69,14 @@
     public abstract void delete(boolean pruneEmptyParentDirs);
 
     /**
+     * Checks if this object is immutable.
+     * Immutable objects can not change and can safely copied.
+     *
+     * @return true if the object is immutable
+     */
+    public abstract boolean isImmutable();
+
+    /**
      * {@inheritDoc}
      */
     public abstract boolean equals(Object obj);

Modified: jackrabbit/branches/1.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInDataStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInDataStore.java?rev=617383&r1=617382&r2=617383&view=diff
==============================================================================
--- jackrabbit/branches/1.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInDataStore.java
(original)
+++ jackrabbit/branches/1.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInDataStore.java
Fri Feb  1 01:12:37 2008
@@ -61,6 +61,13 @@
         // do nothing
     }
 
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isImmutable() {
+        return true;
+    }
+
     public boolean equals(Object obj) {
         if (!(obj instanceof BLOBInDataStore) || obj == null) {
             return false;

Modified: jackrabbit/branches/1.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInMemory.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInMemory.java?rev=617383&r1=617382&r2=617383&view=diff
==============================================================================
--- jackrabbit/branches/1.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInMemory.java
(original)
+++ jackrabbit/branches/1.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInMemory.java
Fri Feb  1 01:12:37 2008
@@ -119,16 +119,25 @@
      * {@inheritDoc}
      */
     public void delete(boolean pruneEmptyParentDirs) {
-        // TODO avoid: this makes the value mutable
-        data = EMPTY_BYTE_ARRAY;
+        // do nothing
+        // this object could still be referenced
+        // the data will be garbage collected
     }
 
     /**
      * {@inheritDoc}
      */
     public void discard() {
-        // TODO avoid: this makes the value mutable
-        data = EMPTY_BYTE_ARRAY;
+        // do nothing
+        // this object could still be referenced
+        // the data will be garbage collected
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isImmutable() {
+        return true;
     }
 
     /**

Modified: jackrabbit/branches/1.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInResource.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInResource.java?rev=617383&r1=617382&r2=617383&view=diff
==============================================================================
--- jackrabbit/branches/1.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInResource.java
(original)
+++ jackrabbit/branches/1.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInResource.java
Fri Feb  1 01:12:37 2008
@@ -103,6 +103,14 @@
     /**
      * {@inheritDoc}
      */
+    public boolean isImmutable() {
+        // delete will modify the state.
+        return false;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
     public long getLength() {
         return length;
     }

Modified: jackrabbit/branches/1.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInTempFile.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInTempFile.java?rev=617383&r1=617382&r2=617383&view=diff
==============================================================================
--- jackrabbit/branches/1.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInTempFile.java
(original)
+++ jackrabbit/branches/1.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInTempFile.java
Fri Feb  1 01:12:37 2008
@@ -133,6 +133,14 @@
     /**
      * {@inheritDoc}
      */
+    public boolean isImmutable() {
+        // discard and delete can modify the state.
+        return false;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
     public long getLength() {
         return length;
     }

Modified: jackrabbit/branches/1.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBValue.java?rev=617383&r1=617382&r2=617383&view=diff
==============================================================================
--- jackrabbit/branches/1.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBValue.java
(original)
+++ jackrabbit/branches/1.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBValue.java
Fri Feb  1 01:12:37 2008
@@ -237,7 +237,7 @@
      * @see #delete(boolean)
      */
     public void discard() {
-        if (!temp) {
+        if (!temp){
             // do nothing if this instance is not backed by temporarily
             // allocated resource/buffer
             return;
@@ -280,6 +280,14 @@
             // this instance is backed by an in-memory buffer
             buffer = EMPTY_BYTE_ARRAY;
         }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isImmutable() {
+        // delete will modify the state
+        return false;
     }
 
     //-------------------------------------------< java.lang.Object overrides >

Modified: jackrabbit/branches/1.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java?rev=617383&r1=617382&r2=617383&view=diff
==============================================================================
--- jackrabbit/branches/1.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java
(original)
+++ jackrabbit/branches/1.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java
Fri Feb  1 01:12:37 2008
@@ -120,7 +120,7 @@
         switch (value.getType()) {
             case PropertyType.BINARY:
                 if (USE_DATA_STORE) {
-                    return new InternalValue(getBLOBFileValue(store, value.getStream()));
+                    return new InternalValue(getBLOBFileValue(store, value.getStream(), true));
                 }
                 if (value instanceof BLOBFileValue) {
                     return new InternalValue((BLOBFileValue) value);
@@ -225,7 +225,7 @@
      */
     public static InternalValue createTemporary(InputStream value) throws RepositoryException
{
         if (USE_DATA_STORE) {        
-            return new InternalValue(getBLOBFileValue(null, value));
+            return new InternalValue(getBLOBFileValue(null, value, true));
         }
         try {
             return new InternalValue(new BLOBValue(value, true));
@@ -245,7 +245,7 @@
      */
     public static InternalValue createTemporary(InputStream value, DataStore store) throws
RepositoryException {
         if (USE_DATA_STORE) {
-            return new InternalValue(getBLOBFileValue(store, value));
+            return new InternalValue(getBLOBFileValue(store, value, true));
         }
         try {
             return new InternalValue(new BLOBValue(value, true));
@@ -262,7 +262,7 @@
      */
     public static InternalValue create(InputStream value) throws RepositoryException {
         if (USE_DATA_STORE) {
-            return new InternalValue(getBLOBFileValue(null, value));
+            return new InternalValue(getBLOBFileValue(null, value, false));
         }
         try {
             return new InternalValue(new BLOBValue(value, false));
@@ -439,6 +439,8 @@
     }    
 
     /**
+     * Get the type of this value.
+     *
      * @return the type
      */
     public int getType() {
@@ -446,29 +448,34 @@
     }
 
     /**
-     * @return
+     * Create a copy of this object. Immutable values will return itself,
+     * while mutable values will return a copy.
+     *
+     * @return itself or a copy
      * @throws RepositoryException
      */
     public InternalValue createCopy() throws RepositoryException {
-        if (USE_DATA_STORE) {
+        if (type != PropertyType.BINARY) {
+            // for all types except BINARY it's safe to return 'this' because the
+            // wrapped value is immutable (and therefore this instance as well)
             return this;
         }
-        if (type == PropertyType.BINARY) {
-            // return a copy since the wrapped BLOBFileValue instance is mutable
-            InputStream stream = ((BLOBFileValue) val).getStream();
+        BLOBFileValue v = (BLOBFileValue) val;
+        if (USE_DATA_STORE) {
+            if (v.isImmutable()) {
+                return this;
+            }
+        }
+        // return a copy since the wrapped BLOBFileValue instance is mutable
+        InputStream stream = v.getStream();
+        try {
+            return createTemporary(stream);
+        } finally {
             try {
-                return createTemporary(stream);
-            } finally {
-                try {
-                    stream.close();
-                } catch (IOException e) {
-                    // ignore
-                }
+                stream.close();
+            } catch (IOException e) {
+                // ignore
             }
-        } else {
-            // for all other types it's safe to return 'this' because the
-            // wrapped value is immutable (and therefore this instance as well)
-            return this;
         }
     }
 
@@ -594,7 +601,16 @@
         type = PropertyType.REFERENCE;
     }
     
-    private static BLOBFileValue getBLOBFileValue(DataStore store, InputStream in) throws
RepositoryException {
+    /**
+     * Create a BLOB value from in input stream. Small objects will create an in-memory object,
+     * while large objects are stored in the data store or in a temp file (if the store parameter
is not set).
+     *
+     * @param store the data store (optional)
+     * @param in the input stream
+     * @param temporary if the file should be deleted when discard is called (ignored if
a data store is used)
+     * @return the value
+     */
+    private static BLOBFileValue getBLOBFileValue(DataStore store, InputStream in, boolean
temporary) throws RepositoryException {
         int maxMemorySize;
         if (store != null) {
             maxMemorySize = store.getMinRecordLength() - 1;
@@ -627,7 +643,7 @@
             if (store != null) {
                 return BLOBInDataStore.getInstance(store, in);
             } else {
-                return BLOBInTempFile.getInstance(in, true);
+                return BLOBInTempFile.getInstance(in, temporary);
             }
         }
     }
@@ -642,6 +658,13 @@
         }
     }
 
+    /**
+     * 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, IOException {
         assert USE_DATA_STORE;
         assert dataStore != null;
@@ -657,7 +680,7 @@
             }
         }
         // store the temp file to the data store, or (theoretically) load it in memory
-        val = getBLOBFileValue(dataStore, v.getStream());
+        val = getBLOBFileValue(dataStore, v.getStream(), false);
     }
 
 }

Modified: jackrabbit/branches/1.4/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.4/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/TestAll.java?rev=617383&r1=617382&r2=617383&view=diff
==============================================================================
--- jackrabbit/branches/1.4/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/TestAll.java
(original)
+++ jackrabbit/branches/1.4/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/TestAll.java
Fri Feb  1 01:12:37 2008
@@ -36,6 +36,7 @@
         suite.addTestSuite(ExportImportTest.class);
         suite.addTestSuite(GarbageCollectorTest.class);
         suite.addTestSuite(PersistenceManagerIteratorTest.class);
+        suite.addTestSuite(CopyValueTest.class);
         return suite;
     }
 



Mime
View raw message