jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r1238674 - in /jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk: model/ store/ store/util/ util/
Date Tue, 31 Jan 2012 15:52:33 GMT
Author: stefan
Date: Tue Jan 31 15:52:33 2012
New Revision: 1238674

URL: http://svn.apache.org/viewvc?rev=1238674&view=rev
Log:
refactoring serialization code

Removed:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/util/
Modified:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/ChildNodeEntriesBucket.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/AbstractPersistenceManager.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/BDbPersistenceManager.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/BinaryBinding.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/FSPersistenceManager.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/H2PersistenceManager.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/InMemPersistenceManager.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/MongoPersistenceManager.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/AbstractRangeIterator.java

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/ChildNodeEntriesBucket.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/ChildNodeEntriesBucket.java?rev=1238674&r1=1238673&r2=1238674&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/ChildNodeEntriesBucket.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/ChildNodeEntriesBucket.java
Tue Jan 31 15:52:33 2012
@@ -16,13 +16,28 @@
  */
 package org.apache.jackrabbit.mk.model;
 
+import org.apache.jackrabbit.mk.store.Binding;
+import org.apache.jackrabbit.mk.util.AbstractRangeIterator;
+
 import java.util.HashMap;
+import java.util.Iterator;
 
 /**
  *
  */
 public class ChildNodeEntriesBucket extends ChildNodeEntriesInlined {
 
+    public static ChildNodeEntriesBucket deserialize(String id, Binding binding) throws Exception
{
+        ChildNodeEntriesBucket newInstance = new ChildNodeEntriesBucket();
+
+        Iterator<Binding.KeyValuePair> iter = binding.read(":children");
+        while (iter.hasNext()) {
+            Binding.KeyValuePair kvp = iter.next();
+            newInstance.add(new ChildNodeEntry(kvp.getKey(), kvp.getValue()));
+        }
+        return newInstance;
+    }
+
     public ChildNodeEntriesBucket() {
         // using stock HashMap since keeping insertion-order is not required
         entries = new HashMap<String, ChildNodeEntry>();
@@ -44,4 +59,17 @@ public class ChildNodeEntriesBucket exte
         clone.entries = (HashMap<String, ChildNodeEntry>) entries.clone();
         return clone;
     }
+
+    //------------------------------------------------< serialization support >
+
+    public void serialize(Binding binding) throws Exception {
+        binding.write(":children", getCount(),
+                new AbstractRangeIterator<Binding.KeyValuePair>(getEntries(0, -1),
0, -1) {
+                    @Override
+                    protected Binding.KeyValuePair doNext() {
+                        ChildNodeEntry cne = (ChildNodeEntry) it.next();
+                        return new Binding.KeyValuePair(cne.getName(), cne.getId());
+                    }
+                });
+    }
 }

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/AbstractPersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/AbstractPersistenceManager.java?rev=1238674&r1=1238673&r2=1238674&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/AbstractPersistenceManager.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/AbstractPersistenceManager.java
Tue Jan 31 15:52:33 2012
@@ -25,6 +25,7 @@ import org.apache.jackrabbit.mk.model.St
 import org.apache.jackrabbit.mk.model.StoredNode;
 import org.apache.jackrabbit.mk.util.SimpleLRUCache;
 
+import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.InputStream;
 import java.util.Collections;
@@ -250,4 +251,11 @@ public abstract class AbstractPersistenc
 
         return blobLength(blobId);
     }
+    
+    //------------------------------------------------< serialization support >
+    
+    public byte[] toBytes(Node node, ByteArrayOutputStream out) throws Exception {
+        node.serialize(new BinaryBinding(out));
+        return idFactory.createNodeId(node, out.toByteArray());
+    }
 }

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/BDbPersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/BDbPersistenceManager.java?rev=1238674&r1=1238673&r2=1238674&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/BDbPersistenceManager.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/BDbPersistenceManager.java
Tue Jan 31 15:52:33 2012
@@ -16,6 +16,8 @@
  */
 package org.apache.jackrabbit.mk.store;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.InputStream;
 
@@ -26,7 +28,6 @@ import org.apache.jackrabbit.mk.model.Co
 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.util.Serializer;
 import org.apache.jackrabbit.mk.util.StringUtils;
 
 import com.sleepycat.je.Database;
