From 77ce3505f3dac995fc94572a77cd26a013637bb9 Mon Sep 17 00:00:00 2001 From: Jukka Zitting Date: Wed, 16 May 2012 17:03:48 +0200 Subject: [PATCH] OAK-102: Expose the branch feature from NodeStore Adjust the interfaces --- .../jackrabbit/oak/spi/state/NodeStateBuilder.java | 45 ++------------ .../apache/jackrabbit/oak/spi/state/NodeStore.java | 15 +++-- .../jackrabbit/oak/spi/state/NodeStoreBranch.java | 62 ++++++++++++++++++++ 3 files changed, 73 insertions(+), 49 deletions(-) create mode 100644 oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeStoreBranch.java diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeStateBuilder.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeStateBuilder.java index 87cf383..e7d8a9f 100644 --- a/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeStateBuilder.java +++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeStateBuilder.java @@ -17,7 +17,6 @@ package org.apache.jackrabbit.oak.spi.state; import org.apache.jackrabbit.oak.api.CoreValue; -import org.apache.jackrabbit.oak.api.PropertyState; import java.util.List; @@ -35,55 +34,34 @@ public interface NodeStateBuilder { NodeState getNodeState(); /** - * Get a builder for a child node - * - * @param name name of the child node - * @return builder for the {@code name}d child node - */ - NodeStateBuilder getChildBuilder(String name); - - /** * Add a sub-tree * * @param name name child node containing the sub-tree * @param nodeState sub-tree - * @return builder for the added sub-tree */ - NodeStateBuilder addNode(String name, NodeState nodeState); - - /** - * Add the named child node if it doesn't already exist. - * - * @param name name of the child node - * @return a builder for the added child or {@code null} if such a child - * already exists - */ - NodeStateBuilder addNode(String name); + void setNode(String name, NodeState nodeState); /** * Remove a child node * @param name name of the child node - * @return {@code true} iff the child node existed */ - boolean removeNode(String name); + void removeNode(String name); /** * Set a property. * * @param name property name * @param value - * @return the affected property state */ - PropertyState setProperty(String name, CoreValue value); + void setProperty(String name, CoreValue value); /** * Set a property. * * @param name property name * @param values - * @return the affected property state */ - PropertyState setProperty(String name, List values); + void setProperty(String name, List values); /** * Remove the named property @@ -91,19 +69,4 @@ public interface NodeStateBuilder { */ void removeProperty(String name); - /** - * Move this node - * @param destParent builder for the parent node of the destination - * @param destName name of the moved node - * @return {@code true} iff the move succeeded - */ - boolean moveTo(NodeStateBuilder destParent, String destName); - - /** - * Copy this node - * @param destParent builder for the parent node of the destination - * @param destName name of the copied node - * @return {@code true} iff the copy succeeded - */ - boolean copyTo(NodeStateBuilder destParent, String destName); } diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeStore.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeStore.java index b92f0e8..cb7faa5 100644 --- a/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeStore.java +++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeStore.java @@ -16,7 +16,6 @@ */ package org.apache.jackrabbit.oak.spi.state; -import org.apache.jackrabbit.oak.api.CommitFailedException; import org.apache.jackrabbit.oak.api.CoreValueFactory; /** @@ -37,6 +36,13 @@ public interface NodeStore { NodeState getRoot(); /** + * Creates a new branch of the tree to which transient changes can be applied. + * + * @return branch + */ + NodeStoreBranch branch(); + + /** * Returns a builder for constructing a new or modified node state. * The builder is initialized with all the properties and child nodes * from the given base node state. @@ -54,13 +60,6 @@ public interface NodeStore { CoreValueFactory getValueFactory(); /** - * Updates the state of the content tree. - * - * @param newRoot new root node state - */ - void setRoot(NodeState newRoot) throws CommitFailedException; - - /** * Compares the given two node states. Any found differences are * reported by calling the relevant added, changed or deleted methods * of the given handler. diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeStoreBranch.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeStoreBranch.java new file mode 100644 index 0000000..17f6539 --- /dev/null +++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeStoreBranch.java @@ -0,0 +1,62 @@ +/* + * 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.oak.spi.state; + +import org.apache.jackrabbit.oak.api.CommitFailedException; + +public interface NodeStoreBranch { + + /** + * Returns the latest state of the branch. + * + * @return root node state + */ + NodeState getRoot(); + + /** + * Updates the state of the content tree. + * + * @param newRoot new root node state + */ + void setRoot(NodeState newRoot); + + /** + * Moves a node. + * + * @param source source path + * @param target target path + * @return {@code true} iff the move succeeded + */ + boolean move(String source, String target); + + /** + * Copies a node. + * + * @param source source path + * @param target target path + * @return {@code true} iff the copy succeeded + */ + boolean copy(String source, String target); + + /** + * Merges the changes in this branch to the main content tree. + * + * @throws CommitFailedException if the merge failed + */ + void merge() throws CommitFailedException; + +} -- 1.7.10.msysgit.1