jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1133863 - in /jackrabbit/sandbox/spi2microkernel/src: main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java
Date Thu, 09 Jun 2011 13:25:10 GMT
Author: mduerig
Date: Thu Jun  9 13:25:10 2011
New Revision: 1133863

URL: http://svn.apache.org/viewvc?rev=1133863&view=rev
Log:
spi2microkernel prototype (WIP)
write support: remove (hacking the hacks....)

Modified:
    jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
    jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java

Modified: jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java?rev=1133863&r1=1133862&r2=1133863&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
Thu Jun  9 13:25:10 2011
@@ -55,7 +55,6 @@ import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
 import javax.jcr.UnsupportedRepositoryOperationException;
 import java.io.IOException;
-import java.io.StringWriter;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
@@ -371,7 +370,7 @@ public class RepositoryServiceImpl exten
 
     private class CommitBuilder implements Batch {
         private final SessionInfo sessionInfo;
-        private final StringBuilder sb = new StringBuilder();
+        private final StringBuilder jsop = new StringBuilder();
 
         public CommitBuilder(SessionInfo sessionInfo) {
             this.sessionInfo = sessionInfo;
@@ -379,12 +378,12 @@ public class RepositoryServiceImpl exten
 
         public void addNode(NodeId parentId, Name nodeName, Name nodetypeName, String uuid)
throws RepositoryException {
             try {
-                StringWriter sw = new StringWriter();
-                JsonBuilder.create(sw)
+                StringBuilder sb = new StringBuilder();
+                JsonBuilder.create(sb)
                     .value(Paths.translateQName(NameConstants.JCR_PRIMARYTYPE), Paths.translateQName(nodetypeName))
                     .build();
 
-                sb.append('+').append(target(parentId, nodeName)).append(" : ").append(sw.toString()).append('\n');
+                jsop.append('+').append(target(parentId, nodeName)).append(" : ").append(sb.toString()).append('\n');
             }
             catch (IOException e) {
                 throw new RepositoryException(e);
@@ -392,24 +391,35 @@ public class RepositoryServiceImpl exten
         }
 
         public void addProperty(NodeId parentId, Name propertyName, QValue value) throws
RepositoryException {
-            addProperty(parentId, propertyName, Values.create(value));
+            setProperty(parentId, propertyName, Values.create(value));
         }
 
         public void addProperty(NodeId parentId, Name propertyName, QValue[] values) throws
RepositoryException {
-            addProperty(parentId, propertyName, Values.create(values));
+            setProperty(parentId, propertyName, Values.create(values));
         }
 
         public void setValue(PropertyId propertyId, QValue value) throws RepositoryException
{
-            addProperty(propertyId.getParentId(), propertyId.getName(), Values.create(value));
+            setProperty(propertyId.getParentId(), propertyId.getName(), Values.create(value));
         }
 
         public void setValue(PropertyId propertyId, QValue[] values) throws RepositoryException
{
-            addProperty(propertyId.getParentId(), propertyId.getName(), Values.create(values));
+            setProperty(propertyId.getParentId(), propertyId.getName(), Values.create(values));
         }
 
         public void remove(ItemId itemId) throws RepositoryException {
-            // todo implement remove
-            throw new UnsupportedRepositoryOperationException("remove");
+            if (itemId.denotesNode()) {
+                NodeId nodeId = (NodeId) itemId;
+                if (nodeId.getPath().denotesRoot()) {
+                    throw new RepositoryException("Cannot remove root node");
+                }
+
+                String path = target(nodeId);
+                jsop.append('-').append(path).append(" : \n");
+            }
+            else {
+                PropertyId propertyId = (PropertyId) itemId;
+                setProperty(propertyId.getParentId(), propertyId.getName(), "null");
+            }
         }
 
         public void reorderNodes(NodeId parentId, NodeId srcNodeId, NodeId beforeNodeId)
throws RepositoryException {
@@ -434,18 +444,23 @@ public class RepositoryServiceImpl exten
 
         public void commit() throws RepositoryException {
             String rev = getRevision(sessionInfo);
-            rev = microKernel.commit("/", sb.toString(), rev);
+            jsop.deleteCharAt(jsop.length() - 1); // remove training new line. DiffParser
messes up otherwise
+            rev = microKernel.commit("/", jsop.toString(), rev);
             setRevision(sessionInfo, rev);
         }
 
+        private String target(NodeId nodeId) throws RepositoryException {
+            return PathUtil.relativize("/", Paths.translateQPath(sessionInfo.getWorkspaceName(),
nodeId.getPath()));   
+        }
+
         private String target(NodeId parentId, Name itemName) throws RepositoryException
{
             String path = Paths.translateQPath(sessionInfo.getWorkspaceName(), parentId.getPath());
             String name = Paths.translateQName(itemName);
             return PathUtil.concat(PathUtil.relativize("/", path), name);
         }
 
-        private void addProperty(NodeId parentId, Name propertyName, String jsonValue) throws
RepositoryException {
-            sb.append('^').append(target(parentId, propertyName)).append(" : ").append(jsonValue);
+        private void setProperty(NodeId parentId, Name propertyName, String jsonValue) throws
RepositoryException {
+            jsop.append('^').append(target(parentId, propertyName)).append(" : ").append(jsonValue).append('\n');
         }
     }
 

Modified: jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java?rev=1133863&r1=1133862&r2=1133863&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java
Thu Jun  9 13:25:10 2011
@@ -333,7 +333,54 @@ public class RepositoryTest {
         }
     }
 
-    @Ignore  // todo implement in RepositoryService
+    @Test
+    public void nullProperty() throws RepositoryException {
+        Node parentNode = getNode(testPath);
+        parentNode.setProperty("newProperty", "some value");
+        parentNode.getSession().save();
+
+        Session session2 = getRepository().login();
+        try {
+            session2.getProperty(testPath + "/newProperty").setValue((String) null);
+            session2.save();
+        }
+        finally {
+            session2.logout();
+        }
+
+        Session session3 = getRepository().login();
+        try {
+            assertFalse(session3.propertyExists(testPath + "/newProperty"));
+        }
+        finally {
+            session3.logout();
+        }
+    }
+
+    @Test
+    public void removeProperty() throws RepositoryException {
+        Node parentNode = getNode(testPath);
+        parentNode.setProperty("newProperty", "some value");
+        parentNode.getSession().save();
+
+        Session session2 = getRepository().login();
+        try {
+            session2.getProperty(testPath + "/newProperty").remove();
+            session2.save();
+        }
+        finally {
+            session2.logout();
+        }
+
+        Session session3 = getRepository().login();
+        try {
+            assertFalse(session3.propertyExists(testPath + "/newProperty"));
+        }
+        finally {
+            session3.logout();
+        }
+    }
+
     @Test
     public void removeNode() throws RepositoryException {
         Node parentNode = getNode(testPath);
@@ -341,9 +388,21 @@ public class RepositoryTest {
         parentNode.getSession().save();
 
         Session session2 = getRepository().login();
-        session2.getNode(testPath + "/newNode").remove();
-        session2.save();
-        session2.logout();
+        try {
+            session2.getNode(testPath + "/newNode").remove();
+            session2.save();
+        }
+        finally {
+            session2.logout();
+        }
+
+        Session session3 = getRepository().login();
+        try {
+            assertFalse(session3.nodeExists(testPath + "/newNode"));
+        }
+        finally {
+            session3.logout();
+        }
     }
 
     //------------------------------------------< private >---



Mime
View raw message