You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by st...@apache.org on 2011/04/18 18:03:26 UTC
svn commit: r1094632 - in
/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk:
Repository.java store/CommitBuilder.java store/MutableNode.java
Author: stefan
Date: Mon Apr 18 16:03:26 2011
New Revision: 1094632
URL: http://svn.apache.org/viewvc?rev=1094632&view=rev
Log:
MicroKernel prototype (WIP)
Added:
jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/CommitBuilder.java
Modified:
jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/Repository.java
jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/MutableNode.java
Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/Repository.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/Repository.java?rev=1094632&r1=1094631&r2=1094632&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/Repository.java (original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/Repository.java Mon Apr 18 16:03:26 2011
@@ -17,6 +17,7 @@
package org.apache.jackrabbit.mk;
import org.apache.jackrabbit.mk.store.Commit;
+import org.apache.jackrabbit.mk.store.CommitBuilder;
import org.apache.jackrabbit.mk.store.MutableCommit;
import org.apache.jackrabbit.mk.store.MutableNode;
import org.apache.jackrabbit.mk.store.Node;
@@ -59,13 +60,12 @@ public class Repository {
initialized = false;
}
- public Node getNode(String revId, String path) throws Exception {
+ public ObjectStore getStore() {
if (!initialized) {
throw new IllegalStateException("not initialized");
}
- String[] ids = resolvePath(revId, path);
- return store.getNode(ids[ids.length - 1]);
+ return store;
}
public String getHeadRevision() throws Exception {
@@ -75,6 +75,20 @@ public class Repository {
return store.getHeadCommit().getId();
}
+ public Node getNode(String revId, String path) throws Exception {
+ if (!initialized) {
+ throw new IllegalStateException("not initialized");
+ }
+
+ String[] ids = resolvePath(revId, path);
+ return store.getNode(ids[ids.length - 1]);
+ }
+
+ public CommitBuilder getCommitBuilder(String revId) throws Exception {
+ return new CommitBuilder(revId, this);
+
+ }
+
String[] /* array of node id's */ resolvePath(String revId, String path) throws Exception {
if (path == null || path.length() == 0 || path.charAt(0) != '/') {
throw new IllegalArgumentException("illegal path");
Added: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/CommitBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/CommitBuilder.java?rev=1094632&view=auto
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/CommitBuilder.java (added)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/CommitBuilder.java Mon Apr 18 16:03:26 2011
@@ -0,0 +1,112 @@
+/*
+ * 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.mk.store;
+
+import org.apache.jackrabbit.mk.Repository;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ *
+ */
+public class CommitBuilder {
+
+ final String baseRevId;
+ final String rootNodeId;
+
+ final Repository rep;
+ final ObjectStore store;
+
+ final Map<String, MutableNode> staged;
+
+ public CommitBuilder(String baseRevId, Repository rep) throws Exception {
+ this.baseRevId = baseRevId;
+ this.rep = rep;
+ store = rep.getStore();
+ rootNodeId = store.getCommit(baseRevId).getRootNodeId();
+ staged = new HashMap<String, MutableNode>();
+ }
+
+ public void addNode(String parentNodePath, String nodeName) throws Exception {
+ addNode(parentNodePath, nodeName, Collections.<String, String>emptyMap());
+ }
+
+ public void addNode(String parentNodePath, String nodeName, Map<String, String> properties) throws Exception {
+ String parentIds[] = resolvePath(baseRevId, parentNodePath);
+
+ Node parent = rep.getNode(baseRevId, parentNodePath);
+ MutableNode modParent;
+ if (!staged.containsKey(parent.getId())) {
+ modParent = new MutableNode(baseRevId, parent);
+ staged.put(parent.getId(), modParent);
+ } else {
+ modParent = staged.get(parent.getId());
+ }
+ if (modParent.getChildNodeEntries().containsKey(nodeName)) {
+ throw new Exception("there's already a child node with name '" + nodeName + "'");
+ }
+ MutableNode newChild = new MutableNode(baseRevId);
+ newChild.getProperties().putAll(properties);
+
+ String newId = rep.getStore().computeId(newChild.toBytes());
+ staged.put(newId, newChild);
+
+ modParent.getChildNodeEntries().put(nodeName, newId);
+ }
+
+ public void removeNode(String nodePath) throws Exception {
+
+ }
+
+ public void setProperty(String nodePath, String propName, String propValue) throws Exception {
+
+ }
+
+ public void setProperties(String nodePath, Map<String, String> properties) throws Exception {
+
+ }
+
+ public String /* new revId */ doCommit() throws Exception {
+ // todo implement
+ return null;
+ }
+
+
+ String[] /* array of node id's */ resolvePath(String revId, String path) throws Exception {
+ if (path == null || path.length() == 0 || path.charAt(0) != '/') {
+ throw new IllegalArgumentException("illegal path");
+ }
+
+ Commit commit = store.getCommit(revId);
+
+ String[] names = path.split("/");
+ String[] ids = new String[names.length + 1];
+
+ // get root node
+ ids[0] = commit.getRootNodeId();
+ Node parent = store.getNode(ids[0]);
+ // traverse path and store id of each element
+ for (int i = 1; i <= names.length; i++) {
+ ids[i] = parent.getChildNodeEntries().get(names[i]);
+ parent = store.getNode(ids[i]);
+ }
+ return ids;
+ }
+
+}
Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/MutableNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/MutableNode.java?rev=1094632&r1=1094631&r2=1094632&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/MutableNode.java (original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/MutableNode.java Mon Apr 18 16:03:26 2011
@@ -61,7 +61,7 @@ public class MutableNode {
*
* @return
*/
- public Map<String, String> getChildEntries() {
+ public Map<String, String> getChildNodeEntries() {
return childEntries;
}