jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dpfis...@apache.org
Subject svn commit: r1305290 - in /jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk: model/ persistence/ store/
Date Mon, 26 Mar 2012 10:06:21 GMT
Author: dpfister
Date: Mon Mar 26 10:06:20 2012
New Revision: 1305290

URL: http://svn.apache.org/viewvc?rev=1305290&view=rev
Log:
Remove Binding from Persistence interface
- make deserialize a separate step in StoredNode

Modified:
    jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/StoredNode.java
    jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/BDbPersistence.java
    jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/FSPersistence.java
    jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/H2Persistence.java
    jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/InMemPersistence.java
    jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/MongoPersistence.java
    jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/Persistence.java
    jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/store/DefaultRevisionStore.java

Modified: jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/StoredNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/StoredNode.java?rev=1305290&r1=1305289&r2=1305290&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/StoredNode.java
(original)
+++ jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/StoredNode.java
Mon Mar 26 10:06:20 2012
@@ -31,23 +31,7 @@ public class StoredNode extends Abstract
 
     private final Id id;
 
-    public static StoredNode deserialize(Id id, RevisionProvider provider, Binding binding)
throws Exception {
-        StoredNode newInstance = new StoredNode(id, provider);
-        Binding.StringEntryIterator iter = binding.readStringMap(":props");
-        while (iter.hasNext()) {
-            Binding.StringEntry entry = iter.next();
-            newInstance.properties.put(entry.getKey(), entry.getValue());
-        }
-        boolean inlined = binding.readIntValue(":inlined") != 0;
-        if (inlined) {
-            newInstance.childEntries = ChildNodeEntriesMap.deserialize(binding);
-        } else {
-            newInstance.childEntries = ChildNodeEntriesTree.deserialize(provider, binding);
-        }
-        return newInstance;
-    }
-
-    private StoredNode(Id id, RevisionProvider provider) {
+    public StoredNode(Id id, RevisionProvider provider) {
         super(provider);
         this.id = id;
     }
@@ -82,4 +66,17 @@ public class StoredNode extends Abstract
         return new UnmodifiableIterator<String>(super.getChildNodeNames(offset, count));
     }
 
+    public void deserialize(Binding binding) throws Exception {
+        Binding.StringEntryIterator iter = binding.readStringMap(":props");
+        while (iter.hasNext()) {
+            Binding.StringEntry entry = iter.next();
+            properties.put(entry.getKey(), entry.getValue());
+        }
+        boolean inlined = binding.readIntValue(":inlined") != 0;
+        if (inlined) {
+            childEntries = ChildNodeEntriesMap.deserialize(binding);
+        } else {
+            childEntries = ChildNodeEntriesTree.deserialize(provider, binding);
+        }
+    }
 }

Modified: jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/BDbPersistence.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/BDbPersistence.java?rev=1305290&r1=1305289&r2=1305290&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/BDbPersistence.java
(original)
+++ jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/BDbPersistence.java
Mon Mar 26 10:06:20 2012
@@ -26,8 +26,8 @@ import org.apache.jackrabbit.mk.model.Co
 import org.apache.jackrabbit.mk.model.Id;
 import org.apache.jackrabbit.mk.model.Node;
 import org.apache.jackrabbit.mk.model.StoredCommit;
+import org.apache.jackrabbit.mk.model.StoredNode;
 import org.apache.jackrabbit.mk.store.BinaryBinding;
-import org.apache.jackrabbit.mk.store.Binding;
 import org.apache.jackrabbit.mk.store.IdFactory;
 import org.apache.jackrabbit.mk.store.NotFoundException;
 
@@ -125,13 +125,14 @@ public class BDbPersistence implements P
         head.put(null, key, data);
     }
 
-    public Binding readNodeBinding(Id id) throws NotFoundException, Exception {
+    public void readNode(StoredNode node) throws NotFoundException, Exception {
+        Id id = node.getId();
         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 new BinaryBinding(in);
+            node.deserialize(new BinaryBinding(in));
         } else {
             throw new NotFoundException(id.toString());
         }

Modified: jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/FSPersistence.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/FSPersistence.java?rev=1305290&r1=1305289&r2=1305290&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/FSPersistence.java
(original)
+++ jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/FSPersistence.java
Mon Mar 26 10:06:20 2012
@@ -27,8 +27,8 @@ import org.apache.jackrabbit.mk.model.Co
 import org.apache.jackrabbit.mk.model.Id;
 import org.apache.jackrabbit.mk.model.Node;
 import org.apache.jackrabbit.mk.model.StoredCommit;
+import org.apache.jackrabbit.mk.model.StoredNode;
 import org.apache.jackrabbit.mk.store.BinaryBinding;
-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.IOUtils;
@@ -80,12 +80,14 @@ public class FSPersistence implements Pe
         }
     }
 
