jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r923927 - in /jackrabbit/sandbox/jackrabbit-j3/src: main/java/org/apache/jackrabbit/j3/ main/java/org/apache/jackrabbit/j3/mc/ main/java/org/apache/jackrabbit/j3/mc/jdbc/ main/java/org/apache/jackrabbit/j3/mc/mem/ test/java/org/apache/jackr...
Date Tue, 16 Mar 2010 18:37:10 GMT
Author: thomasm
Date: Tue Mar 16 18:37:09 2010
New Revision: 923927

URL: http://svn.apache.org/viewvc?rev=923927&view=rev
Log:
Some code for a Jackrabbit 3 prototype

Modified:
    jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/Change.java
    jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/NodeImpl.java
    jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/NodeState.java
    jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/PropertyImpl.java
    jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/SessionImpl.java
    jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/mc/NodeData.java
    jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/mc/jdbc/JdbcStorageSession.java
    jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/mc/mem/MemStorageSession.java
    jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestSimple.java

Modified: jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/Change.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/Change.java?rev=923927&r1=923926&r2=923927&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/Change.java (original)
+++ jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/Change.java Tue
Mar 16 18:37:09 2010
@@ -28,4 +28,14 @@ class ChangeSetProperty implements Chang
         node.doSetProperty(propertyName, value);
     }
 
+}
+
+class ChangeRemoveNode implements Change {
+    NodeImpl node;
+
+    public void apply(SessionImpl session) {
+        // TODO remove all child nodes as well (maybe as a background process)
+        node.doRemove();
+    }
+
 }
\ No newline at end of file

Modified: jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/NodeImpl.java?rev=923927&r1=923926&r2=923927&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/NodeImpl.java
(original)
+++ jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/NodeImpl.java
Tue Mar 16 18:37:09 2010
@@ -120,6 +120,10 @@ public class NodeImpl implements Node {
         return new ValueImpl(state.getPropertyValue(name));
     }
 
+    Val getPropertyVal(Val name) {
+        return state.getPropertyValue(name);
+    }
+
     public NodeImpl getParent() throws ItemNotFoundException, AccessDeniedException, RepositoryException
{
         return parent;
     }
