jackrabbit-oak-dev mailing list archives

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

URL: http://svn.apache.org/viewvc?rev=1298401&view=rev
Log:
refactor String commit id's in Id instances (WIP, middle 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/Commit.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/model/CommitBuilder.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

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=1298401&r1=1298400&r2=1298401&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:15:41 2012
@@ -110,11 +110,11 @@ public class MicroKernelImpl implements 
                     && commit.getCommitTS() >= since) {
                 history.add(commit);
 
-                String commitId = commit.getParentId();
+                Id commitId = commit.getParentId();
                 if (commitId == null) {
                     break;
                 }
-                commit = rep.getCommit(commitId);
+                commit = rep.getCommit(commitId.toString());
             }
         } catch (Exception e) {
             throw new MicroKernelException(e);
@@ -166,11 +166,11 @@ public class MicroKernelImpl implements 
                 if (commit.getId().toString().equals(fromRevisionId)) {
                     break;
                 }
-                String commitId = commit.getParentId();
+                Id commitId = commit.getParentId();
                 if (commitId == null) {
                     break;
                 }
-                commit = rep.getCommit(commitId);
+                commit = rep.getCommit(commitId.toString());
             }
         } catch (Exception e) {
             throw new MicroKernelException(e);

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=1298401&r1=1298400&r2=1298401&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:15:41 2012
@@ -33,7 +33,7 @@ public abstract class AbstractCommit imp
     protected String msg;
 
     // id of parent commit
-    protected String parentId;
+    protected Id parentId;
 
     protected AbstractCommit() {
     }
@@ -45,7 +45,7 @@ public abstract class AbstractCommit imp
         this.commitTS = other.getCommitTS();
     }
 
-    public String getParentId() {
+    public Id getParentId() {
         return parentId;
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/model/Commit.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/model/Commit.java?rev=1298401&r1=1298400&r2=1298401&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/model/Commit.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/model/Commit.java
Thu Mar  8 14:15:41 2012
@@ -25,7 +25,7 @@ public interface Commit {
     
     Id getRootNodeId();
 
-    public String getParentId();
+    public Id getParentId();
 
     public long getCommitTS();
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/model/CommitBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/model/CommitBuilder.java?rev=1298401&r1=1298400&r2=1298401&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/model/CommitBuilder.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/model/CommitBuilder.java
Thu Mar  8 14:15:41 2012
@@ -213,7 +213,7 @@ public class CommitBuilder {
                 return currentHead;
             }
             MutableCommit newCommit = new MutableCommit();
-            newCommit.setParentId(baseRevId);
+            newCommit.setParentId(Id.fromString(baseRevId));
             newCommit.setCommitTS(System.currentTimeMillis());
             newCommit.setMsg(msg);
             newCommit.setRootNodeId(rootNodeId);

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=1298401&r1=1298400&r2=1298401&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:15:41 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 /* implements Comparable<Id> */ {
+public class Id implements Comparable<Id> {
 
     // the raw bytes making up this identifier
     private final byte[] raw;
@@ -89,18 +89,18 @@ public class Id /* implements Comparable
         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;
-//    }
+    @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=1298401&r1=1298400&r2=1298401&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:15:41 2012
@@ -42,7 +42,7 @@ public class MutableCommit extends Abstr
         this.id = other.getId();
     }
 
-    public void setParentId(String parentId) {
+    public void setParentId(Id parentId) {
         this.parentId = parentId;
     }
 

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=1298401&r1=1298400&r2=1298401&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:15:41 2012
@@ -30,10 +30,11 @@ public class StoredCommit extends Abstra
         long commitTS = binding.readLongValue("commitTS");
         String msg = binding.readStringValue("msg");
         String parentId = binding.readStringValue("parentId");
-        return new StoredCommit(id, "".equals(parentId) ? null : parentId, commitTS, rootNodeId,
"".equals(msg) ? null : msg);
+        return new StoredCommit(id, "".equals(parentId) ? null : Id.fromString(parentId),
+                commitTS, rootNodeId, "".equals(msg) ? null : msg);
     }
 
-    public StoredCommit(Id id, String parentId, long commitTS, Id rootNodeId, String msg)
{
+    public StoredCommit(Id id, Id parentId, long commitTS, Id rootNodeId, String msg) {
         this.id = id;
         this.parentId = parentId;
         this.commitTS = commitTS;

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=1298401&r1=1298400&r2=1298401&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:15:41 2012
@@ -60,7 +60,7 @@ public class CopyingGC implements Revisi
     /**
      * First commit id of "to" store.
      */
-    private String firstCommitId;
+    private Id firstCommitId;
     
     /**
      * Map of commits that have been accessed while a GC cycle is running; these
@@ -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().toString().compareTo(o2.getId().toString());
+                    return o1.getId().compareTo(o2.getId());
                 }
             });
 
@@ -92,11 +92,11 @@ public class CopyingGC implements Revisi
      */
     public void start() throws Exception {
         commits.clear();
-        firstCommitId = rsTo.getHeadCommitId().toString();
+        firstCommitId = rsTo.getHeadCommitId();
         
         // Copy the head commit
         MutableCommit commitTo = copy(rsFrom.getHeadCommit());
-        commitTo.setParentId(rsTo.getHeadCommitId().toString());
+        commitTo.setParentId(rsTo.getHeadCommitId());
         Id revId = rsTo.putCommit(commitTo);
         rsTo.setHeadCommitId(revId);
 
@@ -113,11 +113,11 @@ public class CopyingGC implements Revisi
         running = false;
         
         if (commits.size() > 1) {
-            String parentId = firstCommitId;
+            Id parentId = firstCommitId;
             for (MutableCommit commit : commits) {
                 commit.setParentId(parentId);
                 rsTo.putCommit(commit);
-                parentId = commit.getId().toString();
+                parentId = commit.getId();
             }
         }
         // TODO: swap rsFrom/rsTo and reset them



Mime
View raw message