jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r783243 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/ main/java/org/apache/jackrabbit/core/value/ test/java/org/apache/jackrabbit/core/data/
Date Wed, 10 Jun 2009 07:40:35 GMT
Author: thomasm
Date: Wed Jun 10 07:40:32 2009
New Revision: 783243

URL: http://svn.apache.org/viewvc?rev=783243&view=rev
Log:
JCR-2134 Data Store: avoid creating temporary files

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.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
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/InternalValueFactory.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/ValueFactoryImpl.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/CopyValueTest.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/TestTwoGetStreams.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java?rev=783243&r1=783242&r2=783243&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
Wed Jun 10 07:40:32 2009
@@ -1223,7 +1223,7 @@
     public ValueFactory getValueFactory()
             throws UnsupportedRepositoryOperationException, RepositoryException {
         if (valueFactory == null) {
-            valueFactory = new ValueFactoryImpl(this);
+            valueFactory = new ValueFactoryImpl(this, rep.getDataStore());
         }
         return valueFactory;
     }

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=783243&r1=783242&r2=783243&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
Wed Jun 10 07:40:32 2009
@@ -34,7 +34,7 @@
      * @param blob the blob
      */
     BinaryValueImpl(BLOBFileValue blob) throws RepositoryException {
-        super(blob.getStream());
+        super(blob);
         this.blob = blob;
     }
 
@@ -47,15 +47,6 @@
     }
 
     /**
-     * Get the wrapped blob file value
-     * 
-     * @return the blob file value
-     */
-    BLOBFileValue getBlob() {
-        return blob;
-    }
-    
-    /**
      * Get the data identifier if one is available.
      * 
      * @return the data identifier or 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=783243&r1=783242&r2=783243&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
Wed Jun 10 07:40:32 2009
@@ -19,6 +19,7 @@
 import org.apache.commons.io.IOUtils;
 import org.apache.jackrabbit.core.data.DataIdentifier;
 import org.apache.jackrabbit.core.data.DataStore;
+import org.apache.jackrabbit.core.data.DataStoreException;
 import org.apache.jackrabbit.core.fs.FileSystemResource;
 import org.apache.jackrabbit.spi.commons.conversion.MalformedPathException;
 import org.apache.jackrabbit.spi.commons.conversion.NameException;
@@ -123,6 +124,15 @@
                 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();
@@ -207,6 +217,18 @@
                 throw new IllegalArgumentException("illegal value");
         }
     }
+    
+    static InternalValue getInternalValue(DataIdentifier identifier, DataStore store) throws
DataStoreException {
+        // access the record to ensure it is not garbage collected
+        if (store.getRecordIfStored(identifier) != null) {
+            // it exists - so we don't need to stream it again
+            // but we need to create a new object because the original
+            // one might be in a different data store (repository)
+            BLOBFileValue blob = BLOBInDataStore.getInstance(store, identifier);
+            return new InternalValue(blob);
+        }
+        return null;
+    }
 
     /**
      * @param value
@@ -313,6 +335,23 @@
     }
 
     /**
+     * Create an internal value that is stored in the data store (if enabled).
+     * 
+     * @param value the input stream
+     * @return the internal value
+     */
+    public static InternalValue create(InputStream value, DataStore store) throws RepositoryException
{
+        if (USE_DATA_STORE) {
+            return new InternalValue(getBLOBFileValue(store, value, false));
+        }
+        try {
+            return new InternalValue(new BLOBValue(value, false));
+        } catch (IOException e) {
+            throw new RepositoryException("Error creating file", e);
+        }
+    }
+
+    /**
      * @param value
      * @return
      * @throws IOException
@@ -432,7 +471,7 @@
         if (resolver instanceof Session) {
             vf = ((Session) resolver).getValueFactory();
         } else {
-            vf = new ValueFactoryImpl(resolver);
+            vf = new ValueFactoryImpl(resolver, null);
         }
 
         if (vf instanceof ValueFactoryQImpl) {

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/InternalValueFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/InternalValueFactory.java?rev=783243&r1=783242&r2=783243&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/InternalValueFactory.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/InternalValueFactory.java
Wed Jun 10 07:40:32 2009
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.core.value;
 
+import org.apache.jackrabbit.core.data.DataStore;
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.Path;
 import org.apache.jackrabbit.spi.QValue;
@@ -50,11 +51,14 @@
      */
     private static final Logger log = LoggerFactory.getLogger(InternalValueFactory.class);
 
-    private static final QValueFactory INSTANCE = new InternalValueFactory();
+    private static final QValueFactory INSTANCE = new InternalValueFactory(null);
 
-    private InternalValueFactory() {
-    }
+    private final DataStore store;
 
+    InternalValueFactory(DataStore store) {
+        this.store = store;
+    }
+    
     public static QValueFactory getInstance() {
         return INSTANCE;
     }