-    public Binding readNodeBinding(Id id) throws NotFoundException, Exception {
+    public void readNode(StoredNode node) throws NotFoundException, Exception {
+        Id id = node.getId();
         File f = getFile(id);
+        
         if (f.exists()) {
             BufferedInputStream in = new BufferedInputStream(new FileInputStream(f));
             try {
-                return new BinaryBinding(in);
+                node.deserialize(new BinaryBinding(in));
             } finally {
                 in.close();
             }

Modified: jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/H2Persistence.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/H2Persistence.java?rev=1305290&r1=1305289&r2=1305290&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/H2Persistence.java
(original)
+++ jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/H2Persistence.java
Mon Mar 26 10:06:20 2012
@@ -16,26 +16,26 @@
  */
 package org.apache.jackrabbit.mk.persistence;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.Closeable;
+import java.io.File;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.Statement;
+
 import org.apache.jackrabbit.mk.model.ChildNodeEntriesMap;
 import org.apache.jackrabbit.mk.model.Commit;
 import org.apache.jackrabbit.mk.model.Id;
 import org.apache.jackrabbit.mk.model.Node;
 import org.apache.jackrabbit.mk.model.StoredCommit;
+import org.apache.jackrabbit.mk.model.StoredNode;
 import org.apache.jackrabbit.mk.store.BinaryBinding;
-import org.apache.jackrabbit.mk.store.Binding;
 import org.apache.jackrabbit.mk.store.IdFactory;
 import org.apache.jackrabbit.mk.store.NotFoundException;
 import org.h2.jdbcx.JdbcConnectionPool;
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.Closeable;
-import java.io.File;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.Statement;
-
 /**
  *
  */
@@ -116,7 +116,8 @@ public class H2Persistence implements Pe
         }
     }
 
-    public Binding readNodeBinding(Id id) throws NotFoundException, Exception {
+    public void readNode(StoredNode node) throws NotFoundException, Exception {
+        Id id = node.getId();
         Connection con = cp.getConnection();
         try {
             PreparedStatement stmt = con.prepareStatement("select DATA from REVS where ID
= ?");
@@ -125,7 +126,7 @@ public class H2Persistence implements Pe
                 ResultSet rs = stmt.executeQuery();
                 if (rs.next()) {
                     ByteArrayInputStream in = new ByteArrayInputStream(rs.getBytes(1));
-                    return new BinaryBinding(in);
+                    node.deserialize(new BinaryBinding(in));
                 } else {
                     throw new NotFoundException(id.toString());
                 }

Modified: jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/InMemPersistence.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/InMemPersistence.java?rev=1305290&r1=1305289&r2=1305290&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/InMemPersistence.java
(original)
+++ jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/InMemPersistence.java
Mon Mar 26 10:06:20 2012
@@ -27,8 +27,8 @@ import org.apache.jackrabbit.mk.model.Co
 import org.apache.jackrabbit.mk.model.Id;
 import org.apache.jackrabbit.mk.model.Node;
 import org.apache.jackrabbit.mk.model.StoredCommit;
+import org.apache.jackrabbit.mk.model.StoredNode;
 import org.apache.jackrabbit.mk.store.BinaryBinding;
-import org.apache.jackrabbit.mk.store.Binding;
 import org.apache.jackrabbit.mk.store.IdFactory;
 import org.apache.jackrabbit.mk.store.NotFoundException;
 
@@ -54,10 +54,11 @@ public class InMemPersistence implements
         head = id;
     }
 
-    public Binding readNodeBinding(Id id) throws NotFoundException {
+    public void readNode(StoredNode node) throws NotFoundException, Exception {
+        Id id = node.getId();
         byte[] bytes = nodes.get(id);
         if (bytes != null) {
-            return new BinaryBinding(new ByteArrayInputStream(bytes));
+            node.deserialize(new BinaryBinding(new ByteArrayInputStream(bytes)));
         } else {
             throw new NotFoundException(id.toString());
         }

Modified: jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/MongoPersistence.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/MongoPersistence.java?rev=1305290&r1=1305289&r2=1305290&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/MongoPersistence.java
(original)
+++ jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/MongoPersistence.java
Mon Mar 26 10:06:20 2012
@@ -30,6 +30,7 @@ import org.apache.jackrabbit.mk.model.Co
 import org.apache.jackrabbit.mk.model.Id;
 import org.apache.jackrabbit.mk.model.Node;
 import org.apache.jackrabbit.mk.model.StoredCommit;
+import org.apache.jackrabbit.mk.model.StoredNode;
 import org.apache.jackrabbit.mk.store.BinaryBinding;
 import org.apache.jackrabbit.mk.store.Binding;
 import org.apache.jackrabbit.mk.store.IdFactory;
@@ -123,7 +124,8 @@ public class MongoPersistence implements
         db.getCollection(HEAD_COLLECTION).insert(new BasicDBObject(ID_FIELD, id.getBytes()));
     }
 
-    public Binding readNodeBinding(Id id) throws NotFoundException, Exception {
+    public void readNode(StoredNode node) throws NotFoundException, Exception {
+        Id id = node.getId();
         BasicDBObject key = new BasicDBObject();
         if (BINARY_FORMAT) {
             key.put(ID_FIELD, id.getBytes());
@@ -132,12 +134,14 @@ public class MongoPersistence implements
         }
         final BasicDBObject nodeObject = (BasicDBObject) nodes.findOne(key);
         if (nodeObject != null) {
+            Binding binding;
             if (BINARY_FORMAT) {
                 byte[] bytes = (byte[]) nodeObject.get(DATA_FIELD);
-                return new BinaryBinding(new ByteArrayInputStream(bytes));
+                binding = new BinaryBinding(new ByteArrayInputStream(bytes));
             } else {
-                return new DBObjectBinding(nodeObject);
+                binding = new DBObjectBinding(nodeObject);
             }
+            node.deserialize(binding);
         } else {
             throw new NotFoundException(id.toString());
         }

Modified: jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/Persistence.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/Persistence.java?rev=1305290&r1=1305289&r2=1305290&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/Persistence.java
(original)
+++ jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/Persistence.java
Mon Mar 26 10:06:20 2012
@@ -21,15 +21,12 @@ import org.apache.jackrabbit.mk.model.Co
 import org.apache.jackrabbit.mk.model.Id;
 import org.apache.jackrabbit.mk.model.Node;
 import org.apache.jackrabbit.mk.model.StoredCommit;
-import org.apache.jackrabbit.mk.store.Binding;
+import org.apache.jackrabbit.mk.model.StoredNode;
 import org.apache.jackrabbit.mk.store.NotFoundException;
 
 /**
  * Defines the methods exposed by a persistence manager, that stores head
  * revision id, nodes, child node entries and blobs.
- * 
- * TODO: instead of deserializing objects on their own, return Binding
- *       instances, such as in #readNodeBinding.
  */
 public interface Persistence {
 
@@ -37,7 +34,14 @@ public interface Persistence {
 
     void writeHead(Id id) throws Exception;
 
-    Binding readNodeBinding(Id id) throws NotFoundException, Exception;
+    /**
+     * Read a node from storage.
+     * 
+     * @param node node to read, with id given in {@link StoredNode#getId()}
+     * @throws NotFoundException if no such node is found
+     * @throws Exception if some other error occurs
+     */
+    void readNode(StoredNode node) throws NotFoundException, Exception;
 
     Id writeNode(Node node) throws Exception;
 

Modified: jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/store/DefaultRevisionStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/store/DefaultRevisionStore.java?rev=1305290&r1=1305289&r2=1305290&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/store/DefaultRevisionStore.java
(original)
+++ jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/store/DefaultRevisionStore.java
Mon Mar 26 10:06:20 2012
@@ -222,8 +222,8 @@ public class DefaultRevisionStore implem
             return node;
         }
 
-        Binding nodeBinding = pm.readNodeBinding(id);
-        node = StoredNode.deserialize(id, this, nodeBinding);
+        node = new StoredNode(id, this);
+        pm.readNode(node);
 
         cache.put(id, node);
 



Mime
View raw message