jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1444216 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment: JcrImporter.java SegmentWriter.java
Date Fri, 08 Feb 2013 20:23:47 GMT
Author: jukka
Date: Fri Feb  8 20:23:47 2013
New Revision: 1444216

URL: http://svn.apache.org/r1444216
Log:
OAK-593: Segment-based MK

Simple JCR importer

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/JcrImporter.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentWriter.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/JcrImporter.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/JcrImporter.java?rev=1444216&r1=1444215&r2=1444216&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/JcrImporter.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/JcrImporter.java
Fri Feb  8 20:23:47 2013
@@ -16,23 +16,18 @@
  */
 package org.apache.jackrabbit.oak.plugins.segment;
 
-import java.io.IOException;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.Arrays;
 
-import javax.jcr.Binary;
 import javax.jcr.Node;
 import javax.jcr.NodeIterator;
 import javax.jcr.Property;
 import javax.jcr.PropertyIterator;
-import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
-import javax.jcr.Value;
 
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
+import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeBuilder;
+import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeState;
+import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
+import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 
 public class JcrImporter {
 
@@ -42,19 +37,32 @@ public class JcrImporter {
         this.writer = writer;
     }
 
-    public RecordId writeValue(Value value) throws RepositoryException {
-        if (value.getType() == PropertyType.BINARY) {
-            Binary binary = value.getBinary();
-            try {
-                return writer.writeStream(binary.getStream());
-            } catch (IOException e) {
-                throw new RepositoryException(
-                        "Can not read a binary stream from the repository", e);
-            } finally {
-                binary.dispose();
+    public RecordId writeNode(Node node) throws RepositoryException {
+        NodeBuilder builder =
+                new MemoryNodeBuilder(MemoryNodeState.EMPTY_NODE);
+        buildNode(builder, node);
+        return writer.writeNode(builder.getNodeState());
+    }
+
+    private void buildNode(NodeBuilder builder, Node node)
+            throws RepositoryException {
+        PropertyIterator properties = node.getProperties();
+        while (properties.hasNext()) {
+            Property property = properties.nextProperty();
+            if (property.isMultiple()) {
+                builder.setProperty(PropertyStates.createProperty(
+                        property.getName(),
+                        Arrays.asList(property.getValues())));
+            } else {
+                builder.setProperty(PropertyStates.createProperty(
+                        property.getName(), property.getValue()));
             }
-        } else {
-            return writer.writeString(value.getString());
+        }
+
+        NodeIterator childNodes = node.getNodes();
+        while (childNodes.hasNext()) {
+            Node childNode = childNodes.nextNode();
+            buildNode(builder.child(childNode.getName()), childNode);
         }
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentWriter.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentWriter.java?rev=1444216&r1=1444215&r2=1444216&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentWriter.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentWriter.java
Fri Feb  8 20:23:47 2013
@@ -171,8 +171,25 @@ public class SegmentWriter {
             if (diff == 0) {
                 diff = key.compareTo(that.key);
             }
+            if (diff == 0) {
+                diff = value.compareTo(that.value);
+            }
             return diff;
         }
+
+        public boolean equals(Object object) {
+            if (this == object) {
+                return true;
+            } else if (object instanceof MapEntry) {
+                MapEntry that = (MapEntry) object;
+                return hashCode == that.hashCode
+                        && key.equals(that.key)
+                        && value.equals(that.value);
+            } else {
+                return false;
+            }
+        }
+
     }
 
     private synchronized RecordId writeMapBucket(



Mime
View raw message