@@ -128,7 +129,8 @@ public class BDbPersistenceManager exten
         DatabaseEntry data = new DatabaseEntry();
 
         if (db.get(null, key, data, LockMode.DEFAULT) == OperationStatus.SUCCESS) {
-            return Serializer.fromBytes(id, data.getData(), Node.class);
+            ByteArrayInputStream in = new ByteArrayInputStream(data.getData());
+            return StoredNode.deserialize(id, new BinaryBinding(in));
         } else {
             throw new NotFoundException(id);
         }
@@ -136,9 +138,11 @@ public class BDbPersistenceManager exten
 
     @Override
     protected String writeNode(Node node) throws Exception {
-        byte[] data = Serializer.toBytes(node);
-        byte[] rawId = idFactory.createNodeId(node, data);
-        return persist(data, rawId);
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        node.serialize(new BinaryBinding(out));
+        byte[] bytes = out.toByteArray();
+        byte[] rawId = idFactory.createNodeId(node, bytes);
+        return persist(bytes, rawId);
     }
 
     @Override
@@ -147,7 +151,8 @@ public class BDbPersistenceManager exten
         DatabaseEntry data = new DatabaseEntry();
 
         if (db.get(null, key, data, LockMode.DEFAULT) == OperationStatus.SUCCESS) {
-            return Serializer.fromBytes(id, data.getData(), Commit.class);
+            ByteArrayInputStream in = new ByteArrayInputStream(data.getData());
+            return StoredCommit.deserialize(id, new BinaryBinding(in));
         } else {
             throw new NotFoundException(id);
         }
