jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1002606 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util: BundleBinding.java ItemStateBinding.java
Date Wed, 29 Sep 2010 13:12:51 GMT
Author: jukka
Date: Wed Sep 29 13:12:51 2010
New Revision: 1002606

URL: http://svn.apache.org/viewvc?rev=1002606&view=rev
Log:
JCR-2762: Optimize bundle serialization

Remove duplicate code in ItemStateBinding by merging readID to readNodeId and writeID to writeNodeId.

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleBinding.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/ItemStateBinding.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleBinding.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleBinding.java?rev=1002606&r1=1002605&r2=1002606&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleBinding.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleBinding.java
Wed Sep 29 13:12:51 2010
@@ -92,7 +92,7 @@ public class BundleBinding extends ItemS
         bundle.setNodeTypeName(nodeTypeName);
 
         // parentUUID
-        bundle.setParentId(readID(in));
+        bundle.setParentId(readNodeId(in));
 
         // definitionId
         in.readUTF();
@@ -127,10 +127,10 @@ public class BundleBinding extends ItemS
         bundle.setReferenceable(in.readBoolean());
 
         // child nodes (list of uuid/name pairs)
-        NodeId childId = readID(in);
+        NodeId childId = readNodeId(in);
         while (childId != null) {
             bundle.addChildNodeEntry(readQName(in), childId);
-            childId = readID(in);
+            childId = readNodeId(in);
         }
 
         // read modcount, since version 1.0
@@ -142,10 +142,10 @@ public class BundleBinding extends ItemS
         Set<NodeId> sharedSet = new HashSet<NodeId>();
         if (version >= VERSION_2) {
             // shared set (list of parent uuids)
-            NodeId parentId = readID(in);
+            NodeId parentId = readNodeId(in);
             while (parentId != null) {
                 sharedSet.add(parentId);
-                parentId = readID(in);
+                parentId = readNodeId(in);
             }
         }
         bundle.setSharedSet(sharedSet);
