jackrabbit-oak-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dpfis...@apache.org
Subject svn commit: r1298400 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk: ./ model/ store/ store/persistence/
Date Thu, 08 Mar 2012 14:10:34 GMT
Author: dpfister
Date: Thu Mar  8 14:10:33 2012
New Revision: 1298400

URL: http://svn.apache.org/viewvc?rev=1298400&view=rev
Log:
refactor String commit id's in Id instances (WIP, bottom layer)

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/model/AbstractCommit.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/model/Id.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/model/MutableCommit.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/model/StoredCommit.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/CopyingGC.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/DefaultRevisionStore.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/persistence/BDbPersistence.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/persistence/FSPersistence.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/persistence/H2Persistence.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/persistence/InMemPersistence.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/persistence/MongoPersistence.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java?rev=1298400&r1=1298399&r2=1298400&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
Thu Mar  8 14:10:33 2012
@@ -124,7 +124,7 @@ public class MicroKernelImpl implements 
         for (int i = history.size() - 1; i >= 0; i--) {
             StoredCommit commit = history.get(i);
             buff.object().
-                    key("id").value(commit.getId()).
+                    key("id").value(commit.getId().toString()).
                     key("ts").value(commit.getCommitTS()).
                     endObject();
         }
@@ -163,7 +163,7 @@ public class MicroKernelImpl implements 
             StoredCommit commit = toCommit;
             while (commit != null) {
                 commits.add(commit);
-                if (commit.getId().equals(fromRevisionId)) {
+                if (commit.getId().toString().equals(fromRevisionId)) {
                     break;
                 }
                 String commitId = commit.getParentId();
@@ -185,13 +185,13 @@ public class MicroKernelImpl implements 
                 continue;
             }
             commitBuff.object().
-                    key("id").value(commit.getId()).
+                    key("id").value(commit.getId().toString()).
                     key("ts").value(commit.getCommitTS()).
                     key("msg").value(commit.getMsg());
-            String diff = diffCache.get(commit.getId());
+            String diff = diffCache.get(commit.getId().toString());
             if (diff == null) {
-                diff = diff(commit.getParentId(), commit.getId(), filter);
-                diffCache.put(commit.getId(), diff);
+                diff = diff(commit.getParentId().toString(), commit.getId().toString(), filter);
+                diffCache.put(commit.getId().toString(), diff);
             }
             commitBuff.key("changes").value(diff).endObject();
         }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/model/AbstractCommit.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/model/AbstractCommit.java?rev=1298400&r1=1298399&r2=1298400&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/model/AbstractCommit.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/model/AbstractCommit.java
Thu Mar  8 14:10:33 2012
@@ -65,6 +65,6 @@ public abstract class AbstractCommit imp
         binding.write("rootNodeId", rootNodeId.getBytes());
         binding.write("commitTS", commitTS);
         binding.write("msg", msg == null ? "" : msg);