@@ -158,6 +162,10 @@ public class NodeImpl implements Node {
     }
 
     public Node getNode(String relPath) throws PathNotFoundException, RepositoryException
{
+        return getNodeImpl(relPath);
+    }
+
+    NodeImpl getNodeImpl(String relPath) throws PathNotFoundException, RepositoryException
{
         Val childName = Val.get(relPath);
         Val childId = state.getNodeData().getChildId(childName);
         if (childId == null) {
@@ -167,9 +175,36 @@ public class NodeImpl implements Node {
     }
 
     public String getName() throws RepositoryException {
+        if (parent == null) {
+            return "/";
+        }
         return state.getName(parent.state).getString();
     }
 
+    public boolean hasNode(String relPath) throws RepositoryException {
+        Val childName = Val.get(relPath);
+        Val childId = state.getNodeData().getChildId(childName);
+        return childId != null;
+    }
+
+    public void remove() throws VersionException, LockException, ConstraintViolationException,
AccessDeniedException,
+            RepositoryException {
+        ChangeRemoveNode change = new ChangeRemoveNode();
+        SessionImpl s = state.getSession();
+        if (parent == null) {
+            throw new RepositoryException("Can not remove the root node");
+        }
+        synchronized (s) {
+            change.node = this;
+            s.addChange(change);
+        }
+    }
+
+    public void doRemove() {
+        Val name = state.getName(parent.state);
+        getParentNode().state.removeChild(name);
+    }
+
     public void addMixin(String mixinName) throws NoSuchNodeTypeException, VersionException,
             ConstraintViolationException, LockException, RepositoryException {
         // TODO Auto-generated method stub
@@ -323,11 +358,6 @@ public class NodeImpl implements Node {
         return null;
     }
 
-    public boolean hasNode(String relPath) throws RepositoryException {
-        // TODO Auto-generated method stub
-        return false;
-    }
-
     public boolean hasNodes() throws RepositoryException {
         // TODO Auto-generated method stub
         return false;
@@ -578,12 +608,6 @@ public class NodeImpl implements Node {
 
     }
 
-    public void remove() throws VersionException, LockException, ConstraintViolationException,
AccessDeniedException,
-            RepositoryException {
-        // TODO Auto-generated method stub
-
-    }
-
     public void save() throws AccessDeniedException, ItemExistsException, ConstraintViolationException,
             InvalidItemStateException, ReferentialIntegrityException, VersionException, LockException,
             NoSuchNodeTypeException, RepositoryException {

Modified: jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/NodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/NodeState.java?rev=923927&r1=923926&r2=923927&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/NodeState.java
(original)
+++ jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/NodeState.java
Tue Mar 16 18:37:09 2010
@@ -70,6 +70,11 @@ public class NodeState {
         data.addChild(childName, id);
     }
 
+    void removeChild(Val childName) {
+        modify();
+        data.removeChild(childName);
+    }
+
     Val getName(NodeState parent) {
         return data.getName(parent.data);
     }

Modified: jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/PropertyImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/PropertyImpl.java?rev=923927&r1=923926&r2=923927&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/PropertyImpl.java
(original)
+++ jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/PropertyImpl.java
Tue Mar 16 18:37:09 2010
@@ -54,6 +54,10 @@ public class PropertyImpl implements Pro
         return node.getPropertyValue(name);
     }
 
+    public String getString() throws ValueFormatException, RepositoryException {
+        return node.getPropertyVal(name).getString();
+    }
+
     public Binary getBinary() throws ValueFormatException, RepositoryException {
         // TODO Auto-generated method stub
         return null;
@@ -114,11 +118,6 @@ public class PropertyImpl implements Pro
         return null;
     }
 
-    public String getString() throws ValueFormatException, RepositoryException {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
     public int getType() throws RepositoryException {
         // TODO Auto-generated method stub
         return 0;

Modified: jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/SessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/SessionImpl.java?rev=923927&r1=923926&r2=923927&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/SessionImpl.java
(original)
+++ jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/SessionImpl.java
Tue Mar 16 18:37:09 2010
@@ -152,6 +152,7 @@ public class SessionImpl implements Sess
         for (NodeData n : changed) {
             rep.cacheNodeData(n);
         }
+        modified.clear();
     }
 
     public synchronized Node getNodeByIdentifier(String id) throws ItemNotFoundException,
RepositoryException {
@@ -182,6 +183,25 @@ public class SessionImpl implements Sess
         }
     }
 
+    public Node getNode(String absPath) throws PathNotFoundException, RepositoryException
{
+        if (!absPath.startsWith("/")) {
+            throw new RepositoryException("Path does not start with /:" + absPath);
+        }
+        int last = 1;
+        NodeImpl current = getNode(null, storageSession.getRootNodeId());;
+        for (int i=1; i<absPath.length(); i++) {
+            char c = absPath.charAt(i);
+            if (c == '/') {
+                String s = absPath.substring(last, i);
+                current = current.getNodeImpl(s);
+                last = i + 1;
+            }
+        }
+        String s = absPath.substring(last, absPath.length());
+        current = current.getNodeImpl(s);
+        return current;
+    }
+
     public void addLockToken(String lt) {
         // TODO Auto-generated method stub
 
@@ -263,11 +283,6 @@ public class SessionImpl implements Sess
         return null;
     }
 
-    public Node getNode(String absPath) throws PathNotFoundException, RepositoryException
{
-        // TODO Auto-generated method stub
-        return null;
-    }
-
     public Node getNodeByUUID(String uuid) throws ItemNotFoundException, RepositoryException
{
         // TODO Auto-generated method stub
         return null;

Modified: jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/mc/NodeData.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/mc/NodeData.java?rev=923927&r1=923926&r2=923927&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/mc/NodeData.java
(original)
+++ jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/mc/NodeData.java
Tue Mar 16 18:37:09 2010
@@ -20,7 +20,7 @@ public class NodeData {
 
     private final Val id;
     private final Val primaryParentId;
-    private final long version;
+    private long version;
     private Val[] propertyValuePairs;
     private Val[] childNameIdPairs;
     private int cachedParentIndex;
@@ -45,6 +45,10 @@ public class NodeData {
         childNameIdPairs = updatePair(childNameIdPairs, childName, childId);
     }
 
+    public void removeChild(Val childName) {
+        childNameIdPairs = updatePair(childNameIdPairs, childName, null);
+    }
+
     public Val getId() {
         return id;
     }
@@ -239,4 +243,8 @@ public class NodeData {
         return primaryParentId;
     }
 
+    public void incrementVersion() {
+        version++;
+    }
+
 }

Modified: jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/mc/jdbc/JdbcStorageSession.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/mc/jdbc/JdbcStorageSession.java?rev=923927&r1=923926&r2=923927&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/mc/jdbc/JdbcStorageSession.java
(original)
+++ jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/mc/jdbc/JdbcStorageSession.java
Tue Mar 16 18:37:09 2010
@@ -85,14 +85,33 @@ public class JdbcStorageSession implemen
 
     public void save(NodeData[] changed) {
         try {
-            PreparedStatement p = prepare("merge into bundles(id, version, data) values(?,
?, ?)");
+            PreparedStatement insert = prepare("insert into bundles(id, version, data) values(?,
?, ?)");
+            PreparedStatement update = prepare("update bundles set version = ?, data = ?
where id = ?");
             for (NodeData n : changed) {
-                p.setLong(1, n.getId().getLong());
-                p.setLong(2, n.getVersion());
-                bundle.reset();
-                n.writeTo(bundle);
-                p.setBytes(3, bundle.getBytes());
-                p.executeUpdate();
+                try {
+                    if (n.getVersion() == 0) {
+                        n.incrementVersion();
+                        insert.setLong(1, n.getId().getLong());
+                        insert.setLong(2, n.getVersion());
+                        bundle.reset();
+                        n.writeTo(bundle);
+                        insert.setBytes(3, bundle.getBytes());
+                        insert.executeUpdate();
+                    } else {
+                        n.incrementVersion();
+                        update.setLong(3, n.getId().getLong());
+                        update.setLong(1, n.getVersion());
+                        bundle.reset();
+                        n.writeTo(bundle);
+                        update.setBytes(2, bundle.getBytes());
+                        int updateCount = update.executeUpdate();
+                        if (updateCount != 1) {
+                            throw new McException("Update failed, update count is " + updateCount);
+                        }
+                    }
+                } catch (SQLException e) {
+                    throw new McException(e);
+                }
             }
         } catch (SQLException e) {
             throw new McException(e);

Modified: jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/mc/mem/MemStorageSession.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/mc/mem/MemStorageSession.java?rev=923927&r1=923926&r2=923927&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/mc/mem/MemStorageSession.java
(original)
+++ jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/mc/mem/MemStorageSession.java
Tue Mar 16 18:37:09 2010
@@ -47,9 +47,10 @@ public class MemStorageSession implement
     }
 
     public void save(NodeData[] changed) {
-        for (NodeData n : changed) {
-            synchronized (storage) {
+        synchronized (storage) {
+            for (NodeData n : changed) {
                 content.put(n.getId(), n);
+                n.incrementVersion();
             }
         }
     }

Modified: jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestSimple.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestSimple.java?rev=923927&r1=923926&r2=923927&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestSimple.java
(original)
+++ jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestSimple.java
Tue Mar 16 18:37:09 2010
@@ -17,6 +17,7 @@
 package org.apache.jackrabbit.j3;
 
 import javax.jcr.Node;
+import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 
 public class TestSimple extends TestBase {
@@ -40,8 +41,44 @@ public class TestSimple extends TestBase
         assertEquals("Hello", test2.getProperty("name").getValue().getString());
         assertEquals("/test", test.getPath());
         assertEquals("/test", test2.getPath());
+
+        assertTrue(root2.hasNode("test"));
+        root2.getNode("test").remove();
+        assertFalse(root2.hasNode("test"));
+
+        createReadNodes();
+
         session2.logout();
         session.logout();
 
     }
+
+    private void createReadNodes() throws RepositoryException {
+        Node root = session.getRootNode();
+        int max = 10, saveEvery = 1000, count = 0;
+        for(int i=0; i<max; i++) {
+            Node ni = root.addNode("test" + i);
+            for(int j=0; j<max; j++) {
+                Node nj = ni.addNode("test" + j);
+                for(int k=0; k<max; k++) {
+                    Node x = nj.addNode("test" + k);
+                    x.setProperty("value", i + "_" + j + "_" + k);
+                    if (count++ % saveEvery == 0) {
+                        session.save();
+                    }
+                }
+            }
+        }
+        session.save();
+        for(int i=0; i<max; i++) {
+            for(int j=0; j<max; j++) {
+                for(int k=0; k<max; k++) {
+                    String s = "/test" + i + "/test" + j + "/test" + k;
+                    Node x = session.getNode(s);
+                    String v = x.getProperty("value").getString();
+                    assertEquals(i + "_" + j + "_" + k, v);
+                }
+            }
+        }
+    }
 }



Mime
View raw message