jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1484444 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/data/ main/java/org/apache/jackrabbit/core/value/ test/java/org/apache/jackrabbit/core/data/
Date Mon, 20 May 2013 12:28:43 GMT
Author: jukka
Date: Mon May 20 12:28:43 2013
New Revision: 1484444

URL: http://svn.apache.org/r1484444
Log:
JCR-3534: Efficient copying of binaries across repositories with the same data store

Change getIdentifierFromReference() to getRecordFromReference() to avoid problems with a previously
valid reference pointing to a record that has already been removed.

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/AbstractDataStore.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/DataStore.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/MultiDataStore.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/DataStoreTest.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/AbstractDataStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/AbstractDataStore.java?rev=1484444&r1=1484443&r2=1484444&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/AbstractDataStore.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/AbstractDataStore.java
Mon May 20 12:28:43 2013
@@ -48,13 +48,16 @@ public abstract class AbstractDataStore 
         }
     }
 
-    public DataIdentifier getIdentifierFromReference(String reference) {
-        int colon = reference.indexOf(':');
-        if (colon != -1) {
-            DataIdentifier identifier =
-                    new DataIdentifier(reference.substring(0, colon));
-            if (reference.equals(getReferenceFromIdentifier(identifier))) {
-                return identifier;
+    public DataRecord getRecordFromReference(String reference)
+            throws DataStoreException {
+        if (reference != null) {
+            int colon = reference.indexOf(':');
+            if (colon != -1) {
+                DataIdentifier identifier =
+                        new DataIdentifier(reference.substring(0, colon));
+                if (reference.equals(getReferenceFromIdentifier(identifier))) {
+                    return getRecordIfStored(identifier);
+                }
             }
         }
         return null;

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/DataStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/DataStore.java?rev=1484444&r1=1484443&r2=1484444&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/DataStore.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/DataStore.java
Mon May 20 12:28:43 2013
@@ -40,8 +40,10 @@ public interface DataStore {
      * 
      * @param identifier data identifier
      * @return the record if found, and null if not
+     * @throws DataStoreException if the data store could not be accessed
      */
-    DataRecord getRecordIfStored(DataIdentifier identifier) throws DataStoreException;
+    DataRecord getRecordIfStored(DataIdentifier identifier)
+            throws DataStoreException;
 
     /**
      * Returns the identified data record. The given identifier should be
@@ -58,6 +60,18 @@ public interface DataStore {
     DataRecord getRecord(DataIdentifier identifier) throws DataStoreException;
 
     /**
+     * Returns the record that matches the given binary reference.
+     * Returns {@code null} if the reference is invalid, for example if it
+     * points to a record that does not exist.
+     *
+     * @param reference binary reference
+     * @return matching record, or {@code null}
+     * @throws DataStoreException if the data store could not be accessed
+     */
+    DataRecord getRecordFromReference(String reference)
+        throws DataStoreException;
+
+    /**
      * Creates a new data record. The given binary stream is consumed and
      * a binary record containing the consumed stream is created and returned.
      * If the same stream already exists in another record, then that record
@@ -109,15 +123,6 @@ public interface DataStore {
     Iterator<DataIdentifier> getAllIdentifiers() throws DataStoreException;
 
     /**
-     * Returns the identifier that matches the given binary reference.
-     * If the reference is invalid, returns {@code null}.
-     *
-     * @param reference binary reference
-     * @return matching identifier, or {@code null}
-     */
-    DataIdentifier getIdentifierFromReference(String reference);
-
-    /**
      * Initialized the data store
      *
      * @param homeDir the home directory of the repository

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/MultiDataStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/MultiDataStore.java?rev=1484444&r1=1484443&r2=1484444&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/MultiDataStore.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/MultiDataStore.java
Mon May 20 12:28:43 2013
@@ -313,13 +313,13 @@ public class MultiDataStore implements D
         return archiveDataStore.getAllIdentifiers();
     }
 
-    @Override
-    public DataIdentifier getIdentifierFromReference(String reference) {
-        DataIdentifier identifier = primaryDataStore.getIdentifierFromReference(reference);
-        if (identifier == null) {
-            identifier = archiveDataStore.getIdentifierFromReference(reference);
+    public DataRecord getRecordFromReference(String reference)
+            throws DataStoreException {
+        DataRecord record = primaryDataStore.getRecordFromReference(reference);
+        if (record == null) {
+            record = archiveDataStore.getRecordFromReference(reference);
         }
-        return identifier;
+        return record;
     }
 
     /**

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=1484444&r1=1484443&r2=1484444&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
Mon May 20 12:28:43 2013
@@ -19,6 +19,7 @@ package org.apache.jackrabbit.core.value
 import org.apache.commons.io.IOUtils;
 import org.apache.jackrabbit.api.ReferenceBinary;
 import org.apache.jackrabbit.core.data.DataIdentifier;
+import org.apache.jackrabbit.core.data.DataRecord;
 import org.apache.jackrabbit.core.data.DataStore;
 import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
 import org.apache.jackrabbit.spi.commons.value.ValueFactoryQImpl;
@@ -109,11 +110,10 @@ public class ValueFactoryImpl extends Va
                 return new BinaryValueImpl(((BLOBFileValue) binary).copy());
             } else if (binary instanceof ReferenceBinary) {
                 String reference = ((ReferenceBinary) binary).getReference();
-                DataIdentifier identifier = store.getIdentifierFromReference(reference);
-                if (identifier != null) {
-                    InternalValue value = InternalValue.getInternalValue(
-                            identifier, store, false);
-                    return new BinaryValueImpl(value.getBLOBFileValue());
+                DataRecord record = store.getRecordFromReference(reference);
+                if (record != null) {
+                    return new BinaryValueImpl(BLOBInDataStore.getInstance(
+                            store, record.getIdentifier()));
                 }
             }
             return createValue(binary.getStream());

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/DataStoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/DataStoreTest.java?rev=1484444&r1=1484443&r2=1484444&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/DataStoreTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/DataStoreTest.java
Mon May 20 12:28:43 2013
@@ -17,7 +17,6 @@
 package org.apache.jackrabbit.core.data;
 
 import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.IOUtils;
 import org.apache.jackrabbit.core.data.db.DbDataStore;
 import org.apache.jackrabbit.test.JUnitTest;
 
@@ -26,7 +25,6 @@ import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
-import java.security.SecureRandom;
 import java.sql.DriverManager;
 import java.sql.SQLException;
 import java.util.ArrayList;
@@ -115,18 +113,7 @@ public class DataStoreTest extends JUnit
             DataRecord record = store.addRecord(new ByteArrayInputStream(data));
             reference = record.getReference();
 
-            DataIdentifier identifier = store.getIdentifierFromReference(reference);
-            record = store.getRecord(identifier);
-            assertEquals(data.length, record.getLength());
-            InputStream stream = record.getStream();
-            try {
-                for (int i = 0; i < data.length; i++) {
-                    assertEquals(data[i] & 0xff, stream.read());
-                }
-                assertEquals(-1, stream.read());
-            } finally {
-                stream.close();
-            }
+            assertReference(data, reference, store);
         } finally {
             store.close();
         }
@@ -134,23 +121,30 @@ public class DataStoreTest extends JUnit
         store = new FileDataStore();
         store.init(testDir + "/reference");
         try {
-            DataIdentifier identifier = store.getIdentifierFromReference(reference);
-            DataRecord record = store.getRecord(identifier);
-            assertEquals(data.length, record.getLength());
-            InputStream stream = record.getStream();
-            try {
-                for (int i = 0; i < data.length; i++) {
-                    assertEquals(data[i] & 0xff, stream.read());
-                }
-                assertEquals(-1, stream.read());
-            } finally {
-                stream.close();
-            }
+            assertReference(data, reference, store);
         } finally {
             store.close();
         }
     }
 
+    private void assertReference(
+            byte[] expected, String reference, DataStore store)
+            throws Exception {
+        DataRecord record = store.getRecordFromReference(reference);
+        assertNotNull(record);
+        assertEquals(expected.length, record.getLength());
+
+        InputStream stream = record.getStream();
+        try {
+            for (int i = 0; i < expected.length; i++) {
+                assertEquals(expected[i] & 0xff, stream.read());
+            }
+            assertEquals(-1, stream.read());
+        } finally {
+            stream.close();
+        }
+    }
+
     private void shutdownDatabase(String url) {
         if (url.startsWith("jdbc:derby:") || url.startsWith("jdbc:hsqldb:")) {
             try {



Mime
View raw message