Author: jukka Date: Wed Apr 11 07:24:21 2012 New Revision: 1324601 URL: http://svn.apache.org/viewvc?rev=1324601&view=rev Log: OAK-18: Define Oak API Copy tree model interfaces from .mk.model in oak-mk to .oak.api in oak-core. This makes .oak.api independent of oak-mk. Remove Scalar and NodeStateEditor from oak-mk as they are not used there Remove PropertyState.getEncodedValue from oak-core as it's not used there Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/ChildNodeEntry.java - copied, changed from r1324586, jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/Scalar.java jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/NodeState.java jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/NodeStateDiff.java jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/NodeStateEditor.java - copied, changed from r1324586, jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/NodeStateEditor.java jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/NodeStore.java - copied, changed from r1324586, jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/NodeStore.java jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/PropertyState.java - copied, changed from r1324586, jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/PropertyState.java jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Scalar.java - copied, changed from r1324586, jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/Scalar.java jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/AbstractChildNodeEntry.java - copied, changed from r1324586, jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/AbstractPropertyState.java jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/AbstractNodeState.java jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/AbstractPropertyState.java - copied, changed from r1324586, jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/AbstractPropertyState.java jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/ScalarImpl.java - copied, changed from r1324586, jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/ScalarImpl.java Removed: jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/NodeStateEditor.java jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/Scalar.java jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/ScalarImpl.java Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Connection.java jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ConnectionImpl.java jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelChildNodeEntry.java jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeState.java jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStateEditor.java jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelPropertyState.java jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/TransientNodeState.java jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStateEditorFuzzIT.java jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStateEditorTest.java jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStateTest.java jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/LargeKernelNodeStateTest.java jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemStateProvider.java jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyImpl.java jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/util/ValueConverter.java jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/json/JsonBuilder.java jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/AbstractPropertyState.java jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/NodeStore.java jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/PropertyState.java jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/store/AbstractRevisionStore.java jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/store/StoredNodeAsState.java Copied: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/ChildNodeEntry.java (from r1324586, jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/Scalar.java) URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/ChildNodeEntry.java?p2=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/ChildNodeEntry.java&p1=jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/Scalar.java&r1=1324586&r2=1324601&rev=1324601&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/Scalar.java (original) +++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/ChildNodeEntry.java Wed Apr 11 07:24:21 2012 @@ -6,7 +6,7 @@ * (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 + * 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, @@ -14,32 +14,30 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.jackrabbit.mk.model; - -import java.io.InputStream; +package org.apache.jackrabbit.oak.api; /** - * An immutable, typed scalar value. + * TODO: document + * + *
+ * Two child node entries are considered equal if and only if their names + * and referenced node states match. The {@link Object#equals(Object)} + * method needs to be implemented so that it complies with this definition. + * And while child node entries are not meant for use as hash keys, the + * {@link Object#hashCode()} method should still be implemented according + * to this equality contract. */ -public interface Scalar { - enum Type {BOOLEAN, LONG, DOUBLE, BINARY, STRING, NULL} +public interface ChildNodeEntry { /** - * Returns the value type. - *
- * - * @return value type + * TODO: document */ - Type getType(); - - boolean getBoolean(); - - long getLong(); + String getName(); - double getDouble(); - - InputStream getInputStream(); - - String getString(); + /** + * TODO: document + */ + NodeState getNode(); } Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Connection.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Connection.java?rev=1324601&r1=1324600&r2=1324601&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Connection.java (original) +++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Connection.java Wed Apr 11 07:24:21 2012 @@ -16,9 +16,6 @@ */ package org.apache.jackrabbit.oak.api; -import org.apache.jackrabbit.mk.model.NodeState; -import org.apache.jackrabbit.mk.model.NodeStateEditor; - import java.io.Closeable; /** Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/NodeState.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/NodeState.java?rev=1324601&view=auto ============================================================================== --- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/NodeState.java (added) +++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/NodeState.java Wed Apr 11 07:24:21 2012 @@ -0,0 +1,159 @@ +/* + * 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.api; + +/** + * A content tree consists of nodes and properties, each of which + * evolves through different states during its lifecycle. This interface + * represents a specific, immutable state of a node in a content tree. + * A node consists of an unordered set of name -> item mappings, where + * each item is either a property or a child node. + *
+ * Depending on context, a NodeState instance can be interpreted as + * representing the state of just that node, of the subtree starting at + * that node, or of an entire tree in case it's a root node. + *
+ * The crucial difference between this interface and the similarly named + * class in Jackrabbit 2.x is that this interface represents a specific, + * immutable state of a node, whereas the Jackrabbit 2.x class represented + * the current state of a node. + * + *
+ * As mentioned above, all node and property states are always immutable. + * Thus repeating a method call is always guaranteed to produce the same + * result as before unless some internal error occurs (see below). This + * immutability only applies to a specific state instance. Different states + * of a node can obviously be different, and in some cases even different + * instances of the same state may behave slightly differently. For example + * due to performance optimization or other similar changes the iteration + * order of properties or child nodes may be different for two instances + * of the same state. + *
+ * In addition to being immutable, a specific state instance guaranteed to + * be fully thread-safe. Possible caching or other internal changes need to + * be properly synchronized so that any number of concurrent clients can + * safely access a state instance. + * + *
+ * A node state can be (and often is) backed by local files or network + * resources. All IO operations or related concerns like caching should be + * handled transparently below this interface. Potential IO problems and + * recovery attempts like retrying a timed-out network access need to be + * handled below this interface, and only hard errors should be thrown up + * as {@link RuntimeException unchecked exceptions} that higher level code + * is not expected to be able to recover from. + *
+ * Since this interface exposes no higher level constructs like access + * controls, locking, node types or even path parsing, there's no way + * for content access to fail because of such concerns. Such functionality + * and related checked exceptions or other control flow constructs should + * be implemented on a higher level above this interface. + * + *
+ * Not all content exposed by this interface needs to be backed by actual + * persisted data. An implementation may want to provide derived data, + * like for example the aggregate size of the entire subtree as an + * extra virtual property. A virtualization, sharding or caching layer + * could provide a composite view over multiple underlying content trees. + * Or a basic access control layer could decide to hide certain content + * based on specific rules. All such features need to be implemented + * according to the API contract of this interface. A separate higher level + * interface needs to be used if an implementation can't for example + * guarantee immutability of exposed content as discussed above. + * + *
+ * Two node states are considered equal if and only if their properties and + * child nodes match, regardless of ordering. The + * {@link Object#equals(Object)} method needs to be implemented so that it + * complies with this definition. And while node states are not meant for + * use as hash keys, the {@link Object#hashCode()} method should still be + * implemented according to this equality contract. + */ +public interface NodeState { + + /** + * Returns the named property. The name is an opaque string and + * is not parsed or otherwise interpreted by this method. + *
+ * The namespace of properties and child nodes is shared, so if
+ * this method returns a non-null
value for a given
+ * name, then {@link #getChildNode(String)} is guaranteed to return
+ * null
for the same name.
+ *
+ * @param name name of the property to return
+ * @return named property, or null
if not found
+ */
+ PropertyState getProperty(String name);
+
+ /**
+ * Returns the number of properties of this node.
+ *
+ * @return number of properties
+ */
+ long getPropertyCount();
+
+ /**
+ * Returns an iterable of the properties of this node. Multiple
+ * iterations are guaranteed to return the properties in the same
+ * order, but the specific order used is implementation-dependent
+ * and may change across different states of the same node.
+ *
+ * @return properties in some stable order
+ */
+ Iterable extends PropertyState> getProperties();
+
+ /**
+ * Returns the named child node. The name is an opaque string and
+ * is not parsed or otherwise interpreted by this method.
+ *
+ * The namespace of properties and child nodes is shared, so if
+ * this method returns a non-null
value for a given
+ * name, then {@link #getProperty(String)} is guaranteed to return
+ * null
for the same name.
+ *
+ * @param name name of the child node to return
+ * @return named child node, or null
if not found
+ */
+ NodeState getChildNode(String name);
+
+ /**
+ * Returns the number of child nodes of this node.
+ *
+ * @return number of child nodes
+ */
+ long getChildNodeCount();
+
+ /**
+ * Returns an iterable of the child node entries starting from the
+ * given offset. Multiple iterations are guaranteed to return the
+ * child nodes in the same order, but the specific order used is
+ * implementation-dependent and may change across different states
+ * of the same node. An empty iterable is returned if the given
+ * offset is greater than the offset of the last child node entry.
+ *
+ * @param offset zero-based offset of the first entry to return
+ * @param count maximum number of entries to return,
+ * or -1 for all remaining entries
+ * @return requested child node entries in some stable order
+ */
+ Iterable extends ChildNodeEntry> getChildNodeEntries(long offset, int count);
+
+}
Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/NodeStateDiff.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/NodeStateDiff.java?rev=1324601&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/NodeStateDiff.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/NodeStateDiff.java Wed Apr 11 07:24:21 2012
@@ -0,0 +1,79 @@
+/*
+ * 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.api;
+
+/**
+ * Handler of node state differences.
+ * The {@link NodeStore#compare(NodeState, NodeState, NodeStateDiff)} reports
+ * detected node state differences by calling methods of a handler instance
+ * that implements this interface. The compare method will go through all
+ * properties and child nodes of the two states, calling the relevant
+ * added, changed or deleted methods where appropriate. Differences in
+ * the ordering of properties or child nodes do not affect the comparison,
+ * and the order in which such differences are reported is unspecified.
+ */
+public interface NodeStateDiff {
+
+ /**
+ * Called for all added properties.
+ *
+ * @param after property state after the change
+ */
+ void propertyAdded(PropertyState after);
+
+ /**
+ * Called for all changed properties. The names of the given two
+ * property states are guaranteed to be the same.
+ *
+ * @param before property state before the change
+ * @param after property state after the change
+ */
+ void propertyChanged(PropertyState before, PropertyState after);
+
+ /**
+ * Called for all deleted properties.
+ *
+ * @param before property state before the change
+ */
+ void propertyDeleted(PropertyState before);
+
+ /**
+ * Called for all added child nodes.
+ *
+ * @param name name of the added child node
+ * @param after child node state after the change
+ */
+ void childNodeAdded(String name, NodeState after);
+
+ /**
+ * Called for all changed child nodes.
+ *
+ * @param name name of the changed child node
+ * @param before child node state before the change
+ * @param after child node state after the change
+ */
+ void childNodeChanged(String name, NodeState before, NodeState after);
+
+ /**
+ * Called for all deleted child nodes.
+ *
+ * @param name name of the deleted child node
+ * @param before child node state before the change
+ */
+ void childNodeDeleted(String name, NodeState before);
+
+}
Copied: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/NodeStateEditor.java (from r1324586, jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/NodeStateEditor.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/NodeStateEditor.java?p2=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/NodeStateEditor.java&p1=jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/NodeStateEditor.java&r1=1324586&r2=1324601&rev=1324601&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/NodeStateEditor.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/NodeStateEditor.java Wed Apr 11 07:24:21 2012
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.jackrabbit.mk.model;
+package org.apache.jackrabbit.oak.api;
import java.util.List;
Copied: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/NodeStore.java (from r1324586, jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/NodeStore.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/NodeStore.java?p2=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/NodeStore.java&p1=jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/NodeStore.java&r1=1324586&r2=1324601&rev=1324601&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/NodeStore.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/NodeStore.java Wed Apr 11 07:24:21 2012
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.jackrabbit.mk.model;
+package org.apache.jackrabbit.oak.api;
/**
* Storage abstraction for content trees. At any given point in time
Copied: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/PropertyState.java (from r1324586, jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/PropertyState.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/PropertyState.java?p2=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/PropertyState.java&p1=jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/PropertyState.java&r1=1324586&r2=1324601&rev=1324601&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/PropertyState.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/PropertyState.java Wed Apr 11 07:24:21 2012
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.jackrabbit.mk.model;
+package org.apache.jackrabbit.oak.api;
/**
* Immutable property state. A property consists of a name and
@@ -37,11 +37,6 @@ public interface PropertyState {
String getName();
/**
- * @return the JSON encoded value of this property state.
- */
- String getEncodedValue();
-
- /**
* Determine whether this is a multi valued property
* @return {@code true} if and only if this is a multi valued property.
*/
Copied: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Scalar.java (from r1324586, jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/Scalar.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Scalar.java?p2=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Scalar.java&p1=jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/Scalar.java&r1=1324586&r2=1324601&rev=1324601&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/Scalar.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Scalar.java Wed Apr 11 07:24:21 2012
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.jackrabbit.mk.model;
+package org.apache.jackrabbit.oak.api;
import java.io.InputStream;
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ConnectionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ConnectionImpl.java?rev=1324601&r1=1324600&r2=1324601&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ConnectionImpl.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ConnectionImpl.java Wed Apr 11 07:24:21 2012
@@ -18,12 +18,12 @@ package org.apache.jackrabbit.oak.core;
import org.apache.jackrabbit.mk.MicroKernelFactory;
import org.apache.jackrabbit.mk.api.MicroKernel;
-import org.apache.jackrabbit.mk.model.NodeState;
-import org.apache.jackrabbit.mk.model.NodeStateEditor;
-import org.apache.jackrabbit.mk.model.NodeStore;
import org.apache.jackrabbit.oak.api.AuthInfo;
import org.apache.jackrabbit.oak.api.CommitFailedException;
import org.apache.jackrabbit.oak.api.Connection;
+import org.apache.jackrabbit.oak.api.NodeState;
+import org.apache.jackrabbit.oak.api.NodeStateEditor;
+import org.apache.jackrabbit.oak.api.NodeStore;
import org.apache.jackrabbit.oak.api.QueryEngine;
import org.apache.jackrabbit.oak.kernel.KernelNodeStore;
import org.apache.jackrabbit.oak.query.QueryEngineImpl;
Copied: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/AbstractChildNodeEntry.java (from r1324586, jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/AbstractPropertyState.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/AbstractChildNodeEntry.java?p2=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/AbstractChildNodeEntry.java&p1=jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/AbstractPropertyState.java&r1=1324586&r2=1324601&rev=1324601&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/AbstractPropertyState.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/AbstractChildNodeEntry.java Wed Apr 11 07:24:21 2012
@@ -14,56 +14,47 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.jackrabbit.mk.model;
+package org.apache.jackrabbit.oak.kernel;
-import org.apache.jackrabbit.mk.json.JsonBuilder;
+import org.apache.jackrabbit.oak.api.ChildNodeEntry;
/**
- * Abstract base class for {@link PropertyState} implementations.
+ * Abstract base class for {@link ChildNodeEntry} implementations.
* This base class contains default implementations of the
* {@link #equals(Object)} and {@link #hashCode()} methods based on
* the implemented interface.
*/
-public abstract class AbstractPropertyState implements PropertyState {
+public abstract class AbstractChildNodeEntry implements ChildNodeEntry {
/**
- * Default implementation delegating to {@link JsonBuilder#encode(Scalar)}.
- * Derived classes may override this with more efficient implementations.
- */
- @Override
- public String getEncodedValue() {
- return isArray()
- ? JsonBuilder.encode(getArray())
- : JsonBuilder.encode(getScalar());
- }
-
- /**
- * Checks whether the given object is equal to this one. Two property
- * states are considered equal if both their names and encoded values
- * match. Subclasses may override this method with a more efficient
+ * Checks whether the given object is equal to this one. Two child node
+ * entries are considered equal if both their names and referenced node
+ * states match. Subclasses may override this method with a more efficient
* equality check if one is available.
*
* @param that target of the comparison
- * @return {@code true} if the objects are equal, {@code false} otherwise
+ * @return true
if the objects are equal,
+ * false
otherwise
*/
@Override
public boolean equals(Object that) {
if (this == that) {
return true;
- } else if (that instanceof PropertyState) {
- PropertyState other = (PropertyState) that;
+ } else if (that instanceof ChildNodeEntry) {
+ ChildNodeEntry other = (ChildNodeEntry) that;
return getName().equals(other.getName())
- && getEncodedValue().equals(other.getEncodedValue());
+ && getNode().equals(other.getNode());
} else {
return false;
}
+
}
/**
* Returns a hash code that's compatible with how the
* {@link #equals(Object)} method is implemented. The current
- * implementation simply returns the hash code of the property name
- * since {@link PropertyState} instances are not intended for use as
+ * implementation simply returns the hash code of the child node name
+ * since {@link ChildNodeEntry} instances are not intended for use as
* hash keys.
*
* @return hash code
Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/AbstractNodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/AbstractNodeState.java?rev=1324601&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/AbstractNodeState.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/AbstractNodeState.java Wed Apr 11 07:24:21 2012
@@ -0,0 +1,136 @@
+/*
+ * 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.kernel;
+
+import org.apache.jackrabbit.oak.api.ChildNodeEntry;
+import org.apache.jackrabbit.oak.api.NodeState;
+import org.apache.jackrabbit.oak.api.PropertyState;
+
+/**
+ * Abstract base class for {@link NodeState} implementations.
+ * This base class contains default implementations of the
+ * {@link #equals(Object)} and {@link #hashCode()} methods based on
+ * the implemented interface.
+ *
+ * This class also implements trivial (and potentially very slow) versions of
+ * the {@link #getProperty(String)} and {@link #getPropertyCount()} methods
+ * based on {@link #getProperties()}. The {@link #getChildNode(String)} and
+ * {@link #getChildNodeCount()} methods are similarly implemented based on
+ * {@link #getChildNodeEntries(long, int)}. Subclasses should normally
+ * override these method with a more efficient alternatives.
+ */
+public abstract class AbstractNodeState implements NodeState {
+
+ @Override
+ public PropertyState getProperty(String name) {
+ for (PropertyState property : getProperties()) {
+ if (name.equals(property.getName())) {
+ return property;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ @SuppressWarnings("unused")
+ public long getPropertyCount() {
+ long count = 0;
+ for (PropertyState property : getProperties()) {
+ count++;
+ }
+ return count;
+ }
+
+ @Override
+ public NodeState getChildNode(String name) {
+ for (ChildNodeEntry entry : getChildNodeEntries(0, -1)) {
+ if (name.equals(entry.getName())) {
+ return entry.getNode();
+ }
+ }
+ return null;
+ }
+
+ @Override
+ @SuppressWarnings("unused")
+ public long getChildNodeCount() {
+ long count = 0;
+ for (ChildNodeEntry entry : getChildNodeEntries(0, -1)) {
+ count++;
+ }
+ return count;
+ }
+
+ /**
+ * Checks whether the given object is equal to this one. Two node states
+ * are considered equal if all their properties and child nodes match,
+ * regardless of ordering. Subclasses may override this method with a
+ * more efficient equality check if one is available.
+ *
+ * @param that target of the comparison
+ * @return
* This is a low-level interface that doesn't cover functionality like
* merging concurrent changes or rejecting new tree states based on some
@@ -38,28 +34,6 @@ public interface NodeStore {
NodeState getRoot();
/**
- * Creates a private branch from a {@code base} node state
- * for editing. The branch can later be merged back into
- * the node store using the {@link #merge(NodeStateEditor, NodeState) merge}
- * method.
- *
- * @param base base node state
- * @return a private branch rooted at {@code base}
- */
- NodeStateEditor branch(NodeState base);
-
- /**
- * Atomically merges the changes from {@code branch} back into the
- * {@code target}.
- *
- * @param branch branch for merging into {@code target}
- * @param target target of the merge operation
- * @return node state resulting from merging {@code branch} into
- * {@code target}.
- */
- NodeState merge(NodeStateEditor branch, NodeState target);
-
- /**
* Compares the given two node states. Any found differences are
* reported by calling the relevant added, changed or deleted methods
* of the given handler.
Modified: jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/PropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/PropertyState.java?rev=1324601&r1=1324600&r2=1324601&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/PropertyState.java (original)
+++ jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/PropertyState.java Wed Apr 11 07:24:21 2012
@@ -41,22 +41,4 @@ public interface PropertyState {
*/
String getEncodedValue();
- /**
- * Determine whether this is a multi valued property
- * @return {@code true} if and only if this is a multi valued property.
- */
- boolean isArray();
-
- /**
- * @return the single value of this property or {@code null} if this is a multi
- * valued property.
- */
- Scalar getScalar();
-
- /**
- * @return an iterable of the values of this multi valued property or
- * {@code null} if this is not a multi valued property.
- */
- Iterabletrue
if the objects are equal,
+ * false
otherwise
+ */
+ @Override
+ public boolean equals(Object that) {
+ if (this == that) {
+ return true;
+ } else if (that == null || !(that instanceof NodeState)) {
+ return false;
+ }
+
+ NodeState other = (NodeState) that;
+
+ long propertyCount = 0;
+ for (PropertyState property : getProperties()) {
+ if (!property.equals(other.getProperty(property.getName()))) {
+ return false;
+ }
+ propertyCount++;
+ }
+ if (propertyCount != other.getPropertyCount()) {
+ return false;
+ }
+
+ long childNodeCount = 0;
+ for (ChildNodeEntry entry : getChildNodeEntries(0, -1)) {
+ if (!entry.getNode().equals(other.getChildNode(entry.getName()))) {
+ return false;
+ }
+ childNodeCount++;
+ }
+ if (childNodeCount != other.getChildNodeCount()) {
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Returns a hash code that's compatible with how the
+ * {@link #equals(Object)} method is implemented. The current
+ * implementation simply returns zero for everything since
+ * {@link NodeState} instances are not intended for use as hash keys.
+ *
+ * @return hash code
+ */
+ @Override
+ public int hashCode() {
+ return 0;
+ }
+
+}
Copied: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/AbstractPropertyState.java (from r1324586, jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/AbstractPropertyState.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/AbstractPropertyState.java?p2=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/AbstractPropertyState.java&p1=jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/AbstractPropertyState.java&r1=1324586&r2=1324601&rev=1324601&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/AbstractPropertyState.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/AbstractPropertyState.java Wed Apr 11 07:24:21 2012
@@ -14,9 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.jackrabbit.mk.model;
+package org.apache.jackrabbit.oak.kernel;
-import org.apache.jackrabbit.mk.json.JsonBuilder;
+import java.util.Iterator;
+
+import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.api.Scalar;
/**
* Abstract base class for {@link PropertyState} implementations.
@@ -27,17 +30,6 @@ import org.apache.jackrabbit.mk.json.Jso
public abstract class AbstractPropertyState implements PropertyState {
/**
- * Default implementation delegating to {@link JsonBuilder#encode(Scalar)}.
- * Derived classes may override this with more efficient implementations.
- */
- @Override
- public String getEncodedValue() {
- return isArray()
- ? JsonBuilder.encode(getArray())
- : JsonBuilder.encode(getScalar());
- }
-
- /**
* Checks whether the given object is equal to this one. Two property
* states are considered equal if both their names and encoded values
* match. Subclasses may override this method with a more efficient
@@ -52,13 +44,28 @@ public abstract class AbstractPropertySt
return true;
} else if (that instanceof PropertyState) {
PropertyState other = (PropertyState) that;
- return getName().equals(other.getName())
- && getEncodedValue().equals(other.getEncodedValue());
+ return getName().equals(other.getName()) && valueEquals(other);
} else {
return false;
}
}
+ private boolean valueEquals(PropertyState other) {
+ if (isArray() != other.isArray()) {
+ return false;
+ } else if (isArray()) {
+ Iterator