jackrabbit-oak-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dpfis...@apache.org
Subject svn commit: r1298378 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk: ./ model/ store/ store/persistence/
Date Thu, 08 Mar 2012 13:03:52 GMT
Author: dpfister
Date: Thu Mar  8 13:03:51 2012
New Revision: 1298378

URL: http://svn.apache.org/viewvc?rev=1298378&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/Repository.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/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/RevisionProvider.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/RevisionStore.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
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/persistence/Persistence.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/Repository.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/Repository.java?rev=1298378&r1=1298377&r2=1298378&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/Repository.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/Repository.java Thu
Mar  8 13:03:51 2012
@@ -95,7 +95,7 @@ public class Repository {
         if (!initialized) {
             throw new IllegalStateException("not initialized");
         }
-        return rs.getHeadCommitId();
+        return rs.getHeadCommitId().toString();
     }
 
     public StoredCommit getHeadCommit() throws Exception {
@@ -109,7 +109,7 @@ public class Repository {
         if (!initialized) {
             throw new IllegalStateException("not initialized");
         }
-        return rs.getCommit(id);
+        return rs.getCommit(Id.fromString(id));
     }
 
     public NodeState getNodeState(String revId, String path) throws NotFoundException, Exception
{
@@ -129,7 +129,7 @@ public class Repository {
             throw new IllegalStateException("not initialized");
         }
 
-        StoredNode root = rs.getRootNode(revId);
+        StoredNode root = rs.getRootNode(Id.fromString(revId));
         if (PathUtils.denotesRoot(path)) {
             return root;
         }
@@ -150,7 +150,7 @@ public class Repository {
 
         try {
             String[] names = PathUtils.split(path);
-            Node parent = rs.getRootNode(revId);
+            Node parent = rs.getRootNode(Id.fromString(revId));
             for (int i = 0; i < names.length; i++) {
                 ChildNodeEntry cne = parent.getChildNodeEntry(names[i]);
                 if (cne == null) {
@@ -183,7 +183,7 @@ public class Repository {
             throw new IllegalArgumentException("illegal path");
         }
 
-        Commit commit = rs.getCommit(revId);
+        Commit commit = rs.getCommit(Id.fromString(revId));
 
         if (PathUtils.denotesRoot(nodePath)) {
             return new Id[]{commit.getRootNodeId()};

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=1298378&r1=1298377&r2=1298378&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 13:03:51 2012
@@ -176,7 +176,7 @@ public class CommitBuilder {
             return baseRevId;
         }
 
-        String currentHead = store.getHeadCommitId();
+        String currentHead = store.getHeadCommitId().toString();
         if (!currentHead.equals(baseRevId)) {
             // todo gracefully handle certain conflicts (e.g. changes on moved sub-trees,
competing deletes etc)
             // update base revision to new head
@@ -193,13 +193,13 @@ public class CommitBuilder {
 
         Id rootNodeId = persistStagedNodes();
 
-        String newRevId;
+        Id newRevId;
         store.lockHead();
         try {
-            currentHead = store.getHeadCommitId();
+            currentHead = store.getHeadCommitId().toString();
             if (!currentHead.equals(baseRevId)) {
-                StoredNode baseRoot = store.getRootNode(baseRevId);
-                StoredNode theirRoot = store.getRootNode(currentHead);
+                StoredNode baseRoot = store.getRootNode(Id.fromString(baseRevId));
+                StoredNode theirRoot = store.getRootNode(Id.fromString(currentHead));
                 StoredNode ourRoot = store.getNode(rootNodeId);
 
                 rootNodeId = mergeTree(baseRoot, ourRoot, theirRoot);
@@ -207,7 +207,7 @@ public class CommitBuilder {
                 baseRevId = currentHead;
             }
 
-            if (store.getCommit(currentHead).getRootNodeId().equals(rootNodeId)) {
+            if (store.getCommit(Id.fromString(currentHead)).getRootNodeId().equals(rootNodeId))
{
                 // the commit didn't cause any changes,
                 // no need to create new commit object/update head revision
                 return currentHead;
@@ -228,7 +228,7 @@ public class CommitBuilder {
         staged.clear();
         changeLog.clear();
 
-        return newRevId;
+        return newRevId.toString();
     }
 
     MutableNode getOrCreateStagedNode(String nodePath) throws Exception {
@@ -236,7 +236,7 @@ public class CommitBuilder {
         if (node == null) {
             MutableNode parent = staged.get("/");
             if (parent == null) {
-                parent = new MutableNode(store.getRootNode(baseRevId), store);
+                parent = new MutableNode(store.getRootNode(Id.fromString(baseRevId)), store);
                 staged.put("/", parent);
             }
             node = parent;

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=1298378&r1=1298377&r2=1298378&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 13:03:51 2012
@@ -92,12 +92,12 @@ public class CopyingGC implements Revisi
      */
     public void start() throws Exception {
         commits.clear();
-        firstCommitId = rsTo.getHeadCommitId();
+        firstCommitId = rsTo.getHeadCommitId().toString();
         
         // Copy the head commit
         MutableCommit commitTo = copy(rsFrom.getHeadCommit());
-        commitTo.setParentId(rsTo.getHeadCommitId());
-        String revId = rsTo.putCommit(commitTo);
+        commitTo.setParentId(rsTo.getHeadCommitId().toString());
+        Id revId = rsTo.putCommit(commitTo);
         rsTo.setHeadCommitId(revId);
 
         // Add this as sentinel
@@ -190,7 +190,7 @@ public class CopyingGC implements Revisi
         return rsFrom.getNode(id);
     }
 
-    public StoredCommit getCommit(String id) throws NotFoundException,
+    public StoredCommit getCommit(Id id) throws NotFoundException,
             Exception {
         
         if (running) {
@@ -216,7 +216,7 @@ public class CopyingGC implements Revisi
         return rsFrom.getCNEMap(id);
     }
 
-    public StoredNode getRootNode(String commitId) throws NotFoundException,
+    public StoredNode getRootNode(Id commitId) throws NotFoundException,
             Exception {
 
         if (running) {
@@ -238,7 +238,7 @@ public class CopyingGC implements Revisi
         return running ? rsTo.getHeadCommit() : rsFrom.getHeadCommit(); 
     }
 
-    public String getHeadCommitId() throws Exception {
+    public Id getHeadCommitId() throws Exception {
         return running ? rsTo.getHeadCommitId() : rsFrom.getHeadCommitId();
     }
 
@@ -246,7 +246,7 @@ public class CopyingGC implements Revisi
         return running ? rsTo.putNode(node) : rsFrom.putNode(node);
     }
 
-    public String putCommit(MutableCommit commit) throws Exception {
+    public Id putCommit(MutableCommit commit) throws Exception {
         return running ? rsTo.putCommit(commit) : rsFrom.putCommit(commit);
     }
 
@@ -263,7 +263,7 @@ public class CopyingGC implements Revisi
         }
     }
 
-    public void setHeadCommitId(String commitId) throws Exception {
+    public void setHeadCommitId(Id commitId) throws Exception {
         if (running) {
             rsTo.setHeadCommitId(commitId);
         } else {

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=1298378&r1=1298377&r2=1298378&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 13:03:51 2012
@@ -48,7 +48,7 @@ public class DefaultRevisionStore implem
 
     private boolean initialized;
 
-    private String headId;
+    private Id head;
     private long headCounter;
     private final ReentrantReadWriteLock headLock = new ReentrantReadWriteLock();
     private Persistence pm;
@@ -79,20 +79,20 @@ public class DefaultRevisionStore implem
         }
 
         // make sure we've got a HEAD commit
-        headId = pm.readHead();
-        if (headId == null || headId.length() == 0) {
+        head = pm.readHead();
+        if (head == null || head.getBytes().length == 0) {
             // assume virgin repository
-            byte[] rawHeadId = longToBytes(++headCounter);
-            headId = StringUtils.convertBytesToHex(rawHeadId);
+            byte[] rawHead = longToBytes(++headCounter);
+            head = new Id(rawHead);
             
             Id rootNodeId = pm.writeNode(new MutableNode(this));
             MutableCommit initialCommit = new MutableCommit();
             initialCommit.setCommitTS(System.currentTimeMillis());
             initialCommit.setRootNodeId(rootNodeId);
-            pm.writeCommit(rawHeadId, initialCommit);
-            pm.writeHead(headId);
+            pm.writeCommit(head, initialCommit);
+            pm.writeHead(head);
         } else {
-            headCounter = Long.parseLong(headId, 16);
+            headCounter = Long.parseLong(head.toString(), 16);
         }
 
         initialized = true;
@@ -180,7 +180,7 @@ public class DefaultRevisionStore implem
         return id;
     }
 
-    public String putCommit(MutableCommit commit) throws Exception {
+    public Id putCommit(MutableCommit commit) throws Exception {
         verifyInitialized();
 
         PersistHook callback = null;
@@ -189,36 +189,35 @@ public class DefaultRevisionStore implem
             callback.prePersist(this);
         }
 
-        String id = commit.getId();
+        String sid = commit.getId();
         byte[] rawId;
         
-        if (id == null) {
+        if (sid == null) {
             rawId = longToBytes(++headCounter);
-            id = StringUtils.convertBytesToHex(rawId);
         } else {
-            rawId = StringUtils.convertHexToBytes(id);
+            rawId = StringUtils.convertHexToBytes(sid);
         }
-        pm.writeCommit(rawId, commit);
+        Id id = new Id(rawId);
+        pm.writeCommit(id, commit);
 
         if (callback != null)  {
             callback.postPersist(this);
         }
 
-        // TODO fixme, String -> Id
-        cache.put(Id.fromString(id), new StoredCommit(id, commit));
+        cache.put(id, new StoredCommit(id.toString(), commit));
 
         return id;
     }
 
-    public void setHeadCommitId(String commitId) throws Exception {
+    public void setHeadCommitId(Id id) throws Exception {
         verifyInitialized();
 
         headLock.writeLock().lock();
         try {
-            pm.writeHead(commitId);
-            headId = commitId;
+            pm.writeHead(id);
+            head = id;
             
-            long headCounter = Long.parseLong(headId, 16);
+            long headCounter = Long.parseLong(id.toString(), 16);
             if (headCounter > this.headCounter) {
                 this.headCounter = headCounter;
             }
@@ -282,22 +281,21 @@ public class DefaultRevisionStore implem
         return map;
     }
 
-    public StoredCommit getCommit(String id) throws NotFoundException, Exception {
+    public StoredCommit getCommit(Id id) throws NotFoundException, Exception {
         verifyInitialized();
 
-        // TODO fixme, String -> Id
-        StoredCommit commit = (StoredCommit) cache.get(Id.fromString(id));
+        StoredCommit commit = (StoredCommit) cache.get(id);
         if (commit != null) {
             return commit;
         }
 
         commit = pm.readCommit(id);
-        cache.put(Id.fromString(id), commit);
+        cache.put(id, commit);
 
         return commit;
     }
 
-    public StoredNode getRootNode(String commitId) throws NotFoundException, Exception {
+    public StoredNode getRootNode(Id commitId) throws NotFoundException, Exception {
         return getNode(getCommit(commitId).getRootNodeId());
     }
 
@@ -305,12 +303,12 @@ public class DefaultRevisionStore implem
         return getCommit(getHeadCommitId());
     }
 
-    public String getHeadCommitId() throws Exception {
+    public Id getHeadCommitId() throws Exception {
         verifyInitialized();
 
         headLock.readLock().lock();
         try {
-            return headId;
+            return head;
         } finally {
             headLock.readLock().unlock();
         }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/RevisionProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/RevisionProvider.java?rev=1298378&r1=1298377&r2=1298378&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/RevisionProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/RevisionProvider.java
Thu Mar  8 13:03:51 2012
@@ -45,11 +45,11 @@ public interface RevisionProvider {
     Id getId(NodeState node);
 
     StoredNode getNode(Id id) throws NotFoundException, Exception;
-    StoredCommit getCommit(String id) throws NotFoundException, Exception;
+    StoredCommit getCommit(Id id) throws NotFoundException, Exception;
     ChildNodeEntriesMap getCNEMap(Id id) throws NotFoundException, Exception;
-    StoredNode getRootNode(String commitId) throws NotFoundException, Exception;
+    StoredNode getRootNode(Id commitId) throws NotFoundException, Exception;
     StoredCommit getHeadCommit() throws Exception;
-    String getHeadCommitId() throws Exception;
+    Id getHeadCommitId() throws Exception;
     int getBlob(String blobId, long pos, byte[] buff, int off, int length) throws NotFoundException,
Exception;
     long getBlobLength(String blobId) throws NotFoundException, Exception;
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/RevisionStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/RevisionStore.java?rev=1298378&r1=1298377&r2=1298378&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/RevisionStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/RevisionStore.java
Thu Mar  8 13:03:51 2012
@@ -29,9 +29,9 @@ import java.io.InputStream;
 public interface RevisionStore extends RevisionProvider {
 
     Id /*id*/ putNode(MutableNode node) throws Exception;
-    String /*id*/ putCommit(MutableCommit commit) throws Exception;
+    Id /*id*/ putCommit(MutableCommit commit) throws Exception;
     Id /*id*/ putCNEMap(ChildNodeEntriesMap map) throws Exception;
-    void setHeadCommitId(String commitId) throws Exception;
+    void setHeadCommitId(Id commitId) throws Exception;
     void lockHead();
     void unlockHead();
     String /*id*/ putBlob(InputStream in) throws Exception;

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=1298378&r1=1298377&r2=1298378&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 13:03:51 2012
@@ -102,20 +102,20 @@ public class BDbPersistence implements P
         }
     }
 
-    public String readHead() throws Exception {
+    public Id readHead() throws Exception {
         DatabaseEntry key = new DatabaseEntry(HEAD_ID);
         DatabaseEntry data = new DatabaseEntry();
 
         if (head.get(null, key, data, LockMode.DEFAULT) == OperationStatus.SUCCESS) {
-            return StringUtils.convertBytesToHex(data.getData());
+            return new Id(data.getData());
         } else {
             return null;
         }
     }
 
-    public void writeHead(String id) throws Exception {
+    public void writeHead(Id id) throws Exception {
         DatabaseEntry key = new DatabaseEntry(HEAD_ID);
-        DatabaseEntry data = new DatabaseEntry(StringUtils.convertHexToBytes(id));
+        DatabaseEntry data = new DatabaseEntry(id.getBytes());
 
         head.put(null, key, data);
     }
@@ -141,23 +141,23 @@ public class BDbPersistence implements P
         return id;
     }
 
-    public StoredCommit readCommit(String id) throws NotFoundException, Exception {
-        DatabaseEntry key = new DatabaseEntry(StringUtils.convertHexToBytes(id));
+    public StoredCommit readCommit(Id id) throws NotFoundException, Exception {
+        DatabaseEntry key = new DatabaseEntry(id.getBytes());
         DatabaseEntry data = new DatabaseEntry();
 
         if (db.get(null, key, data, LockMode.DEFAULT) == OperationStatus.SUCCESS) {
             ByteArrayInputStream in = new ByteArrayInputStream(data.getData());
-            return StoredCommit.deserialize(id, new BinaryBinding(in));
+            return StoredCommit.deserialize(id.toString(), new BinaryBinding(in));
         } else {
-            throw new NotFoundException(id);
+            throw new NotFoundException(id.toString());
         }
     }
 
-    public void writeCommit(byte[] rawId, Commit commit) throws Exception {
+    public void writeCommit(Id id, Commit commit) throws Exception {
         ByteArrayOutputStream out = new ByteArrayOutputStream();
         commit.serialize(new BinaryBinding(out));
         byte[] bytes = out.toByteArray();
-        persist(rawId, bytes);
+        persist(id.getBytes(), bytes);
     }
 
     public ChildNodeEntriesMap readCNEMap(Id id) throws NotFoundException, Exception {

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=1298378&r1=1298377&r2=1298378&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 13:03:51 2012
@@ -51,26 +51,27 @@ public class FSPersistence implements Pe
         }
         head = new File(homeDir, "HEAD");
         if (!head.exists()) {
-            writeHead("");
+            writeHead(null);
         }
     }
 
     public void close() {
     }
 
-    public String readHead() throws Exception {
+    public Id readHead() throws Exception {
         FileInputStream in = new FileInputStream(head);
         try {
-            return IOUtils.readString(in);
+            String s = IOUtils.readString(in);
+            return s.equals("") ? null : Id.fromString(s);
         } finally {
             in.close();
         }
     }
 
-    public void writeHead(String id) throws Exception {
+    public void writeHead(Id id) throws Exception {
         FileOutputStream out = new FileOutputStream(head);
         try {
-            IOUtils.writeString(out, id);
+            IOUtils.writeString(out, id == null ? "" : id.toString());
         } finally {
             out.close();
         }
@@ -99,25 +100,25 @@ public class FSPersistence implements Pe
         return id;
     }
 
-    public StoredCommit readCommit(String id) throws NotFoundException, Exception {
-        File f = getFile(Id.fromString(id));
+    public StoredCommit readCommit(Id id) throws NotFoundException, Exception {
+        File f = getFile(id);
         if (f.exists()) {
             BufferedInputStream in = new BufferedInputStream(new FileInputStream(f));
             try {
-                return StoredCommit.deserialize(id, new BinaryBinding(in));
+                return StoredCommit.deserialize(id.toString(), new BinaryBinding(in));
             } finally {
                 in.close();
             }
         } else {
-            throw new NotFoundException(id);
+            throw new NotFoundException(id.toString());
         }
     }
 
-    public void writeCommit(byte[] rawId, Commit commit) throws Exception {
+    public void writeCommit(Id id, Commit commit) throws Exception {
         ByteArrayOutputStream out = new ByteArrayOutputStream();
         commit.serialize(new BinaryBinding(out));
         byte[] bytes = out.toByteArray();
-        writeFile(new Id(rawId), bytes);
+        writeFile(id, bytes);
     }
 
     public ChildNodeEntriesMap readCNEMap(Id id) throws NotFoundException, Exception {

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=1298378&r1=1298377&r2=1298378&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 13:03:51 2012
@@ -25,7 +25,6 @@ import org.apache.jackrabbit.mk.store.Bi
 import org.apache.jackrabbit.mk.store.Binding;
 import org.apache.jackrabbit.mk.store.IdFactory;
 import org.apache.jackrabbit.mk.store.NotFoundException;
-import org.apache.jackrabbit.mk.util.StringUtils;
 import org.h2.jdbcx.JdbcConnectionPool;
 
 import java.io.ByteArrayInputStream;
@@ -66,9 +65,9 @@ public class H2Persistence implements Pe
         Connection con = cp.getConnection();
         try {
             Statement stmt = con.createStatement();
-            stmt.execute("create table if not exists REVS (ID binary primary key, DATA binary)");
-            stmt.execute("create table if not exists head(id varchar) as select ''");
-            stmt.execute("create sequence if not exists datastore_id");
+            stmt.execute("create table if not exists REVS(ID binary primary key, DATA binary)");
+            stmt.execute("create table if not exists HEAD(ID binary) as select null");
+            stmt.execute("create sequence if not exists DATASTORE_ID");
 /*
             DbBlobStore store = new DbBlobStore();
             store.setConnectionPool(cp);
@@ -83,27 +82,27 @@ public class H2Persistence implements Pe
         cp.dispose();
     }
 
-    public String readHead() throws Exception {
+    public Id readHead() throws Exception {
         Connection con = cp.getConnection();
         try {
-            PreparedStatement stmt = con.prepareStatement("select * from head");
+            PreparedStatement stmt = con.prepareStatement("select * from HEAD");
             ResultSet rs = stmt.executeQuery();
-            String headId = null;
+            byte[] rawId = null;
             if (rs.next()) {
-                headId = rs.getString(1);
+                rawId = rs.getBytes(1);
             }
             stmt.close();
-            return headId;
+            return rawId == null ? null : new Id(rawId); 
         } finally {
             con.close();
         }
     }
 
-    public void writeHead(String id) throws Exception {
+    public void writeHead(Id id) throws Exception {
         Connection con = cp.getConnection();
         try {
-            PreparedStatement stmt = con.prepareStatement("update head set id=?");
-            stmt.setString(1, id);
+            PreparedStatement stmt = con.prepareStatement("update HEAD set ID=?");
+            stmt.setBytes(1, id.getBytes());
             stmt.execute();
             stmt.close();
         } finally {
@@ -143,7 +142,7 @@ public class H2Persistence implements Pe
         try {
             PreparedStatement stmt = con
                     .prepareStatement(
-                            "insert into REVS (ID, DATA) select ?, ? where not exists (select
1 from revs where ID = ?)");
+                            "insert into REVS (ID, DATA) select ?, ? where not exists (select
1 from REVS where ID = ?)");
             try {
                 stmt.setBytes(1, rawId);
                 stmt.setBytes(2, bytes);
@@ -158,18 +157,18 @@ public class H2Persistence implements Pe
         return new Id(rawId);
     }
 
-    public StoredCommit readCommit(String id) throws NotFoundException, Exception {
+    public StoredCommit readCommit(Id id) throws NotFoundException, Exception {
         Connection con = cp.getConnection();
         try {
             PreparedStatement stmt = con.prepareStatement("select DATA from REVS where ID
= ?");
             try {
-                stmt.setBytes(1, StringUtils.convertHexToBytes(id));
+                stmt.setBytes(1, id.getBytes());
                 ResultSet rs = stmt.executeQuery();
                 if (rs.next()) {
                     ByteArrayInputStream in = new ByteArrayInputStream(rs.getBytes(1));
-                    return StoredCommit.deserialize(id, new BinaryBinding(in));
+                    return StoredCommit.deserialize(id.toString(), new BinaryBinding(in));
                 } else {
-                    throw new NotFoundException(id);
+                    throw new NotFoundException(id.toString());
                 }
             } finally {
                 stmt.close();
@@ -179,7 +178,7 @@ public class H2Persistence implements Pe
         }
     }
     
-    public void writeCommit(byte[] rawId, Commit commit) throws Exception {
+    public void writeCommit(Id id, Commit commit) throws Exception {
         ByteArrayOutputStream out = new ByteArrayOutputStream();
         commit.serialize(new BinaryBinding(out));
         byte[] bytes = out.toByteArray();
@@ -188,11 +187,11 @@ public class H2Persistence implements Pe
         try {
             PreparedStatement stmt = con
                     .prepareStatement(
-                            "insert into REVS (ID, DATA) select ?, ? where not exists (select
1 from revs where ID = ?)");
+                            "insert into REVS (ID, DATA) select ?, ? where not exists (select
1 from REVS where ID = ?)");
             try {
-                stmt.setBytes(1, rawId);
+                stmt.setBytes(1, id.getBytes());
                 stmt.setBytes(2, bytes);
-                stmt.setBytes(3, rawId);
+                stmt.setBytes(3, id.getBytes());
                 stmt.executeUpdate();
             } finally {
                 stmt.close();
@@ -233,7 +232,7 @@ public class H2Persistence implements Pe
         try {
             PreparedStatement stmt = con
                     .prepareStatement(
-                            "insert into REVS (ID, DATA) select ?, ? where not exists (select
1 from revs where ID = ?)");
+                            "insert into REVS (ID, DATA) select ?, ? where not exists (select
1 from REVS where ID = ?)");
             try {
                 stmt.setBytes(1, rawId);
                 stmt.setBytes(2, bytes);

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=1298378&r1=1298377&r2=1298378&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 13:03:51 2012
@@ -35,7 +35,6 @@ import org.apache.jackrabbit.mk.store.Bi
 import org.apache.jackrabbit.mk.store.Binding;
 import org.apache.jackrabbit.mk.store.IdFactory;
 import org.apache.jackrabbit.mk.store.NotFoundException;
-import org.apache.jackrabbit.mk.util.StringUtils;
 
 /**
  *
@@ -43,11 +42,11 @@ import org.apache.jackrabbit.mk.util.Str
 public class InMemPersistence implements Persistence, BlobStore {
 
     private final Map<Id, byte[]> nodes = Collections.synchronizedMap(new HashMap<Id,
byte[]>());
-    private final Map<String, StoredCommit> commits = Collections.synchronizedMap(new
HashMap<String, StoredCommit>());
+    private final Map<Id, StoredCommit> commits = Collections.synchronizedMap(new HashMap<Id,
StoredCommit>());
     private final Map<Id, ChildNodeEntriesMap> cneMaps = Collections.synchronizedMap(new
HashMap<Id, ChildNodeEntriesMap>());
     private final BlobStore blobs = new MemoryBlobStore();
 
-    private String head;
+    private Id head;
 
     // TODO: make this configurable
     private IdFactory idFactory = IdFactory.getDigestFactory();
@@ -59,11 +58,11 @@ public class InMemPersistence implements
     public void close() {
     }
 
-    public String readHead() throws Exception {
+    public Id readHead() throws Exception {
         return head;
     }
 
-    public void writeHead(String id) throws Exception {
+    public void writeHead(Id id) throws Exception {
         head = id;
     }
 
@@ -89,23 +88,22 @@ public class InMemPersistence implements
         return id;
     }
 
-    public StoredCommit readCommit(String id) throws NotFoundException, Exception {
+    public StoredCommit readCommit(Id id) throws NotFoundException, Exception {
         StoredCommit commit = commits.get(id);
         if (commit != null) {
             return commit;
         } else {
-            throw new NotFoundException(id);
+            throw new NotFoundException(id.toString());
         }
     }
 
-    public void writeCommit(byte[] rawId, Commit commit) throws Exception {
+    public void writeCommit(Id id, Commit commit) throws Exception {
         ByteArrayOutputStream out = new ByteArrayOutputStream();
         commit.serialize(new BinaryBinding(out));
         byte[] bytes = out.toByteArray();
-        String id = StringUtils.convertBytesToHex(rawId);
 
         if (!commits.containsKey(id)) {
-            commits.put(id, StoredCommit.deserialize(id, new BinaryBinding(new ByteArrayInputStream(bytes))));
+            commits.put(id, StoredCommit.deserialize(id.toString(), 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=1298378&r1=1298377&r2=1298378&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 13:03:51 2012
@@ -109,17 +109,17 @@ public class MongoPersistence implements
         db = null;
     }
 
-    public String readHead() throws Exception {
+    public Id readHead() throws Exception {
         DBObject entry = db.getCollection(HEAD_COLLECTION).findOne();
         if (entry == null) {
             return null;
         }
-        return (String) entry.get(ID_FIELD);
+        return new Id((byte[]) entry.get(ID_FIELD));
     }
 
-    public void writeHead(String id) throws Exception {
+    public void writeHead(Id id) throws Exception {
         // capped collection of size 1
-        db.getCollection(HEAD_COLLECTION).insert(new BasicDBObject(ID_FIELD, id));
+        db.getCollection(HEAD_COLLECTION).insert(new BasicDBObject(ID_FIELD, id.getBytes()));
     }
 
     public Binding readNodeBinding(Id id) throws NotFoundException, Exception {
@@ -164,37 +164,37 @@ public class MongoPersistence implements
         return id;
     }
 
-    public StoredCommit readCommit(String id) throws NotFoundException, Exception {
+    public StoredCommit readCommit(Id id) throws NotFoundException, Exception {
         BasicDBObject key = new BasicDBObject();
+        
         if (BINARY_FORMAT) {
-            key.put(ID_FIELD, StringUtils.convertHexToBytes(id));
+            key.put(ID_FIELD, id.getBytes());
         } else {
-            key.put(ID_FIELD, id);
+            key.put(ID_FIELD, id.toString());
         }
         BasicDBObject commitObject = (BasicDBObject) commits.findOne(key);
         if (commitObject != null) {
             if (BINARY_FORMAT) {
                 byte[] bytes = (byte[]) commitObject.get(DATA_FIELD);
-                return StoredCommit.deserialize(id, new BinaryBinding(new ByteArrayInputStream(bytes)));
+                return StoredCommit.deserialize(id.toString(), new BinaryBinding(new ByteArrayInputStream(bytes)));
             } else {
-                return StoredCommit.deserialize(id, new DBObjectBinding(commitObject));
+                return StoredCommit.deserialize(id.toString(), new DBObjectBinding(commitObject));
             }
         } else {
-            throw new NotFoundException(id);
+            throw new NotFoundException(id.toString());
         }
     }
 
-    public void writeCommit(byte[] rawId, Commit commit) throws Exception {
+    public void writeCommit(Id id, Commit commit) throws Exception {
         ByteArrayOutputStream out = new ByteArrayOutputStream();
         commit.serialize(new BinaryBinding(out));
         byte[] bytes = out.toByteArray();
-        String id = StringUtils.convertBytesToHex(rawId);
 
         BasicDBObject commitObject;
         if (BINARY_FORMAT) {
-            commitObject = new BasicDBObject(ID_FIELD, rawId).append(DATA_FIELD, bytes);
+            commitObject = new BasicDBObject(ID_FIELD, id.getBytes()).append(DATA_FIELD,
bytes);
         } else {
-            commitObject = new BasicDBObject(ID_FIELD, id);
+            commitObject = new BasicDBObject(ID_FIELD, id.toString());
             commit.serialize(new DBObjectBinding(commitObject));
         }
         try {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/persistence/Persistence.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/persistence/Persistence.java?rev=1298378&r1=1298377&r2=1298378&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/persistence/Persistence.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/persistence/Persistence.java
Thu Mar  8 13:03:51 2012
@@ -39,9 +39,9 @@ public interface Persistence {
 
     void close();
 
-    String readHead() throws Exception;
+    Id readHead() throws Exception;
 
-    void writeHead(String id) throws Exception;
+    void writeHead(Id id) throws Exception;
 
     Binding readNodeBinding(Id id) throws NotFoundException, Exception;
 
@@ -51,7 +51,7 @@ public interface Persistence {
 
     Id writeCNEMap(ChildNodeEntriesMap map) throws Exception;
 
-    StoredCommit readCommit(String id) throws NotFoundException, Exception;
+    StoredCommit readCommit(Id id) throws NotFoundException, Exception;
 
-    void writeCommit(byte[] rawId, Commit commit) throws Exception;
+    void writeCommit(Id id, Commit commit) throws Exception;
 }



Mime
View raw message