@@ -181,7 +181,7 @@ public class BundleBinding extends ItemS
             return false;
         }
         try {
-            NodeId parentId = readID(in);
+            NodeId parentId = readNodeId(in);
             log.debug("ParentUUID: " + parentId);
         } catch (IOException e) {
             log.error("Error while reading ParentUUID: " + e);
@@ -225,11 +225,11 @@ public class BundleBinding extends ItemS
             return false;
         }
         try {
-            NodeId cneId = readID(in);
+            NodeId cneId = readNodeId(in);
             while (cneId != null) {
                 Name cneName = readQName(in);
                 log.debug("ChildNodentry: " + cneId + ":" + cneName);
-                cneId = readID(in);
+                cneId = readNodeId(in);
             }
         } catch (IOException e) {
             log.error("Error while reading child node entry: " + e);
@@ -265,7 +265,7 @@ public class BundleBinding extends ItemS
         out.writeInt(nameIndex.stringToIndex(bundle.getNodeTypeName().getLocalName()));
 
         // parentUUID
-        writeID(out, bundle.getParentId());
+        writeNodeId(out, bundle.getParentId());
 
         // definitionId
         out.writeUTF("");
@@ -299,19 +299,19 @@ public class BundleBinding extends ItemS
 
         // child nodes (list of uuid/name pairs)
         for (NodePropBundle.ChildNodeEntry entry : bundle.getChildNodeEntries()) {
-            writeID(out, entry.getId());  // uuid
+            writeNodeId(out, entry.getId());  // uuid
             writeQName(out, entry.getName());   // name
         }
-        writeID(out, null);
+        writeNodeId(out, null);
 
         // write mod count
         writeModCount(out, bundle.getModCount());
 
         // write shared set
         for (NodeId nodeId: bundle.getSharedSet()) {
-            writeID(out, nodeId);
+            writeNodeId(out, nodeId);
         }
-        writeID(out, null);
+        writeNodeId(out, null);
 
         // set size of bundle
         bundle.setSize(out.size() - size);
@@ -390,10 +390,10 @@ public class BundleBinding extends ItemS
                     val = InternalValue.create(readQName(in));
                     break;
                 case PropertyType.WEAKREFERENCE:
-                    val = InternalValue.create(readID(in), true);
+                    val = InternalValue.create(readNodeId(in), true);
                     break;
                 case PropertyType.REFERENCE:
-                    val = InternalValue.create(readID(in), false);
+                    val = InternalValue.create(readNodeId(in), false);
                     break;
                 default:
                     // because writeUTF(String) has a size limit of 64k,
@@ -544,7 +544,7 @@ public class BundleBinding extends ItemS
                 case PropertyType.WEAKREFERENCE:
                 case PropertyType.REFERENCE:
                     try {
-                        NodeId id = readID(in);
+                        NodeId id = readNodeId(in);
                         log.debug("  reference: " + id);
                     } catch (IOException e) {
                         log.error("Error while reading reference value: " + e);
@@ -717,7 +717,7 @@ public class BundleBinding extends ItemS
                     break;
                 case PropertyType.WEAKREFERENCE:
                 case PropertyType.REFERENCE:
-                    writeID(out, val.getNodeId());
+                    writeNodeId(out, val.getNodeId());
                     break;
                 default:
                     // because writeUTF(String) has a size limit of 64k,

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/ItemStateBinding.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/ItemStateBinding.java?rev=1002606&r1=1002605&r2=1002606&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/ItemStateBinding.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/ItemStateBinding.java
Wed Sep 29 13:12:51 2010
@@ -155,7 +155,7 @@ public class ItemStateBinding {
         state.setNodeTypeName(NameFactoryImpl.getInstance().create(uri, local));
 
         // parentUUID
-        state.setParentId(readID(in));
+        state.setParentId(readNodeId(in));
         // definitionId
         in.readUTF();
 
@@ -177,7 +177,7 @@ public class ItemStateBinding {
         count = in.readInt();   // count
         for (int i = 0; i < count; i++) {
             Name name = readQName(in);
-            NodeId parentId = readID(in);
+            NodeId parentId = readNodeId(in);
             state.addChildNodeEntry(name, parentId);
         }
 
@@ -188,7 +188,7 @@ public class ItemStateBinding {
             // shared set (list of parent uuids)
             count = in.readInt();   // count
             for (int i = 0; i < count; i++) {
-                state.addShare(readID(in));
+                state.addShare(readNodeId(in));
             }
         }
         return state;
@@ -207,7 +207,7 @@ public class ItemStateBinding {
         out.writeInt((VERSION_CURRENT << 24) | nsIndex.stringToIndex(state.getNodeTypeName().getNamespaceURI()));
         out.writeUTF(state.getNodeTypeName().getLocalName());
         // parentUUID
-        writeID(out, state.getParentId());
+        writeNodeId(out, state.getParentId());
         // definitionId
         out.writeUTF("");
         // mixin types
@@ -229,7 +229,7 @@ public class ItemStateBinding {
         for (Iterator<ChildNodeEntry> iter = collChild.iterator(); iter.hasNext();)
{
             ChildNodeEntry entry = iter.next();
             writeQName(out, entry.getName());   // name
-            writeID(out, entry.getId());  // uuid
+            writeNodeId(out, entry.getId());  // uuid
         }
         writeModCount(out, state.getModCount());
         
@@ -237,7 +237,7 @@ public class ItemStateBinding {
         Collection<NodeId> collShared = state.getSharedSet();
         out.writeInt(collShared.size()); // count
         for (Iterator<NodeId> iter = collShared.iterator(); iter.hasNext();) {
-            writeID(out, iter.next());
+            writeNodeId(out, iter.next());
         }
     }
 
@@ -263,12 +263,12 @@ public class ItemStateBinding {
      * @param id the node id
      * @throws IOException in an I/O error occurs.
      */
-    public void writeNodeId(DataOutputStream out, String id) throws IOException {
+    public void writeNodeId(DataOutputStream out, NodeId id) throws IOException {
         if (id == null) {
             out.writeBoolean(false);
         } else {
             out.writeBoolean(true);
-            out.write(new NodeId(id).getRawBytes());
+            out.write(id.getRawBytes());
         }
     }
 
@@ -304,40 +304,6 @@ public class ItemStateBinding {
     }
 
     /**
-     * Deserializes a NodeID
-     * @param in the input stream
-     * @return the uuid
-     * @throws IOException in an I/O error occurs.
-     */
-    public NodeId readID(DataInputStream in) throws IOException {
-        if (in.readBoolean()) {
-            byte[] bytes = new byte[16];
-            int pos = 0;
-            while (pos < 16) {
-                pos += in.read(bytes, pos, 16 - pos);
-            }
-            return new NodeId(bytes);
-        } else {
-            return null;
-        }
-    }
-
-    /**
-     * Serializes a node id
-     * @param out the output stream
-     * @param id the id
-     * @throws IOException in an I/O error occurs.
-     */
-    public void writeID(DataOutputStream out, NodeId id) throws IOException {
-        if (id == null) {
-            out.writeBoolean(false);
-        } else {
-            out.writeBoolean(true);
-            out.write(id.getRawBytes());
-        }
-    }
-
-    /**
      * Deserializes a Name
      * @param in the input stream
      * @return the qname
@@ -419,7 +385,7 @@ public class ItemStateBinding {
      * @throws IOException in an I/O error occurs.
      */
     public void writePropertyId(DataOutputStream out, PropertyId id) throws IOException {
-        writeID(out, id.getParentId());
+        writeNodeId(out, id.getParentId());
         writeQName(out, id.getName());
     }
 



Mime
View raw message