jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r594699 - in /jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp: journal/ByteBufferInputStream.java journal/FileJournal.java tree/ tree/Leaf.java tree/Tree.java tree/TreeFactory.java
Date Tue, 13 Nov 2007 23:12:11 GMT
Author: jukka
Date: Tue Nov 13 15:12:08 2007
New Revision: 594699

URL: http://svn.apache.org/viewvc?rev=594699&view=rev
Log:
NGP: Implemented a tree structure on top of journal records

Added:
    jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/tree/
    jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/tree/Leaf.java
  (with props)
    jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/tree/Tree.java
  (with props)
    jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/tree/TreeFactory.java
  (with props)
Modified:
    jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/journal/ByteBufferInputStream.java
    jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/journal/FileJournal.java

Modified: jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/journal/ByteBufferInputStream.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/journal/ByteBufferInputStream.java?rev=594699&r1=594698&r2=594699&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/journal/ByteBufferInputStream.java
(original)
+++ jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/journal/ByteBufferInputStream.java
Tue Nov 13 15:12:08 2007
@@ -20,7 +20,7 @@
 import java.io.InputStream;
 import java.nio.ByteBuffer;
 
-class ByteBufferInputStream extends InputStream {
+public class ByteBufferInputStream extends InputStream {
 
     private final ByteBuffer buffer;
 

Modified: jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/journal/FileJournal.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/journal/FileJournal.java?rev=594699&r1=594698&r2=594699&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/journal/FileJournal.java
(original)
+++ jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/journal/FileJournal.java
Tue Nov 13 15:12:08 2007
@@ -90,7 +90,7 @@
             int n = stream.read(buffer, length, buffer.length - length);
             if (n != -1) {
                 length += n;
-            } else if (length < 8) {
+            } else if (length <= 6) {
                 return SmallRecord.getIdentifier(buffer, length);
             } else if (length < 0xffff) {
                 return addRecord(buffer, length);

Added: jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/tree/Leaf.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/tree/Leaf.java?rev=594699&view=auto
==============================================================================
--- jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/tree/Leaf.java
(added)
+++ jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/tree/Leaf.java
Tue Nov 13 15:12:08 2007
@@ -0,0 +1,40 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.ngp.tree;
+
+import org.apache.jackrabbit.ngp.journal.Record;
+
+public class Leaf {
+
+    private final Record key;
+
+    private final Record value;
+
+    public Leaf(Record key, Record value) {
+        this.key = key;
+        this.value = value;
+    }
+
+    public Record getKey() {
+        return key;
+    }
+
+    public Record getValue() {
+        return value;
+    }
+
+}

Propchange: jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/tree/Leaf.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/tree/Tree.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/tree/Tree.java?rev=594699&view=auto
==============================================================================
--- jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/tree/Tree.java
(added)
+++ jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/tree/Tree.java
Tue Nov 13 15:12:08 2007
@@ -0,0 +1,88 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.ngp.tree;
+
+import java.nio.ByteBuffer;
+import java.nio.LongBuffer;
+
+import javax.jcr.RepositoryException;
+
+import org.apache.jackrabbit.ngp.journal.Journal;
+import org.apache.jackrabbit.ngp.journal.Record;
+
+public class Tree {
+
+    private final Journal journal;
+
+    private final Record name;
+
+    private final Record record;
+
+    private final LongBuffer leaves;
+
+    private final LongBuffer subTrees;
+
+    public Tree(Journal journal, long name, Record record)
+            throws RepositoryException {
+        this.journal = journal;
+        this.name = journal.getRecord(name);
+        this.record = record;
+
+        ByteBuffer buffer = record.getBuffer();
+        int p = buffer.getInt();
+        int q = buffer.getInt();
+        if (p < 0 || q < 0 || 8 + (p + q) * 16 != record.getLength()) {
+            throw new RepositoryException("Invalid tree record");
+        }
+
+        buffer.limit(buffer.position() + p * 16);
+        this.leaves = buffer.asLongBuffer();
+
+        buffer.position(buffer.limit());
+        buffer.limit(buffer.position() + q * 16);
+        this.subTrees = buffer.asLongBuffer();
+    }
+
+    public Record getName() {
+        return name;
+    }
+
+    Record getRecord() {
+        return record;
+    }
+
+    public Leaf[] getLeaves() throws RepositoryException {
+        Leaf[] array = new Leaf[leaves.remaining() / 2];
+        for (int i = 0; i < array.length; i++) {
+            Record name = journal.getRecord(leaves.get(i * 2));
+            Record value = journal.getRecord(leaves.get(i * 2 + 1));
+            array[i] = new Leaf(name, value);
+        }
+        return array;
+    }
+
+    public Tree[] getSubTrees() throws RepositoryException {
+        Tree[] array = new Tree[subTrees.remaining() / 2];
+        for (int i = 0; i < array.length; i++) {
+            long name = subTrees.get(i * 2);
+            Record record = journal.getRecord(subTrees.get(i * 2 + 1));
+            array[i] = new Tree(journal, name, record);
+        }
+        return array;
+    }
+
+}

Propchange: jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/tree/Tree.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/tree/TreeFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/tree/TreeFactory.java?rev=594699&view=auto
==============================================================================
--- jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/tree/TreeFactory.java
(added)
+++ jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/tree/TreeFactory.java
Tue Nov 13 15:12:08 2007
@@ -0,0 +1,81 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.ngp.tree;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.jcr.RepositoryException;
+
+import org.apache.jackrabbit.ngp.journal.ByteBufferInputStream;
+import org.apache.jackrabbit.ngp.journal.Journal;
+import org.apache.jackrabbit.ngp.journal.Record;
+
+public class TreeFactory {
+
+    private final Journal journal;
+
+    private final long name;
+
+    private final List leaves = new ArrayList();
+
+    private final List subTrees = new ArrayList();
+
+    public TreeFactory(Journal journal, long name) {
+        this.journal = journal;
+        this.name = name;
+    }
+
+    public void addLeaf(Record name, Record value) {
+        leaves.add(new Leaf(name, value));
+    }
+
+    public void addSubTree(Tree subTree) {
+        subTrees.add(subTree);
+    }
+
+    public Tree createTree() throws RepositoryException {
+        ByteBuffer buffer =
+            ByteBuffer.allocate(8 + (leaves.size() + subTrees.size()) * 16);
+        buffer.putInt(leaves.size());
+        buffer.putInt(subTrees.size());
+        Iterator iterator = leaves.iterator();
+        while (iterator.hasNext()) {
+            Leaf leaf = (Leaf) iterator.next();
+            buffer.putLong(leaf.getKey().getIdentifier());
+            buffer.putLong(leaf.getValue().getIdentifier());
+        }
+        iterator = subTrees.iterator();
+        while (iterator.hasNext()) {
+            Tree subTree = (Tree) iterator.next();
+            buffer.putLong(subTree.getName().getIdentifier());
+            buffer.putLong(subTree.getRecord().getIdentifier());
+        }
+        buffer.flip();
+        try {
+            long identifier =
+                journal.addRecord(new ByteBufferInputStream(buffer));
+            return new Tree(journal, name, journal.getRecord(identifier));
+        } catch (IOException e) {
+            throw new RepositoryException("Unable to create a tree record", e);
+        }
+    }
+
+}

Propchange: jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/tree/TreeFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message