jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1132946 - in /jackrabbit/sandbox/spi2microkernel/src: main/java/org/apache/jackrabbit/spi2microkernel/ test/java/org/apache/jackrabbit/spi2microkernel/
Date Tue, 07 Jun 2011 10:22:52 GMT
Author: mduerig
Date: Tue Jun  7 10:22:51 2011
New Revision: 1132946

URL: http://svn.apache.org/viewvc?rev=1132946&view=rev
Log:
spi2microkernel prototype (WIP)
write support: addNode

Added:
    jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java
      - copied, changed from r1132604, jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/Tests.java
Removed:
    jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/Tests.java
Modified:
    jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
    jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/MicrokernelTest.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=1132946&r1=1132945&r2=1132946&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
Tue Jun  7 10:22:51 2011
@@ -21,6 +21,7 @@ package org.apache.jackrabbit.spi2microk
 import org.apache.jackrabbit.mk.MicroKernelImpl;
 import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.mk.api.MicroKernelException;
+import org.apache.jackrabbit.mk.util.PathUtil;
 import org.apache.jackrabbit.spi.Batch;
 import org.apache.jackrabbit.spi.ChildInfo;
 import org.apache.jackrabbit.spi.ItemId;
@@ -37,6 +38,7 @@ import org.apache.jackrabbit.spi.QValue;
 import org.apache.jackrabbit.spi.SessionInfo;
 import org.apache.jackrabbit.spi.commons.AbstractRepositoryService;
 import org.apache.jackrabbit.spi.commons.ItemInfoCacheImpl;
+import org.apache.jackrabbit.spi.commons.batch.ConsolidatingChangeLog;
 import org.apache.jackrabbit.spi2microkernel.util.Json;
 import org.apache.jackrabbit.spi2microkernel.util.JsonHandlerBase;
 import org.apache.jackrabbit.spi2microkernel.util.NodeTypes;
@@ -66,6 +68,7 @@ public class RepositoryServiceImpl exten
 
         put(Repository.NODE_TYPE_MANAGEMENT_SAME_NAME_SIBLINGS_SUPPORTED, FALSE);
         put(Repository.OPTION_WORKSPACE_MANAGEMENT_SUPPORTED, TRUE);
+        put(Repository.LEVEL_2_SUPPORTED, TRUE);
     }};
 
     private static final Map<String, String> NAMESPACES = Collections.emptyMap();
@@ -252,14 +255,15 @@ public class RepositoryServiceImpl exten
 
     @Override
     public Batch createBatch(SessionInfo sessionInfo, ItemId itemId) throws RepositoryException
{
-        // todo implement createBatch
-        throw new UnsupportedRepositoryOperationException();
+        return new ChangeLog(sessionInfo);
     }
 
     @Override
     public void submit(Batch batch) throws RepositoryException {
-        // todo implement submit
-        throw new UnsupportedRepositoryOperationException();
+        ChangeLog changeLog = changeLog(batch);
+        CommitBuilder commitBuilder = new CommitBuilder(changeLog.sessionInfo);
+        changeLog.apply(commitBuilder);
+        commitBuilder.commit();
     }
 
     //------------------------------------------< Workspace management >---
@@ -283,6 +287,15 @@ public class RepositoryServiceImpl exten
 
     //------------------------------------------< private >---
 
+    private static ChangeLog changeLog(Batch batch) throws RepositoryException {
+        if (batch instanceof ChangeLog) {
+            return (ChangeLog) batch;
+        }
+        else {
+            throw new RepositoryException("Invalid batch " + batch);
+        }
+    }
+
     private String getRevision(SessionInfo sessionInfo) throws RepositoryException {
         String rev = sessions.get(sessionInfo);
 
@@ -294,9 +307,13 @@ public class RepositoryServiceImpl exten
         }
     }
 
+    private void setRevision(SessionInfo sessionInfo, String revisionId) {
+        sessions.put(sessionInfo, revisionId);
+    }
+
     private void initSessionInfo(SessionInfo sessionInfo) throws RepositoryException {
         try {
-            sessions.put(sessionInfo, microKernel.getHeadRevision());
+            setRevision(sessionInfo, microKernel.getHeadRevision());
         }
         catch (MicroKernelException e) {
             throw new RepositoryException(e.getMessage(), e);
@@ -340,4 +357,82 @@ public class RepositoryServiceImpl exten
         }
     }
 