@@ -155,9 +160,11 @@ public class BDbPersistenceManager exten
 
     @Override
     protected String writeCommit(Commit commit) throws Exception {
-        byte[] data = Serializer.toBytes(commit);
-        byte[] rawId = idFactory.createRevisionId(commit, data);
-        return persist(data, rawId);
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        commit.serialize(new BinaryBinding(out));
+        byte[] bytes = out.toByteArray();
+        byte[] rawId = idFactory.createRevisionId(commit, bytes);
+        return persist(bytes, rawId);
     }
 
     @Override

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/BinaryBinding.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/BinaryBinding.java?rev=1238674&r1=1238673&r2=1238674&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/BinaryBinding.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/BinaryBinding.java
Tue Jan 31 15:52:33 2012
@@ -25,66 +25,81 @@ import java.util.Iterator;
 import java.util.NoSuchElementException;
 
 /**
- *
+ * Implementation note: the 'key' parameter is ignored
+ * since it's not required for binary serialization.
  */
 public class BinaryBinding implements Binding {
 
     protected InputStream in;
     protected OutputStream out;
     
-    public BinaryBinding(InputStream in, OutputStream out) {
+    public BinaryBinding(InputStream in) {
         this.in = in;
+        out = null;
+    }
+
+    public BinaryBinding(OutputStream out) {
         this.out = out;
+        in = null;
     }
 
     public void write(String key, String value) throws Exception {
-        IOUtils.writeString(out, key);
+        if (out == null) {
+            throw new IllegalStateException("no OutputStream provided");
+        }
         IOUtils.writeString(out, value);
     }
 
     public void write(String key, long value) throws Exception {
-        IOUtils.writeString(out, key);
+        if (out == null) {
+            throw new IllegalStateException("no OutputStream provided");
+        }
         IOUtils.writeVarLong(out, value);
     }
 
     public void write(String key, int value) throws Exception {
-        IOUtils.writeString(out, key);
+        if (out == null) {
+            throw new IllegalStateException("no OutputStream provided");
+        }
         IOUtils.writeVarInt(out, value);
     }
 
     public void write(String key, int count, Iterator<KeyValuePair> iterator) throws
Exception {
-        IOUtils.writeString(out, key);
+        if (out == null) {
+            throw new IllegalStateException("no OutputStream provided");
+        }
         IOUtils.writeVarInt(out, count);
         while (iterator.hasNext()) {
             KeyValuePair kvp = iterator.next();
-            write(kvp.getKey(), kvp.getValue());
+            IOUtils.writeString(out, kvp.getKey());
+            IOUtils.writeString(out, kvp.getValue());
         }
     }
 
     public String readStringValue(String key) throws Exception {
-        if (!IOUtils.readString(in).equals(key)) {
-            throw new Exception("incompatible serialization format");
+        if (in == null) {
+            throw new IllegalStateException("no InputStream provided");
         }
         return IOUtils.readString(in);
     }
 
     public long readLongValue(String key) throws Exception {
-        if (!IOUtils.readString(in).equals(key)) {
-            throw new Exception("incompatible serialization format");
+        if (in == null) {
+            throw new IllegalStateException("no InputStream provided");
         }
         return IOUtils.readVarLong(in);
     }
 
     public int readIntValue(String key) throws Exception {
-        if (!IOUtils.readString(in).equals(key)) {
-            throw new Exception("incompatible serialization format");
+        if (in == null) {
+            throw new IllegalStateException("no InputStream provided");
         }
         return IOUtils.readVarInt(in);
     }
 
     public Iterator<KeyValuePair> read(String key) throws Exception {
-        if (!IOUtils.readString(in).equals(key)) {
-            throw new Exception("incompatible serialization format");
+        if (in == null) {
+            throw new IllegalStateException("no InputStream provided");
         }
         final int size = IOUtils.readVarInt(in);
         return new Iterator<KeyValuePair>() {

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/FSPersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/FSPersistenceManager.java?rev=1238674&r1=1238673&r2=1238674&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/FSPersistenceManager.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/FSPersistenceManager.java
Tue Jan 31 15:52:33 2012
@@ -30,7 +30,6 @@ import org.apache.jackrabbit.mk.model.Co
 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.util.Serializer;
 import org.apache.jackrabbit.mk.util.IOUtils;
 import org.apache.jackrabbit.mk.util.StringUtils;
 
@@ -88,13 +87,11 @@ public class FSPersistenceManager extend
         File f = getFile(id);
         if (f.exists()) {
             BufferedInputStream in = new BufferedInputStream(new FileInputStream(f));
-            ByteArrayOutputStream out = new ByteArrayOutputStream();
             try {
-                IOUtils.copy(in, out);
+                return StoredNode.deserialize(id, new BinaryBinding(in));
             } finally {
                 in.close();
             }
-            return Serializer.fromBytes(id, out.toByteArray(), Node.class);
         } else {
             throw new NotFoundException(id);
         }
@@ -102,7 +99,9 @@ public class FSPersistenceManager extend
 
     @Override
     protected String writeNode(Node node) throws Exception {
-        byte[] bytes = Serializer.toBytes(node);
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        node.serialize(new BinaryBinding(out));
+        byte[] bytes = out.toByteArray();
         byte[] rawId = idFactory.createNodeId(node, bytes);
         return writeFile(bytes, rawId);
     }
@@ -112,13 +111,11 @@ public class FSPersistenceManager extend
         File f = getFile(id);
         if (f.exists()) {
             BufferedInputStream in = new BufferedInputStream(new FileInputStream(f));
-            ByteArrayOutputStream out = new ByteArrayOutputStream();
             try {
-                IOUtils.copy(in, out);
+                return StoredCommit.deserialize(id, new BinaryBinding(in));
             } finally {
                 in.close();
             }
-            return Serializer.fromBytes(id, out.toByteArray(), Commit.class);
         } else {
             throw new NotFoundException(id);
         }
@@ -126,7 +123,9 @@ public class FSPersistenceManager extend
 
     @Override
     protected String writeCommit(Commit commit) throws Exception {
-        byte[] bytes = Serializer.toBytes(commit);
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        commit.serialize(new BinaryBinding(out));
+        byte[] bytes = out.toByteArray();
         byte[] rawId = idFactory.createRevisionId(commit, bytes);
         return writeFile(bytes, rawId);
     }

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/H2PersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/H2PersistenceManager.java?rev=1238674&r1=1238673&r2=1238674&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/H2PersistenceManager.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/H2PersistenceManager.java
Tue Jan 31 15:52:33 2012
@@ -24,7 +24,6 @@ import org.apache.jackrabbit.mk.model.Co
 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.util.Serializer;
 import org.apache.jackrabbit.mk.util.StringUtils;
 import org.h2.jdbcx.JdbcConnectionPool;
 
@@ -122,11 +121,8 @@ public class H2PersistenceManager extend
                 stmt.setBytes(1, StringUtils.convertHexToBytes(id));
                 ResultSet rs = stmt.executeQuery();
                 if (rs.next()) {
-/*
                     ByteArrayInputStream in = new ByteArrayInputStream(rs.getBytes(1));
-                    return StoredNode.deserialize(id, new BinaryBinding(in, null));
-*/
-                    return Serializer.fromBytes(id, rs.getBytes(1), Node.class);
+                    return StoredNode.deserialize(id, new BinaryBinding(in));
                 } else {
                     throw new NotFoundException(id);
                 }
@@ -140,12 +136,9 @@ public class H2PersistenceManager extend
 
     @Override
     protected String writeNode(Node node) throws Exception {
-/*
         ByteArrayOutputStream out = new ByteArrayOutputStream();
-        node.serialize(new BinaryBinding(null, out));
+        node.serialize(new BinaryBinding(out));
         byte[] bytes = out.toByteArray();
-*/
-        byte[] bytes = Serializer.toBytes(node);
         byte[] rawId = idFactory.createNodeId(node, bytes);
         String id = StringUtils.convertBytesToHex(rawId);
 
@@ -177,11 +170,8 @@ public class H2PersistenceManager extend
                 stmt.setBytes(1, StringUtils.convertHexToBytes(id));
                 ResultSet rs = stmt.executeQuery();
                 if (rs.next()) {
-/*
                     ByteArrayInputStream in = new ByteArrayInputStream(rs.getBytes(1));
-                    return StoredCommit.deserialize(id, new BinaryBinding(in, null));
-*/
-                    return Serializer.fromBytes(id, rs.getBytes(1), Commit.class);
+                    return StoredCommit.deserialize(id, new BinaryBinding(in));
                 } else {
                     throw new NotFoundException(id);
                 }
@@ -195,12 +185,9 @@ public class H2PersistenceManager extend
     
     @Override
     protected String writeCommit(Commit commit) throws Exception {
-/*
         ByteArrayOutputStream out = new ByteArrayOutputStream();
-        commit.serialize(new BinaryBinding(null, out));
+        commit.serialize(new BinaryBinding(out));
         byte[] bytes = out.toByteArray();
-*/
-        byte[] bytes = Serializer.toBytes(commit);
         byte[] rawId = idFactory.createRevisionId(commit, bytes);
         String id = StringUtils.convertBytesToHex(rawId);
 
@@ -249,4 +236,4 @@ public class H2PersistenceManager extend
         // todo implement
         return null;
     }
-}
+}
\ No newline at end of file

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/InMemPersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/InMemPersistenceManager.java?rev=1238674&r1=1238673&r2=1238674&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/InMemPersistenceManager.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/InMemPersistenceManager.java
Tue Jan 31 15:52:33 2012
@@ -16,6 +16,8 @@
  */
 package org.apache.jackrabbit.mk.store;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.InputStream;
 import java.util.Collections;
@@ -29,7 +31,6 @@ import org.apache.jackrabbit.mk.model.Co
 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.util.Serializer;
 import org.apache.jackrabbit.mk.util.StringUtils;
 
 /**
@@ -75,11 +76,13 @@ public class InMemPersistenceManager ext
 
     @Override
     protected String writeNode(Node node) throws Exception {
-        byte[] bytes = Serializer.toBytes(node);
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        node.serialize(new BinaryBinding(out));
+        byte[] bytes = out.toByteArray();
         String id = StringUtils.convertBytesToHex(idFactory.createNodeId(node, bytes));
 
         if (!nodes.containsKey(id)) {
-            nodes.put(id, Serializer.fromBytes(id, bytes, Node.class));
+            nodes.put(id, StoredNode.deserialize(id, new BinaryBinding(new ByteArrayInputStream(bytes))));
         }
 
         return id;
@@ -97,11 +100,13 @@ public class InMemPersistenceManager ext
 
     @Override
     protected String writeCommit(Commit commit) throws Exception {
-        byte[] bytes = Serializer.toBytes(commit);
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        commit.serialize(new BinaryBinding(out));
+        byte[] bytes = out.toByteArray();
         String id = StringUtils.convertBytesToHex(idFactory.createRevisionId(commit, bytes));
 
         if (!commits.containsKey(id)) {
-            commits.put(id, Serializer.fromBytes(id, bytes, Commit.class));
+            commits.put(id, StoredCommit.deserialize(id, new BinaryBinding(new ByteArrayInputStream(bytes))));
         }
 
         return id;

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/MongoPersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/MongoPersistenceManager.java?rev=1238674&r1=1238673&r2=1238674&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/MongoPersistenceManager.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/MongoPersistenceManager.java
Tue Jan 31 15:52:33 2012
@@ -16,6 +16,8 @@
  */
 package org.apache.jackrabbit.mk.store;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.InputStream;
 import java.util.HashMap;
@@ -29,7 +31,6 @@ import org.apache.jackrabbit.mk.model.Co
 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.util.Serializer;
 import org.apache.jackrabbit.mk.util.IOUtils;
 import org.apache.jackrabbit.mk.util.StringUtils;
 import org.bson.types.ObjectId;
@@ -134,7 +135,7 @@ public class MongoPersistenceManager ext
             // todo support partitioned child node lists
             if (BINARY_FORMAT) {
                 byte[] bytes = (byte[]) nodeObject.get(DATA_FIELD);
-                return Serializer.fromBytes(id, bytes, Node.class);
+                return StoredNode.deserialize(id, new BinaryBinding(new ByteArrayInputStream(bytes)));
             } else {
                 final Iterator<String> it = nodeObject.keySet().iterator();
                 final BasicDBObject children = (BasicDBObject) nodeObject.get(CHILDREN_OBJECT);
@@ -162,7 +163,9 @@ public class MongoPersistenceManager ext
 
     @Override
     protected String writeNode(Node node) throws Exception {
-        byte[] bytes = Serializer.toBytes(node);
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        node.serialize(new BinaryBinding(out));
+        byte[] bytes = out.toByteArray();
         byte[] key = idFactory.createNodeId(node, bytes);
         String id = StringUtils.convertBytesToHex(key);
 
@@ -202,7 +205,7 @@ public class MongoPersistenceManager ext
         if (commitObject != null) {
             if (BINARY_FORMAT) {
                 byte[] bytes = (byte[]) commitObject.get(DATA_FIELD);
-                return Serializer.fromBytes(id, bytes, Commit.class);
+                return StoredCommit.deserialize(id, new BinaryBinding(new ByteArrayInputStream(bytes)));
             } else {
                 return new StoredCommit(id,
                         (String) commitObject.get("parentId"),
@@ -217,7 +220,9 @@ public class MongoPersistenceManager ext
 
     @Override
     protected String writeCommit(Commit commit) throws Exception {
-        byte[] bytes = Serializer.toBytes(commit);
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        commit.serialize(new BinaryBinding(out));
+        byte[] bytes = out.toByteArray();
         byte[] key = idFactory.createRevisionId(commit, bytes);
         String id = StringUtils.convertBytesToHex(key);
 
@@ -288,7 +293,7 @@ public class MongoPersistenceManager ext
         if (bucketObject != null) {
             if (BINARY_FORMAT) {
                 byte[] bytes = (byte[]) bucketObject.get(DATA_FIELD);
-                return Serializer.fromBytes(id, bytes, ChildNodeEntriesBucket.class);
+                return ChildNodeEntriesBucket.deserialize(id, new BinaryBinding(new ByteArrayInputStream(bytes)));
             } else {
                 ChildNodeEntriesBucket bucket = new ChildNodeEntriesBucket();
                 for (String name : bucketObject.keySet()) {
@@ -305,7 +310,9 @@ public class MongoPersistenceManager ext
 
     @Override
     protected String writeCNEBucket(ChildNodeEntriesBucket bucket) throws Exception {
-        byte[] bytes = Serializer.toBytes(bucket);
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        bucket.serialize(new BinaryBinding(out));
+        byte[] bytes = out.toByteArray();
         byte[] key = idFactory.createBucketId(bucket, bytes);
         String id = StringUtils.convertBytesToHex(key);
 

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/AbstractRangeIterator.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/AbstractRangeIterator.java?rev=1238674&r1=1238673&r2=1238674&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/AbstractRangeIterator.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/AbstractRangeIterator.java
Tue Jan 31 15:52:33 2012
@@ -25,22 +25,22 @@ import java.util.NoSuchElementException;
 public abstract class AbstractRangeIterator<T> implements Iterator<T> {
 
     protected final Iterator<?> it;
-    protected int count;
+    protected int maxCount;
 
     public AbstractRangeIterator(Iterator<?> it, int offset, int count) {
         while (offset-- > 0 && it.hasNext()) {
             it.next();
         }
-        this.count = count;
+        maxCount = count < 0 ? Integer.MAX_VALUE : count;
         this.it = it;
     }
 
     public boolean hasNext() {
-        return (count > 0 && it.hasNext());
+        return (maxCount > 0 && it.hasNext());
     }
 
     public T next() {
-        if (count-- > 0) {
+        if (maxCount-- > 0) {
             return doNext();
         }
         throw new NoSuchElementException();



Mime
View raw message