Return-Path: Delivered-To: apmail-jackrabbit-commits-archive@www.apache.org Received: (qmail 92518 invoked from network); 18 Apr 2011 16:03:48 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 18 Apr 2011 16:03:48 -0000 Received: (qmail 71359 invoked by uid 500); 18 Apr 2011 16:03:48 -0000 Delivered-To: apmail-jackrabbit-commits-archive@jackrabbit.apache.org Received: (qmail 71328 invoked by uid 500); 18 Apr 2011 16:03:48 -0000 Mailing-List: contact commits-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@jackrabbit.apache.org Delivered-To: mailing list commits@jackrabbit.apache.org Received: (qmail 71321 invoked by uid 99); 18 Apr 2011 16:03:48 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 18 Apr 2011 16:03:48 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 18 Apr 2011 16:03:47 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id D34FE23888E4; Mon, 18 Apr 2011 16:03:26 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1094632 - in /jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk: Repository.java store/CommitBuilder.java store/MutableNode.java Date: Mon, 18 Apr 2011 16:03:26 -0000 To: commits@jackrabbit.apache.org From: stefan@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110418160326.D34FE23888E4@eris.apache.org> 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 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(); + } + + public void addNode(String parentNodePath, String nodeName) throws Exception { + addNode(parentNodePath, nodeName, Collections.emptyMap()); + } + + public void addNode(String parentNodePath, String nodeName, Map 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 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 getChildEntries() { + public Map getChildNodeEntries() { return childEntries; }