+    private class CommitBuilder implements Batch {
+        private final SessionInfo sessionInfo;
+        private final StringBuilder sb = new StringBuilder();
+
+        public CommitBuilder(SessionInfo sessionInfo) {
+            this.sessionInfo = sessionInfo;
+        }
+
+        public void addNode(NodeId parentId, Name nodeName, Name nodetypeName, String uuid)
throws RepositoryException {
+            String wspName = sessionInfo.getWorkspaceName();
+            Path path = parentId.getPath();
+            String mkPath = Paths.translateQPath(wspName, path);
+            mkPath = PathUtil.relativize("/", mkPath);
+            String name = Paths.translateQName(nodeName);
+
+            sb.append('+').append(PathUtil.concat(mkPath, name)).append(" : {}\n");
+        }
+
+        public void addProperty(NodeId parentId, Name propertyName, QValue value) throws
RepositoryException {
+            // todo implement addProperty
+            throw new UnsupportedRepositoryOperationException("addProperty");
+        }
+
+        public void addProperty(NodeId parentId, Name propertyName, QValue[] values) throws
RepositoryException {
+            // todo implement addProperty
+            throw new UnsupportedRepositoryOperationException("addProperty");
+        }
+
+        public void setValue(PropertyId propertyId, QValue value) throws RepositoryException
{
+            // todo implement setValue
+            throw new UnsupportedRepositoryOperationException("setValue");
+        }
+
+        public void setValue(PropertyId propertyId, QValue[] values) throws RepositoryException
{
+            // todo implement setValue
+            throw new UnsupportedRepositoryOperationException("setValue");
+        }
+
+        public void remove(ItemId itemId) throws RepositoryException {
+            // todo implement remove
+            throw new UnsupportedRepositoryOperationException("remove");
+        }
+
+        public void reorderNodes(NodeId parentId, NodeId srcNodeId, NodeId beforeNodeId)
throws RepositoryException {
+            // todo implement reorderNodes
+            throw new UnsupportedRepositoryOperationException("reorderNodes");
+        }
+
+        public void setMixins(NodeId nodeId, Name[] mixinNodeTypeNames) throws RepositoryException
{
+            // todo implement setMixins
+            throw new UnsupportedRepositoryOperationException("setMixin");
+        }
+
+        public void setPrimaryType(NodeId nodeId, Name primaryNodeTypeName) throws RepositoryException
{
+            // todo implement setPrimaryType
+            throw new UnsupportedRepositoryOperationException("setPrimaryType");
+        }
+
+        public void move(NodeId srcNodeId, NodeId destParentNodeId, Name destName) throws
RepositoryException {
+            // todo implement move
+            throw new UnsupportedRepositoryOperationException("move");
+        }
+
+        public void commit() throws RepositoryException {
+            String rev = getRevision(sessionInfo);
+            rev = microKernel.commit("/", sb.toString(), rev);
+            setRevision(sessionInfo, rev);
+        }
+    }
+
+    private static class ChangeLog extends ConsolidatingChangeLog {
+        private final SessionInfo sessionInfo;
+
+        public ChangeLog(SessionInfo sessionInfo) {
+            this.sessionInfo = sessionInfo;
+        }
+    }
+
 }

Modified: jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/MicrokernelTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/MicrokernelTest.java?rev=1132946&r1=1132945&r2=1132946&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/MicrokernelTest.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/MicrokernelTest.java
Tue Jun  7 10:22:51 2011
@@ -35,7 +35,7 @@ import static org.junit.Assert.assertEqu
 import static org.junit.Assert.assertTrue;
 
 public class MicrokernelTest {
-    private static final File REPO_HOME_DIR = new File("target/repository");
+    private static final File REPO_HOME_DIR = new File("target/micro-kernel-test/repository");
 
     private MicroKernelImpl microkernel;
 
@@ -52,7 +52,7 @@ public class MicrokernelTest {
                 "\"multiIntProp\":[1,2,3]} ", head);
         }
     }
-
+    
     @Ignore  // todo fix in microkernel
     @Test
     public void missingName() {

Copied: jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java
(from r1132604, jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/Tests.java)
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java?p2=jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java&p1=jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/Tests.java&r1=1132604&r2=1132946&rev=1132946&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/Tests.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java
Tue Jun  7 10:22:51 2011
@@ -43,8 +43,8 @@ import java.util.Set;
 import static java.util.Arrays.asList;
 import static org.junit.Assert.*;
 
-public class Tests {
-    private static final File REPO_HOME_DIR = new File("target/repository");
+public class RepositoryTest {
+    private static final File REPO_HOME_DIR = new File("target/repository-test/repository");
     
     private Repository repository;
     private Session session;
@@ -200,6 +200,13 @@ public class Tests {
         assertTrue(property.isSame(propertyAgain));
     }
 
+    @Test
+    public void addNode() throws RepositoryException {
+        Node node = getNode("/bar");
+        node.addNode("new");
+        getSession().save();
+    }
+    
     //------------------------------------------< private >---
 
     private Repository getRepository() throws RepositoryException {



Mime
View raw message