-        binding.write("parentId", parentId == null ? "" : parentId);
+        binding.write("parentId", parentId == null ? "" : parentId.toString());
     }
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/model/Id.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/model/Id.java?rev=1298400&r1=1298399&r2=1298400&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/model/Id.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/model/Id.java Thu
Mar  8 14:10:33 2012
@@ -33,7 +33,7 @@ import java.util.Arrays;
  * passed to {@link Id#Id(byte[])} must not be reused or modified, the same
  * applies for the <code>byte[]</code> returned by {@link Id#getBytes()}.
  */
-public class Id {
+public class Id /* implements Comparable<Id> */ {
 
     // the raw bytes making up this identifier
     private final byte[] raw;
@@ -88,6 +88,19 @@ public class Id {
         // the string representation is intentionally not stored
         return StringUtils.convertBytesToHex(raw);
     }
+    
+//    @Override
+//    public int compareTo(Id o) {
+//        byte[] other = o.getBytes();
+//        int len = Math.min(raw.length, other.length);
+//        
+//        for (int i = 0; i < len; i++) {
+//            if (raw[i] != other[i]) {
+//                return raw[i] - other[i];
+//            }
+//        }
+//        return raw.length - other.length;
+//    }
 
     /**
      * Returns the raw byte representation of this identifier.

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/model/MutableCommit.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/model/MutableCommit.java?rev=1298400&r1=1298399&r2=1298400&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/model/MutableCommit.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/model/MutableCommit.java
Thu Mar  8 14:10:33 2012
@@ -24,7 +24,7 @@ public class MutableCommit extends Abstr
     /**
      * Commit id.
      */
-    private String id;
+    private Id id;
     
     public MutableCommit() {
     }
@@ -63,7 +63,7 @@ public class MutableCommit extends Abstr
      * 
      * @return commit id
      */
-    public String getId() {
+    public Id getId() {
         return id;
     }
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/model/StoredCommit.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/model/StoredCommit.java?rev=1298400&r1=1298399&r2=1298400&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/model/StoredCommit.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/model/StoredCommit.java
Thu Mar  8 14:10:33 2012
@@ -23,9 +23,9 @@ import org.apache.jackrabbit.mk.store.Bi
  */
 public class StoredCommit extends AbstractCommit {
 
-    private final String id;
+    private final Id id;
 
-    public static StoredCommit deserialize(String id, Binding binding) throws Exception {
+    public static StoredCommit deserialize(Id id, Binding binding) throws Exception {
         Id rootNodeId = new Id(binding.readBytesValue("rootNodeId"));
         long commitTS = binding.readLongValue("commitTS");
         String msg = binding.readStringValue("msg");
@@ -33,7 +33,7 @@ public class StoredCommit extends Abstra
         return new StoredCommit(id, "".equals(parentId) ? null : parentId, commitTS, rootNodeId,
"".equals(msg) ? null : msg);
     }
 
-    public StoredCommit(String id, String parentId, long commitTS, Id rootNodeId, String
msg) {
+    public StoredCommit(Id id, String parentId, long commitTS, Id rootNodeId, String msg)
{
         this.id = id;
         this.parentId = parentId;
         this.commitTS = commitTS;
@@ -41,12 +41,12 @@ public class StoredCommit extends Abstra
         this.msg = msg;
     }
 
-    public StoredCommit(String id, Commit commit) {
+    public StoredCommit(Id id, Commit commit) {
         super(commit);
         this.id = id;
     }
 
-    public String getId() {
+    public Id getId() {
         return id;
     }
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/CopyingGC.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/CopyingGC.java?rev=1298400&r1=1298399&r2=1298400&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/CopyingGC.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/CopyingGC.java
Thu Mar  8 14:10:33 2012
@@ -70,7 +70,7 @@ public class CopyingGC implements Revisi
     private final TreeSet<MutableCommit> commits = new TreeSet<MutableCommit>(
             new Comparator<MutableCommit>() {
                 public int compare(MutableCommit o1, MutableCommit o2) {
-                    return o1.getId().compareTo(o2.getId());
+                    return o1.getId().toString().compareTo(o2.getId().toString());
                 }
             });
 
@@ -117,7 +117,7 @@ public class CopyingGC implements Revisi
             for (MutableCommit commit : commits) {
                 commit.setParentId(parentId);
                 rsTo.putCommit(commit);
-                parentId = commit.getId();
+                parentId = commit.getId().toString();
             }
         }
         // TODO: swap rsFrom/rsTo and reset them

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/DefaultRevisionStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/DefaultRevisionStore.java?rev=1298400&r1=1298399&r2=1298400&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/DefaultRevisionStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/DefaultRevisionStore.java
Thu Mar  8 14:10:33 2012
@@ -27,7 +27,6 @@ import org.apache.jackrabbit.mk.model.St
 import org.apache.jackrabbit.mk.store.persistence.H2Persistence;
 import org.apache.jackrabbit.mk.store.persistence.Persistence;
 import org.apache.jackrabbit.mk.util.SimpleLRUCache;
-import org.apache.jackrabbit.mk.util.StringUtils;
 import org.apache.jackrabbit.oak.model.NodeState;
 
 import java.io.Closeable;
@@ -189,23 +188,16 @@ public class DefaultRevisionStore implem
             callback.prePersist(this);
         }
 
-        String sid = commit.getId();
-        byte[] rawId;
-        
-        if (sid == null) {
-            rawId = longToBytes(++headCounter);
-        } else {
-            rawId = StringUtils.convertHexToBytes(sid);
+        Id id = commit.getId();
+        if (id == null) {
+            id = new Id(longToBytes(++headCounter));
         }
-        Id id = new Id(rawId);
         pm.writeCommit(id, commit);
 
         if (callback != null)  {
             callback.postPersist(this);
         }
-
-        cache.put(id, new StoredCommit(id.toString(), commit));
-
+        cache.put(id, new StoredCommit(id, commit));
         return id;
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/persistence/BDbPersistence.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/persistence/BDbPersistence.java?rev=1298400&r1=1298399&r2=1298400&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/persistence/BDbPersistence.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/persistence/BDbPersistence.java
Thu Mar  8 14:10:33 2012
@@ -146,7 +146,7 @@ public class BDbPersistence implements P
 
         if (db.get(null, key, data, LockMode.DEFAULT) == OperationStatus.SUCCESS) {
             ByteArrayInputStream in = new ByteArrayInputStream(data.getData());
-            return StoredCommit.deserialize(id.toString(), new BinaryBinding(in));
+            return StoredCommit.deserialize(id, new BinaryBinding(in));
         } else {
             throw new NotFoundException(id.toString());
         }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/persistence/FSPersistence.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/persistence/FSPersistence.java?rev=1298400&r1=1298399&r2=1298400&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/persistence/FSPersistence.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/persistence/FSPersistence.java
Thu Mar  8 14:10:33 2012
@@ -105,7 +105,7 @@ public class FSPersistence implements Pe
         if (f.exists()) {
             BufferedInputStream in = new BufferedInputStream(new FileInputStream(f));
             try {
-                return StoredCommit.deserialize(id.toString(), new BinaryBinding(in));
+                return StoredCommit.deserialize(id, new BinaryBinding(in));
             } finally {
                 in.close();
             }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/persistence/H2Persistence.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/persistence/H2Persistence.java?rev=1298400&r1=1298399&r2=1298400&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/persistence/H2Persistence.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/persistence/H2Persistence.java
Thu Mar  8 14:10:33 2012
@@ -166,7 +166,7 @@ public class H2Persistence implements Pe
                 ResultSet rs = stmt.executeQuery();
                 if (rs.next()) {
                     ByteArrayInputStream in = new ByteArrayInputStream(rs.getBytes(1));
-                    return StoredCommit.deserialize(id.toString(), new BinaryBinding(in));
+                    return StoredCommit.deserialize(id, new BinaryBinding(in));
                 } else {
                     throw new NotFoundException(id.toString());
                 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/persistence/InMemPersistence.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/persistence/InMemPersistence.java?rev=1298400&r1=1298399&r2=1298400&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/persistence/InMemPersistence.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/persistence/InMemPersistence.java
Thu Mar  8 14:10:33 2012
@@ -103,7 +103,7 @@ public class InMemPersistence implements
         byte[] bytes = out.toByteArray();
 
         if (!commits.containsKey(id)) {
-            commits.put(id, StoredCommit.deserialize(id.toString(), new BinaryBinding(new
ByteArrayInputStream(bytes))));
+            commits.put(id, StoredCommit.deserialize(id, new BinaryBinding(new ByteArrayInputStream(bytes))));
         }
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/persistence/MongoPersistence.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/persistence/MongoPersistence.java?rev=1298400&r1=1298399&r2=1298400&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/persistence/MongoPersistence.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/persistence/MongoPersistence.java
Thu Mar  8 14:10:33 2012
@@ -176,9 +176,9 @@ public class MongoPersistence implements
         if (commitObject != null) {
             if (BINARY_FORMAT) {
                 byte[] bytes = (byte[]) commitObject.get(DATA_FIELD);
-                return StoredCommit.deserialize(id.toString(), new BinaryBinding(new ByteArrayInputStream(bytes)));
+                return StoredCommit.deserialize(id, new BinaryBinding(new ByteArrayInputStream(bytes)));
             } else {
-                return StoredCommit.deserialize(id.toString(), new DBObjectBinding(commitObject));
+                return StoredCommit.deserialize(id, new DBObjectBinding(commitObject));
             }
         } else {
             throw new NotFoundException(id.toString());



Mime
View raw message