@@ -146,7 +150,7 @@
     }
 
     public QValue create(InputStream value) throws RepositoryException, IOException {
-        return InternalValue.create(value);
+        return InternalValue.create(value, store);
     }
 
     public QValue create(File value) throws RepositoryException, IOException {

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/ValueFactoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/ValueFactoryImpl.java?rev=783243&r1=783242&r2=783243&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/ValueFactoryImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/ValueFactoryImpl.java
Wed Jun 10 07:40:32 2009
@@ -16,12 +16,15 @@
  */
 package org.apache.jackrabbit.core.value;
 
+import org.apache.jackrabbit.core.data.DataIdentifier;
+import org.apache.jackrabbit.core.data.DataStore;
 import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
 import org.apache.jackrabbit.spi.commons.value.ValueFactoryQImpl;
 import org.apache.jackrabbit.spi.QValue;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import javax.jcr.Binary;
 import javax.jcr.Value;
 import javax.jcr.PropertyType;
 import javax.jcr.ValueFormatException;
@@ -38,6 +41,8 @@
      * logger instance
      */
     private static final Logger log = LoggerFactory.getLogger(ValueFactoryImpl.class);
+    
+    private final DataStore store;
 
     /**
      * Constructs a new <code>ValueFactoryQImpl</code> based
@@ -46,8 +51,9 @@
      *
      * @param resolver wrapped <code>NamePathResolver</code>
      */
-    public ValueFactoryImpl(NamePathResolver resolver) {
-        super(InternalValueFactory.getInstance(), resolver);
+    public ValueFactoryImpl(NamePathResolver resolver, DataStore store) {
+        super(new InternalValueFactory(store), resolver);
+        this.store = store;
     }
 
     public Value createValue(QValue qvalue) {
@@ -56,11 +62,29 @@
                 return new BinaryValueImpl(((InternalValue) qvalue).getBLOBFileValue());
             } catch (RepositoryException e) {
                 // should not get here
-                log.error(e.getMessage());
+                log.error(e.getMessage(), e);
             }
         }
         return super.createValue(qvalue);
     }
+    
+    public Value createValue(Binary binary) {
+        try {
+            if (binary instanceof BLOBInDataStore) {
+                DataIdentifier identifier = ((BLOBInDataStore) binary).getDataIdentifier();
+                InternalValue value = InternalValue.getInternalValue(identifier, store);
+                if (value != null) {
+                    // if the value is already in this data store
+                    return new BinaryValueImpl(value.getBLOBFileValue());
+                }
+            }
+            return createValue(binary.getStream());
+        } catch (RepositoryException e) {
+            log.error(e.getMessage(), e);
+            // ignore - the super method may be smarter
+        }
+        return super.createValue(binary);
+    }    
 
     public Value createValue(InputStream value) {
         try {

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/CopyValueTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/CopyValueTest.java?rev=783243&r1=783242&r2=783243&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/CopyValueTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/CopyValueTest.java
Wed Jun 10 07:40:32 2009
@@ -50,7 +50,7 @@
 
     private void doTestCopy(int length) throws Exception {
         Node root = superuser.getRootNode();
-        if(root.hasNode("testCopy")) {
+        if (root.hasNode("testCopy")) {
             root.getNode("testCopy").remove();
             superuser.save();
         }
@@ -80,7 +80,7 @@
     public void testRandomOperations() throws Exception {
         Random random = new Random(1);
         Node root = superuser.getRootNode();
-        if(root.hasNode("testRandom")) {
+        if (root.hasNode("testRandom")) {
             root.getNode("testRandom").remove();
             superuser.save();
         }
@@ -150,7 +150,7 @@
             }
         }
         superuser.save();
-        for(int i=0; i<opCounts.length; i++) {
+        for (int i = 0; i < opCounts.length; i++) {
             log(i + ": " + opCounts[i]);
         }
         testRoot.remove();

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/TestTwoGetStreams.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/TestTwoGetStreams.java?rev=783243&r1=783242&r2=783243&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/TestTwoGetStreams.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/TestTwoGetStreams.java
Wed Jun 10 07:40:32 2009
@@ -22,6 +22,7 @@
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
 import javax.jcr.Value;
+import javax.jcr.ValueFactory;
 
 import org.apache.jackrabbit.api.JackrabbitValue;
 import org.apache.jackrabbit.core.RepositoryImpl;
@@ -53,8 +54,9 @@
         }
         
         Node root = superuser.getRootNode();
-        root.setProperty("p1", new RandomInputStream(1, STREAM_LENGTH));
-        root.setProperty("p2", new RandomInputStream(1, STREAM_LENGTH));
+        ValueFactory vf = superuser.getValueFactory();
+        root.setProperty("p1", vf.createBinary(new RandomInputStream(1, STREAM_LENGTH)));
+        root.setProperty("p2", vf.createBinary(new RandomInputStream(1, STREAM_LENGTH)));
         superuser.save();
 
         Value v1 = root.getProperty("p1").getValue();



Mime
View raw message