Class DelegatingDocumentNodeState
- java.lang.Object
-
- org.apache.jackrabbit.oak.spi.state.AbstractNodeState
-
- org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState
-
- org.apache.jackrabbit.oak.plugins.document.secondary.DelegatingDocumentNodeState
-
- All Implemented Interfaces:
NodeState
public class DelegatingDocumentNodeState extends AbstractDocumentNodeState
NodeState wrapper which wraps another NodeState (mostly SegmentNodeState) so as to expose it as anAbstractDocumentNodeStateby extracting the meta properties which are stored as hidden properties
-
-
Field Summary
Fields Modifier and Type Field Description static StringPROP_LAST_REVstatic StringPROP_REVISION
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description @NotNull NodeBuilderbuilder()Returns a builder for constructing a new node state based on this state, i.e.booleanexists()Checks whether this node exists.booleangetBoolean(@NotNull String name)Returns the boolean value of the named property.@NotNull NodeStategetChildNode(@NotNull String name)Returns the named, possibly non-existent, child node.longgetChildNodeCount(long max)Returns the number of iterable child nodes of this node.@NotNull Iterable<? extends ChildNodeEntry>getChildNodeEntries()Returns the iterable child node entries of this instance.Iterable<String>getChildNodeNames()Returns the names of all iterable child nodes.RevisionVectorgetLastRevision()longgetLong(String name)Returns the long value of the named property.StringgetName(@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.protected NodeStateDiffergetNodeStateDiffer()PathgetPath()@NotNull Iterable<? extends PropertyState>getProperties()Returns an iterable of the properties of this node.PropertyStategetProperty(@NotNull String name)Returns the named property, ornullif no such property exists.longgetPropertyCount()Returns the number of properties of this node.RevisionVectorgetRootRevision()StringgetString(String name)Returns the string value of the named property.@NotNull Iterable<String>getStrings(@NotNull String name)Returns the string values of the named property.booleanhasChildNode(@NotNull String name)Checks whether the named child node exists.static booleanhasMetaProps(NodeState delegate)booleanhasNoChildren()booleanhasProperty(@NotNull String name)Checks whether the named property exists.booleanisFromExternalChange()AbstractDocumentNodeStatewithRootRevision(@NotNull RevisionVector root, boolean externalChange)Creates a copy of thisDocumentNodeStatewith theAbstractDocumentNodeState.getRootRevision()set to the givenrootrevision.static AbstractDocumentNodeStatewrap(NodeState delegate, NodeStateDiffer differ)static NodeStatewrapIfPossible(NodeState delegate, NodeStateDiffer differ)Wraps a given root NodeState as aDelegatingDocumentNodeStateif it has required meta properties otherwise just returns the passed NodeState-
Methods inherited from class org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState
compareAgainstBaseState, equals
-
Methods inherited from class org.apache.jackrabbit.oak.spi.state.AbstractNodeState
checkValidName, compareAgainstBaseState, comparePropertiesAgainstBaseState, count, equals, getBoolean, getLong, getName, getNames, getString, getStrings, hashCode, isValidName, toString, toString
-
-
-
-
Field Detail
-
PROP_REVISION
public static final String PROP_REVISION
- See Also:
- Constant Field Values
-
PROP_LAST_REV
public static final String PROP_LAST_REV
- See Also:
- Constant Field Values
-
-
Method Detail
-
wrapIfPossible
public static NodeState wrapIfPossible(NodeState delegate, NodeStateDiffer differ)
Wraps a given root NodeState as aDelegatingDocumentNodeStateif it has required meta properties otherwise just returns the passed NodeState- Parameters:
delegate- nodeState to wrap- Returns:
- wrapped state or original state
-
hasMetaProps
public static boolean hasMetaProps(NodeState delegate)
-
wrap
public static AbstractDocumentNodeState wrap(NodeState delegate, NodeStateDiffer differ)
-
getPath
public Path getPath()
- Specified by:
getPathin classAbstractDocumentNodeState
-
getLastRevision
public RevisionVector getLastRevision()
- Specified by:
getLastRevisionin classAbstractDocumentNodeState
-
getRootRevision
public RevisionVector getRootRevision()
- Specified by:
getRootRevisionin classAbstractDocumentNodeState
-
isFromExternalChange
public boolean isFromExternalChange()
- Specified by:
isFromExternalChangein classAbstractDocumentNodeState
-
withRootRevision
public AbstractDocumentNodeState withRootRevision(@NotNull @NotNull RevisionVector root, boolean externalChange)
Description copied from class:AbstractDocumentNodeStateCreates a copy of thisDocumentNodeStatewith theAbstractDocumentNodeState.getRootRevision()set to the givenrootrevision. This method returnsthisinstance if the givenrootrevision is the same as the one in this instance and theAbstractDocumentNodeState.isFromExternalChange()flags are equal.- Specified by:
withRootRevisionin classAbstractDocumentNodeState- Parameters:
root- the root revision for the copy of this node state.externalChange- if theAbstractDocumentNodeState.isFromExternalChange()flag must be set on the returned node state.- Returns:
- a copy of this node state with the given root revision and external change flag.
-
hasNoChildren
public boolean hasNoChildren()
- Specified by:
hasNoChildrenin classAbstractDocumentNodeState
-
getNodeStateDiffer
protected NodeStateDiffer getNodeStateDiffer()
- Specified by:
getNodeStateDifferin classAbstractDocumentNodeState
-
exists
public boolean exists()
Description copied from interface:NodeStateChecks whether this node exists. See the above discussion about the existence of node states.- Returns:
trueif this node exists,falseif not
-
getProperties
@NotNull public @NotNull Iterable<? extends PropertyState> getProperties()
Description copied from interface:NodeStateReturns 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.- Returns:
- properties in some stable order
-
hasChildNode
public boolean hasChildNode(@NotNull @NotNull String name)Description copied from interface:NodeStateChecks whether the named child node exists. The implementation is equivalent togetChildNode(name).exists(), except that passing an invalid name as argument will result in afalsereturn value instead of anIllegalArgumentException.- Parameters:
name- name of the child node- Returns:
trueif the named child node exists,falseotherwise
-
getChildNode
@NotNull public @NotNull NodeState getChildNode(@NotNull @NotNull String name) throws IllegalArgumentException
Description copied from interface:NodeStateReturns the named, possibly non-existent, child node. Use theNodeState.exists()method on the returned child node to determine whether the node exists or not.- Parameters:
name- name of the child node to return- Returns:
- named child node
- Throws:
IllegalArgumentException- if the given name string is is empty or contains a forward slash character
-
getChildNodeEntries
@NotNull public @NotNull Iterable<? extends ChildNodeEntry> getChildNodeEntries()
Description copied from interface:NodeStateReturns the iterable child node entries of this instance. 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.Note on cost and performance: while it is possible to iterate over all child
NodeStates with the two methodsNodeState.getChildNodeNames()andNodeState.getChildNode(String), this method is considered more efficient because an implementation can potentially perform the retrieval of the name andNodeStatein one call. This results in O(n) vs. O(n log n) when iterating over the child node names and then look up theNodeStateby name.- Returns:
- child node entries in some stable order
-
builder
@NotNull public @NotNull NodeBuilder builder()
Description copied from interface:NodeStateReturns a builder for constructing a new node state based on this state, i.e. starting with all the properties and child nodes of this state.- Returns:
- node builder based on this state
-
getProperty
public PropertyState getProperty(@NotNull @NotNull String name)
Description copied from interface:NodeStateReturns the named property, ornullif no such property exists.- Specified by:
getPropertyin interfaceNodeState- Overrides:
getPropertyin classAbstractNodeState- Parameters:
name- name of the property to return- Returns:
- named property, or
nullif not found
-
getPropertyCount
public long getPropertyCount()
Description copied from interface:NodeStateReturns the number of properties of this node.- Specified by:
getPropertyCountin interfaceNodeState- Overrides:
getPropertyCountin classAbstractNodeState- Returns:
- number of properties
-
hasProperty
public boolean hasProperty(@NotNull @NotNull String name)Description copied from interface:NodeStateChecks whether the named property exists. The implementation is equivalent togetProperty(name) != null, but may be optimized to avoid having to load the property value.- Specified by:
hasPropertyin interfaceNodeState- Overrides:
hasPropertyin classAbstractNodeState- Parameters:
name- property name- Returns:
trueif the named property exists,falseotherwise
-
getBoolean
public boolean getBoolean(@NotNull @NotNull String name)Description copied from interface:NodeStateReturns the boolean value of the named property. The implementation is equivalent to the following code, but may be optimized.PropertyState property = state.getProperty(name); return property != null && property.getType() == Type.BOOLEAN && property.getValue(Type.BOOLEAN);- Specified by:
getBooleanin interfaceNodeState- Overrides:
getBooleanin classAbstractNodeState- Parameters:
name- property name- Returns:
- boolean value of the named property, or
false
-
getLong
public long getLong(String name)
Description copied from interface:NodeStateReturns the long value of the named property. The implementation is equivalent to the following code, but may be optimized.PropertyState property = state.getProperty(name); if (property != null && property.getType() == Type.LONG) { return property.getValue(Type.LONG); } else { return 0; }- Specified by:
getLongin interfaceNodeState- Overrides:
getLongin classAbstractNodeState- Parameters:
name- property name- Returns:
- long value of the named property, or zero
-
getString
public String getString(String name)
Description copied from interface:NodeStateReturns the string value of the named property. The implementation is equivalent to the following code, but may be optimized.PropertyState property = state.getProperty(name); if (property != null && property.getType() == Type.STRING) { return property.getValue(Type.STRING); } else { return null; }- Specified by:
getStringin interfaceNodeState- Overrides:
getStringin classAbstractNodeState- Parameters:
name- property name- Returns:
- string value of the named property, or
null
-
getStrings
@NotNull public @NotNull Iterable<String> getStrings(@NotNull @NotNull String name)
Description copied from interface:NodeStateReturns the string values of the named property. The implementation is equivalent to the following code, but may be optimized.PropertyState property = state.getProperty(name); if (property != null && property.getType() == Type.STRINGS) { return property.getValue(Type.STRINGS); } else { return Collections.emptyList(); }- Specified by:
getStringsin interfaceNodeState- Overrides:
getStringsin classAbstractNodeState- Parameters:
name- property name- Returns:
- string values of the named property, or an empty collection
-
getName
public String getName(@NotNull @NotNull String name)
Description copied from interface:NodeStateReturns the name value of the named property. The implementation is equivalent to the following code, but may be optimized.PropertyState property = state.getProperty(name); if (property != null && property.getType() == Type.NAME) { return property.getValue(Type.NAME); } else { return null; }- Specified by:
getNamein interfaceNodeState- Overrides:
getNamein classAbstractNodeState- Parameters:
name- property name- Returns:
- name value of the named property, or
null
-
getNames
@NotNull public @NotNull Iterable<String> getNames(@NotNull @NotNull String name)
Description copied from interface:NodeStateReturns the name values of the named property. The implementation is equivalent to the following code, but may be optimized.PropertyState property = state.getProperty(name); if (property != null && property.getType() == Type.NAMES) { return property.getValue(Type.NAMES); } else { return Collections.emptyList(); }- Specified by:
getNamesin interfaceNodeState- Overrides:
getNamesin classAbstractNodeState- Parameters:
name- property name- Returns:
- name values of the named property, or an empty collection
-
getChildNodeCount
public long getChildNodeCount(long max)
Description copied from interface:NodeStateReturns the number of iterable child nodes of this node.If an implementation knows 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).
- Specified by:
getChildNodeCountin interfaceNodeState- Overrides:
getChildNodeCountin classAbstractNodeState- Parameters:
max- the maximum number of entries to traverse- Returns:
- number of iterable child nodes
-
getChildNodeNames
public Iterable<String> getChildNodeNames()
Description copied from interface:NodeStateReturns the names of all iterable child nodes.- Specified by:
getChildNodeNamesin interfaceNodeState- Overrides:
getChildNodeNamesin classAbstractNodeState- Returns:
- child node names in some stable order
-
-