public class MemoryNodeBuilder extends Object implements NodeBuilder
A MemoryNodeBuilder instance tracks uncommitted changes without
relying on weak references or requiring hard references on the entire
accessed subtree. It does this by relying on MutableNodeState
instances for tracking uncommitted changes and on Head
instances for tracking the connectedness of the builder. A builder keeps
a reference to the parent builder and knows its own name, which is used
to check for relevant changes in its parent builder and update its state
accordingly.
A builder is in one of three possible states, which is tracked within
its Head instance:
MutableNodeState
instance. Before each access the connected builder checks whether its
parents base state has been reset and if so, resets its own base state
accordingly.
| Modifier | Constructor and Description |
|---|---|
protected |
MemoryNodeBuilder(MemoryNodeBuilder parent,
String name)
Creates a new in-memory child builder.
|
|
MemoryNodeBuilder(@NotNull NodeState base)
Creates a new in-memory node state builder rooted at
and based on the passed
base state. |
| Modifier and Type | Method and Description |
|---|---|
protected void |
annotateSourcePath()
Annotate this builder with its source path if this builder has not
been transiently added.
|
@NotNull NodeBuilder |
child(@NotNull String name)
Returns a builder for constructing changes to the named child node.
|
org.apache.jackrabbit.oak.api.Blob |
createBlob(InputStream stream) |
protected MemoryNodeBuilder |
createChildBuilder(String name)
Factory method for creating new child state builders.
|
boolean |
exists()
Checks whether this builder represents a node that exists.
|
@NotNull NodeState |
getBaseState()
Returns the original base state that this builder is modifying.
|
boolean |
getBoolean(@NotNull String name)
Returns the boolean value of the named property.
|
@NotNull NodeBuilder |
getChildNode(@NotNull String name)
Returns a builder for constructing changes to the named child node.
|
long |
getChildNodeCount(long max)
Returns the current number of child nodes.
|
@NotNull Iterable<String> |
getChildNodeNames()
Returns the names of current child nodes.
|
protected String |
getName()
Accessor for name
|
@Nullable String |
getName(@NotNull String name)
Returns the name value of the named property.
|
@NotNull Iterable<String> |
getNames(@NotNull String name)
Returns the name values of the named property.
|
@NotNull NodeState |
getNodeState()
Returns an immutable node state that matches the current state of
the builder.
|
protected MemoryNodeBuilder |
getParent()
Accessor for parent builder
|
String |
getPath() |
@NotNull Iterable<? extends org.apache.jackrabbit.oak.api.PropertyState> |
getProperties()
Returns the current properties.
|
org.apache.jackrabbit.oak.api.PropertyState |
getProperty(String name)
Returns the current state of the named property, or
null
if the property is not set. |
long |
getPropertyCount()
Returns the current number of properties.
|
@Nullable String |
getString(@NotNull String name)
Returns the name value of the named property.
|
boolean |
hasChildNode(@NotNull String name)
Checks whether the named child node currently exists.
|
boolean |
hasProperty(String name)
Checks whether the named property exists.
|
boolean |
isModified()
Check whether this builder represents a modified node, which has either modified properties
or removed or added child nodes.
|
boolean |
isNew()
Check whether this builder represents a new node, which is not present in the base state.
|
boolean |
isNew(String name)
Check whether the named property is new, i.e.
|
boolean |
isReplaced()
Check whether this builder represents a node that used to exist but
was then replaced with other content, for example as a result of
a
NodeBuilder.setChildNode(String) call. |
boolean |
isReplaced(String name)
Check whether the named property exists in the base state but is
replaced with other content, for example as a result of
a
NodeBuilder.setProperty(PropertyState) call. |
boolean |
isRoot() |
boolean |
moveTo(@NotNull NodeBuilder newParent,
@NotNull String newName)
This implementation has the same semantics as adding this node
with name
newName as a new child of newParent followed
by removing this node. |
boolean |
remove()
Remove this child node from its parent.
|
@NotNull NodeBuilder |
removeProperty(String name)
Remove the named property.
|
void |
reset(@NotNull NodeState newBase)
Throws away all changes in this builder and resets the base to the
given node state.
|
protected void |
set(NodeState newState)
Replaces the current state of this builder with the given node state.
|
@NotNull NodeBuilder |
setChildNode(@NotNull String name)
Adds the named child node and returns a builder for modifying it.
|
@NotNull NodeBuilder |
setChildNode(@NotNull String name,
@NotNull NodeState state)
Adds or replaces a subtree.
|
@NotNull NodeBuilder |
setProperty(@NotNull org.apache.jackrabbit.oak.api.PropertyState property)
Set a property state
|
<T> @NotNull NodeBuilder |
setProperty(String name,
T value)
Set a property state
|
<T> @NotNull NodeBuilder |
setProperty(String name,
T value,
org.apache.jackrabbit.oak.api.Type<T> type)
Set a property state
|
String |
toString() |
protected void |
updated()
Called whenever this node is modified, i.e.
|
protected MemoryNodeBuilder(MemoryNodeBuilder parent, String name)
parent - parent buildername - name of this nodepublic MemoryNodeBuilder(@NotNull
@NotNull NodeState base)
base state.base - base state of the new builderpublic final boolean isRoot()
true iff this is the root builderprotected MemoryNodeBuilder createChildBuilder(String name)
protected void updated()
updated() call on the root builder
(unless this is already the root builder), which subclasses can use
to capture aggregate update information across the whole tree.protected final MemoryNodeBuilder getParent()
protected final String getName()
public void reset(@NotNull
@NotNull NodeState newBase)
newBase - new base stateprotected void set(NodeState newState)
newState - new state@NotNull public @NotNull NodeState getNodeState()
NodeBuildergetNodeState in interface NodeBuilder@NotNull public @NotNull NodeState getBaseState()
NodeBuilderexists method
returns false) if this builder represents a new node that
didn't exist in the base content tree.getBaseState in interface NodeBuilderpublic boolean exists()
NodeBuilderexists in interface NodeBuildertrue if the node exists, false otherwisepublic boolean isNew()
NodeBuilderisNew in interface NodeBuildertrue for a new nodepublic boolean isNew(String name)
NodeBuilderisNew in interface NodeBuildername - property nametrue for a new propertypublic boolean isModified()
NodeBuilderisModified in interface NodeBuildertrue for a modified nodepublic boolean isReplaced()
NodeBuilderNodeBuilder.setChildNode(String) call.isReplaced in interface NodeBuildertrue for a replaced nodepublic boolean isReplaced(String name)
NodeBuilderNodeBuilder.setProperty(PropertyState) call.isReplaced in interface NodeBuildername - property nametrue for a replaced propertypublic long getChildNodeCount(long max)
NodeBuilderIf an implementation does know the exact value, it returns it (even if the value is higher than max). If the implementation does not know the exact value, and the child node count is higher than max, it may return Long.MAX_VALUE. The cost of the operation is at most O(max).
getChildNodeCount in interface NodeBuildermax - the maximum value@NotNull public @NotNull Iterable<String> getChildNodeNames()
NodeBuildergetChildNodeNames in interface NodeBuilderpublic boolean hasChildNode(@NotNull
@NotNull String name)
NodeBuilderhasChildNode in interface NodeBuildername - child node nametrue if the named child node exists,
false otherwise@NotNull public @NotNull NodeBuilder child(@NotNull @NotNull String name)
NodeBuilder
All updates to the returned child builder will implicitly affect
also this builder, as if a
setNode(name, childBuilder.getNodeState()) method call
had been made after each update. Repeated calls to this method with
the same name will return the same child builder instance until an
explicit NodeBuilder.setChildNode(String, NodeState) or
NodeBuilder.remove() call is made, at which point the link
between this builder and a previously returned child builder for
that child node name will get broken.
child in interface NodeBuildername - name of the child node@NotNull public @NotNull NodeBuilder getChildNode(@NotNull @NotNull String name)
NodeBuilderIllegalStateExceptions to be thrown.getChildNode in interface NodeBuildername - name of the child node@NotNull public @NotNull NodeBuilder setChildNode(@NotNull @NotNull String name)
NodeBuildersetChildNode in interface NodeBuildername - name of the child node@NotNull public @NotNull NodeBuilder setChildNode(@NotNull @NotNull String name, @NotNull @NotNull NodeState state)
NodeBuildersetChildNode in interface NodeBuildername - name of the child node containing the new subtreestate - subtreepublic boolean remove()
NodeBuilderremove in interface NodeBuildertrue for existing nodes, false otherwisepublic boolean moveTo(@NotNull
@NotNull NodeBuilder newParent,
@NotNull
@NotNull String newName)
throws IllegalArgumentException
newName as a new child of newParent followed
by removing this node. As a consequence this implementation allows
moving this node into the subtree rooted here, the result of which
is the same as removing this node.
See also the general contract
for MoveTo.
moveTo in interface NodeBuildernewParent - builder for the new parent.newName - name of this child at the new parenttrue on success, false otherwiseIllegalArgumentException - if the given name string is empty
or contains the forward slash characterprotected final void annotateSourcePath()
MoveDetector.SOURCE_PATH.
The source path of a builder is its current path if its current source path annotation is empty and none of its parents has a source path annotation set. Otherwise it is the source path of the first parent (or self) that has its source path annotation set appended with the relative path from that parent to this builder.
This builder has been transiently added when there exists no base node at its source path.
public long getPropertyCount()
NodeBuildergetPropertyCount in interface NodeBuilder@NotNull public @NotNull Iterable<? extends org.apache.jackrabbit.oak.api.PropertyState> getProperties()
NodeBuildergetProperties in interface NodeBuilderpublic boolean hasProperty(String name)
NodeBuildergetProperty(name) != null, but may be optimized
to avoid having to load the property value.hasProperty in interface NodeBuildername - property nametrue if the named property exists,
false otherwisepublic org.apache.jackrabbit.oak.api.PropertyState getProperty(String name)
NodeBuildernull
if the property is not set.getProperty in interface NodeBuildername - property namepublic boolean getBoolean(@NotNull
@NotNull String name)
NodeBuilder
PropertyState property = builder.getProperty(name);
return property != null
&& property.getType() == Type.BOOLEAN
&& property.getValue(Type.BOOLEAN);
getBoolean in interface NodeBuildername - property namefalse@Nullable public @Nullable String getString(@NotNull @NotNull String name)
NodeBuilder
PropertyState property = builder.getProperty(name);
if (property != null && property.getType() == Type.STRING) {
return property.getValue(Type.STRING);
} else {
return null;
}
getString in interface NodeBuildername - property namenull@Nullable public @Nullable String getName(@NotNull @NotNull String name)
NodeBuilder
PropertyState property = builder.getProperty(name);
if (property != null && property.getType() == Type.NAME) {
return property.getValue(Type.NAME);
} else {
return null;
}
getName in interface NodeBuildername - property namenull@NotNull public @NotNull Iterable<String> getNames(@NotNull @NotNull String name)
NodeBuilder
PropertyState property = builder.getProperty(name);
if (property != null && property.getType() == Type.NAMES) {
return property.getValue(Type.NAMES);
} else {
return Collections.emptyList();
}
getNames in interface NodeBuildername - property name@NotNull public @NotNull NodeBuilder setProperty(@NotNull @NotNull org.apache.jackrabbit.oak.api.PropertyState property)
NodeBuildersetProperty in interface NodeBuilderproperty - The property state to set@NotNull public <T> @NotNull NodeBuilder setProperty(String name, @NotNull T value)
NodeBuildersetProperty in interface NodeBuilderT - The type of this property. Must be one of String, Blob, byte[], Long, Integer, Double, Boolean, BigDecimalname - The name of this propertyvalue - The value of this property@NotNull public <T> @NotNull NodeBuilder setProperty(String name, @NotNull T value, org.apache.jackrabbit.oak.api.Type<T> type)
NodeBuildersetProperty in interface NodeBuilderT - The type of this property.name - The name of this propertyvalue - The value of this property@NotNull public @NotNull NodeBuilder removeProperty(String name)
NodeBuildername does not exist.removeProperty in interface NodeBuildername - name of the propertypublic org.apache.jackrabbit.oak.api.Blob createBlob(InputStream stream) throws IOException
createBlob in interface NodeBuilderIOExceptionpublic final String getPath()
Copyright © 2012–2020 The Apache Software Foundation. All rights reserved.