jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1481964 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core: data/ data/db/ value/
Date Mon, 13 May 2013 16:47:30 GMT
Author: jukka
Date: Mon May 13 16:47:30 2013
New Revision: 1481964

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

Move the getReference() method from DataIdentifier to DataRecord to make identifier handling
easier

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/AbstractDataRecord.java
    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/DataIdentifier.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/DataRecord.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/FileDataRecord.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/FileDataStore.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DbDataRecord.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DbDataStore.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInDataStore.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/AbstractDataRecord.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/AbstractDataRecord.java?rev=1481964&r1=1481963&r2=1481964&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/AbstractDataRecord.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/AbstractDataRecord.java
Mon May 13 16:47:30 2013
@@ -26,6 +26,11 @@ package org.apache.jackrabbit.core.data;
 public abstract class AbstractDataRecord implements DataRecord {
 
     /**
+     * The data store that contains this record.
+     */
+    private final AbstractDataStore store;
+
+    /**
      * The binary identifier;
      */
     private final DataIdentifier identifier;
@@ -35,7 +40,9 @@ public abstract class AbstractDataRecord
      *
      * @param identifier data identifier
      */
-    public AbstractDataRecord(DataIdentifier identifier) {
+    public AbstractDataRecord(
+            AbstractDataStore store, DataIdentifier identifier) {
+        this.store = store;
         this.identifier = identifier;
     }
 
@@ -48,6 +55,10 @@ public abstract class AbstractDataRecord
         return identifier;
     }
 
+    public String getReference() {
+        return store.getReferenceFromIdentifier(identifier);
+    }
+
     /**
      * Returns the string representation of the data identifier.
      *

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=1481964&r1=1481963&r2=1481964&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 13 16:47:30 2013
@@ -52,14 +52,12 @@ public abstract class AbstractDataStore 
 
     @Override
     public DataIdentifier getIdentifierFromReference(String reference) {
-        if (secret != null) {
-            int colon = reference.indexOf(':');
-            if (colon != -1) {
-                String identifier = reference.substring(0, colon);
-                String signature = reference.substring(colon + 1);
-                if (signature.equals(sign(identifier))) {
-                    return new DataIdentifier(identifier, reference);
-                }
+        int colon = reference.indexOf(':');
+        if (colon != -1) {
+            DataIdentifier identifier =
+                    new DataIdentifier(reference.substring(0, colon));
+            if (reference.equals(getReferenceFromIdentifier(identifier))) {
+                return identifier;
             }
         }
         return null;
@@ -67,27 +65,21 @@ public abstract class AbstractDataStore 
 
     //---------------------------------------------------------< protected >--
 
-    protected DataIdentifier createIdentifier(final String identifier) {
+    protected String getReferenceFromIdentifier(DataIdentifier identifier) {
         if (secret != null) {
-            return new DataIdentifier(identifier) {
-                public String getReference() {
-                    return identifier + ':' + sign(identifier);
-                }
-            };
-        } else {
-            return new DataIdentifier(identifier);
-        }
-    }
+            try {
+                String id = identifier.toString();
 
-    private String sign(String identifier) {
-        try {
-            Mac mac = Mac.getInstance(ALGORITHM);
-            mac.init(new SecretKeySpec(secret.getBytes("UTF-8"), ALGORITHM));
-            return encodeHexString(mac.doFinal(identifier.getBytes("UTF-8")));
-        } catch (Exception e) {
-            // TODO: log a warning about this exception
-            return null;
+                Mac mac = Mac.getInstance(ALGORITHM);
+                mac.init(new SecretKeySpec(secret.getBytes("UTF-8"), ALGORITHM));
+                byte[] hash = mac.doFinal(id.getBytes("UTF-8"));
+
+                return id + ':' + encodeHexString(hash);
+            } catch (Exception e) {
+                // TODO: log a warning about this exception
+            }
         }
+        return null;
     }
 
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/DataIdentifier.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/DataIdentifier.java?rev=1481964&r1=1481963&r2=1481964&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/DataIdentifier.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/DataIdentifier.java
Mon May 13 16:47:30 2013
@@ -36,48 +36,12 @@ public class DataIdentifier implements S
     private final String identifier;
 
     /**
-     * Binary reference, or {@code null}.
-     */
-    private final String reference;
-
-    /**
-     * Creates a data identifier from the given string.
-     *
-     * @param identifier data identifier
-     * @param reference binary reference, or {@code null}
-     */
-    public DataIdentifier(String identifier, String reference) {
-        this.identifier = identifier;
-        this.reference = reference;
-    }
-
-    /**
      * Creates a data identifier from the given string.
      *
      * @param identifier data identifier
      */
     public DataIdentifier(String identifier) {
-        this(identifier, null);
-    }
-
-    /**
-     * Creates a data identifier from the hexadecimal string
-     * representation of the given bytes.
-     *
-     * @param identifier data identifier
-     */
-    public DataIdentifier(byte[] identifier) {
-        this(AbstractDataStore.encodeHexString(identifier), null);
-    }
-
-    /**
-     * Returns a secure reference to the identified binary, or {@code null}
-     * if no such reference is available.
-     *
-     * @return binary reference, or {@code null}
-     */
-    public String getReference() {
-        return reference;
+        this.identifier  = identifier;
     }
 
     //-------------------------------------------------------------< Object >

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/DataRecord.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/DataRecord.java?rev=1481964&r1=1481963&r2=1481964&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/DataRecord.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/DataRecord.java
Mon May 13 16:47:30 2013
@@ -31,6 +31,14 @@ public interface DataRecord {
     DataIdentifier getIdentifier();
 
     /**
+     * Returns a secure reference to this binary, or {@code null} if no such
+     * reference is available.
+     *
+     * @return binary reference, or {@code null}
+     */
+    String getReference();
+
+    /**
      * Returns the length of the binary stream in this record.
      *
      * @return length of the binary stream

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/FileDataRecord.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/FileDataRecord.java?rev=1481964&r1=1481963&r2=1481964&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/FileDataRecord.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/FileDataRecord.java
Mon May 13 16:47:30 2013
@@ -36,8 +36,9 @@ public class FileDataRecord extends Abst
      * @param identifier data identifier
      * @param file file that contains the binary stream
      */
-    public FileDataRecord(DataIdentifier identifier, File file) {
-        super(identifier);
+    public FileDataRecord(
+            AbstractDataStore store, DataIdentifier identifier, File file) {
+        super(store, identifier);
         assert file.isFile();
         this.file = file;
     }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/FileDataStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/FileDataStore.java?rev=1481964&r1=1481963&r2=1481964&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/FileDataStore.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/FileDataStore.java
Mon May 13 16:47:30 2013
@@ -158,7 +158,7 @@ public class FileDataStore extends Abstr
                 }
             }
             usesIdentifier(identifier);
-            return new FileDataRecord(identifier, file);
+            return new FileDataRecord(this, identifier, file);
         }
     }
 
@@ -209,7 +209,7 @@ public class FileDataStore extends Abstr
                 output.close();
             }
             DataIdentifier identifier =
-                    createIdentifier(encodeHexString(digest.digest()));
+                    new DataIdentifier(encodeHexString(digest.digest()));
             File file;
 
             synchronized (this) {
@@ -247,7 +247,7 @@ public class FileDataStore extends Abstr
             // this will also make sure that
             // tempId is not garbage collected until here
             inUse.remove(tempId);
-            return new FileDataRecord(identifier, file);
+            return new FileDataRecord(this, identifier, file);
         } catch (NoSuchAlgorithmException e) {
             throw new DataStoreException(DIGEST + " not available", e);
         } catch (IOException e) {

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DbDataRecord.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DbDataRecord.java?rev=1481964&r1=1481963&r2=1481964&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DbDataRecord.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DbDataRecord.java
Mon May 13 16:47:30 2013
@@ -40,7 +40,7 @@ public class DbDataRecord extends Abstra
      * @param lastModified
      */
     public DbDataRecord(DbDataStore store, DataIdentifier identifier, long length, long lastModified)
{
-        super(identifier);
+        super(store, identifier);
         this.store = store;
         this.length = length;
         this.lastModified = lastModified;

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DbDataStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DbDataStore.java?rev=1481964&r1=1481963&r2=1481964&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DbDataStore.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DbDataStore.java
Mon May 13 16:47:30 2013
@@ -357,7 +357,7 @@ public class DbDataStore extends Abstrac
             conHelper.exec(updateDataSQL, wrapper, tempId);
             long length = in.getByteCount();
             DataIdentifier identifier =
-                    createIdentifier(encodeHexString(digest.digest()));
+                    new DataIdentifier(encodeHexString(digest.digest()));
             usesIdentifier(identifier);
             String id = identifier.toString();
             long newModified;

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInDataStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInDataStore.java?rev=1481964&r1=1481963&r2=1481964&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInDataStore.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInDataStore.java
Mon May 13 16:47:30 2013
@@ -106,7 +106,12 @@ class BLOBInDataStore extends BLOBFileVa
 
     @Override
     public String getReference() {
-        return identifier.getReference();
+        try {
+            return getDataRecord().getReference();
+        } catch (DataStoreException e) {
+            log.warn("Unable to access the reference to " + identifier, e);
+            return null;
+        }
     }
 
     public String toString() {



Mime
View raw message