Class NodeDocument
- java.lang.Object
-
- org.apache.jackrabbit.oak.plugins.document.Document
-
- org.apache.jackrabbit.oak.plugins.document.NodeDocument
-
- All Implemented Interfaces:
CacheValue
public final class NodeDocument extends Document
A document storing data about a node.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
NodeDocument.SplitDocType
A document which is created from splitting a main document can be classified into multiple types depending on the content i.e.
-
Field Summary
Fields Modifier and Type Field Description static String
COLLISIONS
Revision collision markers set by commits with modifications, which overlap with un-merged branch commits.static String
DELETED_ONCE
Flag indicating that whether this node was ever deleted.static String
HAS_BINARY_FLAG
static long
HAS_BINARY_VAL
static String
MAX_ID_VALUE
All NodeDocument ID value would be less than this value It can be used as endKey in DocumentStore#query methodsstatic String
MIN_ID_VALUE
All NodeDocument ID value would be greater than this value It can be used as startKey in DocumentStore#query methodsstatic String
MODIFIED_IN_SECS
The modified time in seconds (5 second resolution).static NodeDocument
NULL
Marker document, which indicates the document does not exist.static String
PATH
The node path, in case the id can not be converted to a path.static String
SD_MAX_REV_TIME_IN_SECS
Property name which refers to timestamp (long) of the latest revision kept in the documentstatic String
SD_TYPE
Defines the type of split document.
-
Constructor Summary
Constructors Constructor Description NodeDocument(@NotNull DocumentStore store, long creationTime)
Required for serialization
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
addCollision(@NotNull UpdateOp op, @NotNull Revision revision, @NotNull Revision other)
Add a collision marker for the givenrevision
.String
asString()
boolean
containsRevision(@NotNull Revision revision)
Returnstrue
if this document contains an entry for the givenrevision
in theREVISIONS
map.static NodeDocument
fromString(DocumentStore store, String s)
@Nullable Path
getCommitRootPath(Revision revision)
Returns the commit root path for the givenrevision
ornull
if this document does not have a commit root entry for the givenrevision
.long
getCreated()
long
getLastCheckTime()
Returns the last time when this object was checked for consistency.@NotNull Map<Integer,Revision>
getLastRev()
@Nullable Revision
getLiveRevision(RevisionContext context, RevisionVector readRevision, Map<Revision,String> validRevisions, org.apache.jackrabbit.oak.plugins.document.LastRevs lastRevs)
Get the earliest (oldest) revision where the node was alive at or before the provided revision, if the node was alive at the given revision.@NotNull Set<Revision>
getLocalBranchCommits()
Returns the branch commit entries on this document (BRANCH_COMMITS
).@NotNull Path
getMainPath()
Returns the path of the main document if this document is part of a _prev history tree.@Nullable Long
getModified()
See alsoMODIFIED_IN_SECS
.static long
getModifiedInSecs(long timestamp)
Return time in seconds with 5 second resolution@Nullable DocumentNodeState
getNodeAtRevision(@NotNull DocumentNodeStore nodeStore, @NotNull RevisionVector readRevision, @Nullable Revision lastModified)
Returns aDocumentNodeState
as seen at the givenreadRevision
.@NotNull Path
getPath()
NodeDocument.SplitDocType
getSplitDocType()
Determines the type of split document@NotNull Map<Revision,String>
getValueMap(@NotNull String key)
Gets the value map for the given key.boolean
hasAllRevisionLessThan(long maxRevisionTime)
Checks if revision time of all entries in this document is less than the passed timeboolean
hasBeenModifiedSince(long lastModifiedTime)
Checks if this document has been modified after the given lastModifiedTimeboolean
hasBinary()
boolean
hasChildren()
Returnstrue
if this node possibly has children.static void
hasLastRev(@NotNull UpdateOp op, @NotNull Revision revision)
static boolean
isCommitRootEntry(String name)
static boolean
isDeletedEntry(String name)
static boolean
isLastRevEntry(String name)
static boolean
isRevisionsEntry(String name)
boolean
isSplitDocument()
Determines if this document is a split documentvoid
markUpToDate(long checkTime)
Mark this instance as up-to-date (matches the state in persistence store).static void
removeBranchCommit(@NotNull UpdateOp op, @NotNull Revision revision)
static void
removeCollision(@NotNull UpdateOp op, @NotNull Revision revision)
static void
removeCommitRoot(@NotNull UpdateOp op, @NotNull Revision revision)
static void
removeDeleted(@NotNull UpdateOp op, @NotNull Revision revision)
static void
removePrevious(@NotNull UpdateOp op, @NotNull org.apache.jackrabbit.oak.plugins.document.Range range)
static void
removePrevious(@NotNull UpdateOp op, @NotNull Revision revision)
static void
removeRevision(@NotNull UpdateOp op, @NotNull Revision revision)
static void
removeStalePrevious(@NotNull UpdateOp op, @NotNull Revision revision)
static void
setBranchCommit(@NotNull UpdateOp op, @NotNull Revision revision)
static void
setChildrenFlag(@NotNull UpdateOp op, boolean hasChildNode)
static void
setCommitRoot(@NotNull UpdateOp op, @NotNull Revision revision, int commitRootDepth)
static void
setDeleted(@NotNull UpdateOp op, @NotNull Revision revision, boolean deleted)
static void
setDeletedOnce(@NotNull UpdateOp op)
static void
setHasBinary(@NotNull UpdateOp op)
static void
setLastRev(@NotNull UpdateOp op, @NotNull Revision revision)
static void
setModified(@NotNull UpdateOp op, @NotNull Revision revision)
static void
setPrevious(@NotNull UpdateOp op, @NotNull org.apache.jackrabbit.oak.plugins.document.Range range)
static void
setRevision(@NotNull UpdateOp op, @NotNull Revision revision, @NotNull String commitValue)
static void
setStalePrevious(@NotNull UpdateOp op, @NotNull Revision revision, int height)
static void
setSweepRevision(@NotNull UpdateOp op, @NotNull Revision revision)
@NotNull Iterable<UpdateOp>
split(@NotNull RevisionContext context, @NotNull RevisionVector head, @NotNull Function<String,Long> binarySize)
Returns update operations to split this document.static void
unsetCommitRoot(@NotNull UpdateOp op, @NotNull Revision revision)
static void
unsetRevision(@NotNull UpdateOp op, @NotNull Revision revision)
boolean
wasDeletedOnce()
Returnstrue
if this document was ever deleted in past.
-
-
-
Field Detail
-
NULL
public static final NodeDocument NULL
Marker document, which indicates the document does not exist.
-
MIN_ID_VALUE
public static final String MIN_ID_VALUE
All NodeDocument ID value would be greater than this value It can be used as startKey in DocumentStore#query methods- See Also:
- Constant Field Values
-
MAX_ID_VALUE
public static final String MAX_ID_VALUE
All NodeDocument ID value would be less than this value It can be used as endKey in DocumentStore#query methods- See Also:
- Constant Field Values
-
COLLISIONS
public static final String COLLISIONS
Revision collision markers set by commits with modifications, which overlap with un-merged branch commits. Key: revision, value: always true- See Also:
- Constant Field Values
-
MODIFIED_IN_SECS
public static final String MODIFIED_IN_SECS
The modified time in seconds (5 second resolution).- See Also:
- Constant Field Values
-
DELETED_ONCE
public static final String DELETED_ONCE
Flag indicating that whether this node was ever deleted. Its just used as a hint. If set to true then it indicates that node was once deleted.Note that a true value does not mean that node should be considered deleted as it might have been resurrected in later revision. Further note that it might get reset by maintenance tasks once they discover that it indeed was resurrected.
- See Also:
- Constant Field Values
-
PATH
public static final String PATH
The node path, in case the id can not be converted to a path.- See Also:
- Constant Field Values
-
HAS_BINARY_FLAG
public static final String HAS_BINARY_FLAG
- See Also:
- Constant Field Values
-
SD_TYPE
public static final String SD_TYPE
Defines the type of split document. Its value is an integer whose value is defined as per- See Also:
NodeDocument.SplitDocType
, Constant Field Values
-
SD_MAX_REV_TIME_IN_SECS
public static final String SD_MAX_REV_TIME_IN_SECS
Property name which refers to timestamp (long) of the latest revision kept in the document- See Also:
- Constant Field Values
-
HAS_BINARY_VAL
public static final long HAS_BINARY_VAL
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
NodeDocument
public NodeDocument(@NotNull @NotNull DocumentStore store, long creationTime)
Required for serialization- Parameters:
store
- the document store.creationTime
- time at which it was created. Would be different from current time in case of being resurrected from a serialized for
-
-
Method Detail
-
getModifiedInSecs
public static long getModifiedInSecs(long timestamp)
Return time in seconds with 5 second resolution- Parameters:
timestamp
- time in millis to convert- Returns:
- the time in seconds with the given resolution.
-
getValueMap
@NotNull public @NotNull Map<Revision,String> getValueMap(@NotNull @NotNull String key)
Gets the value map for the given key. This method is similar toDocument.get(String)
but will always return a value map. The returned value map may span multiple documents if the values of the givenkey
were split off toPREVIOUS
documents.- Parameters:
key
- a string key.- Returns:
- the map associated with the key.
-
getCreated
public long getCreated()
- Returns:
- the system time this object was created.
-
getModified
@Nullable public @Nullable Long getModified()
See alsoMODIFIED_IN_SECS
.- Returns:
- the time in seconds this document was last modified with five
seconds precision. Returns
null
if none is set.
-
hasChildren
public boolean hasChildren()
Returnstrue
if this node possibly has children. If false then that indicates that there are no child- Returns:
true
if this node has children
-
wasDeletedOnce
public boolean wasDeletedOnce()
Returnstrue
if this document was ever deleted in past.
-
hasBeenModifiedSince
public boolean hasBeenModifiedSince(long lastModifiedTime)
Checks if this document has been modified after the given lastModifiedTime- Parameters:
lastModifiedTime
- time to compare against in millis- Returns:
true
if this document was modified after the given lastModifiedTime
-
hasAllRevisionLessThan
public boolean hasAllRevisionLessThan(long maxRevisionTime)
Checks if revision time of all entries in this document is less than the passed time- Parameters:
maxRevisionTime
- timemstamp (in millis) of revision to check- Returns:
true
if timestamp of maximum revision stored in this document is less than than the passed revision timestamp
-
isSplitDocument
public boolean isSplitDocument()
Determines if this document is a split document- Returns:
true
if this document is a split document
-
getSplitDocType
public NodeDocument.SplitDocType getSplitDocType()
Determines the type of split document- Returns:
- type of Split Document
-
markUpToDate
public void markUpToDate(long checkTime)
Mark this instance as up-to-date (matches the state in persistence store).- Parameters:
checkTime
- time at which the check was performed
-
getLastCheckTime
public long getLastCheckTime()
Returns the last time when this object was checked for consistency.- Returns:
- the last check time
-
hasBinary
public boolean hasBinary()
-
getMainPath
@NotNull public @NotNull Path getMainPath()
Returns the path of the main document if this document is part of a _prev history tree. Otherwise this method simply returnsgetPath()
.- Returns:
- the path of the main document.
-
getLastRev
@NotNull public @NotNull Map<Integer,Revision> getLastRev()
- Returns:
- a map of the last known revision for each clusterId.
-
containsRevision
public boolean containsRevision(@NotNull @NotNull Revision revision)
Returnstrue
if this document contains an entry for the givenrevision
in theREVISIONS
map. Please note that an entry in theREVISIONS
map does not necessarily mean the the revision is committed. UseRevisionContext.getCommitValue(Revision, NodeDocument)
to get the commit state of a revision.- Parameters:
revision
- the revision to check.- Returns:
true
if this document contains the given revision.
-
getCommitRootPath
@Nullable public @Nullable Path getCommitRootPath(Revision revision)
Returns the commit root path for the givenrevision
ornull
if this document does not have a commit root entry for the givenrevision
.- Parameters:
revision
- a revision.- Returns:
- the commit root path or
null
.
-
getNodeAtRevision
@Nullable public @Nullable DocumentNodeState getNodeAtRevision(@NotNull @NotNull DocumentNodeStore nodeStore, @NotNull @NotNull RevisionVector readRevision, @Nullable @Nullable Revision lastModified)
Returns aDocumentNodeState
as seen at the givenreadRevision
.- Parameters:
nodeStore
- the node store.readRevision
- the read revision.lastModified
- the revision when this node was last modified, but the value is potentially not yet reflected in this document. SeeRevisionContext.getPendingModifications()
.- Returns:
- the node or
null
if the node doesn't exist at the given read revision.
-
getLiveRevision
@Nullable public @Nullable Revision getLiveRevision(RevisionContext context, RevisionVector readRevision, Map<Revision,String> validRevisions, org.apache.jackrabbit.oak.plugins.document.LastRevs lastRevs)
Get the earliest (oldest) revision where the node was alive at or before the provided revision, if the node was alive at the given revision.- Parameters:
context
- the revision contextreadRevision
- the read revisionvalidRevisions
- the map of revisions to commit value already checked against readRevision and considered valid.lastRevs
- to keep track of the last modification.- Returns:
- the earliest revision, or null if the node is deleted at the given revision
-
split
@NotNull public @NotNull Iterable<UpdateOp> split(@NotNull @NotNull RevisionContext context, @NotNull @NotNull RevisionVector head, @NotNull @NotNull Function<String,Long> binarySize)
Returns update operations to split this document. The implementation may decide to not return any operations if no splitting is required. A caller must explicitly pass a head revision even though it is available through theRevisionContext
. The given head revision must reflect a head state beforedoc
was retrieved from the document store. This is important in order to maintain consistency. See OAK-3081 for details.- Parameters:
context
- the revision context.head
- the head revision before this document was retrieved from the document store.binarySize
- a function that returns the binary size of the given JSON property value String.- Returns:
- the split operations, whereby the last updateOp is guaranteed to be the update of the main document (unless the entire list is empty)
-
getLocalBranchCommits
@NotNull public @NotNull Set<Revision> getLocalBranchCommits()
Returns the branch commit entries on this document (BRANCH_COMMITS
). This method does not consider previous documents, but only returns the entries on this document.
-
setChildrenFlag
public static void setChildrenFlag(@NotNull @NotNull UpdateOp op, boolean hasChildNode)
-
setModified
public static void setModified(@NotNull @NotNull UpdateOp op, @NotNull @NotNull Revision revision)
-
setRevision
public static void setRevision(@NotNull @NotNull UpdateOp op, @NotNull @NotNull Revision revision, @NotNull @NotNull String commitValue)
-
unsetRevision
public static void unsetRevision(@NotNull @NotNull UpdateOp op, @NotNull @NotNull Revision revision)
-
isRevisionsEntry
public static boolean isRevisionsEntry(String name)
-
isCommitRootEntry
public static boolean isCommitRootEntry(String name)
-
isDeletedEntry
public static boolean isDeletedEntry(String name)
-
isLastRevEntry
public static boolean isLastRevEntry(String name)
-
removeRevision
public static void removeRevision(@NotNull @NotNull UpdateOp op, @NotNull @NotNull Revision revision)
-
addCollision
public static void addCollision(@NotNull @NotNull UpdateOp op, @NotNull @NotNull Revision revision, @NotNull @NotNull Revision other)
Add a collision marker for the givenrevision
.- Parameters:
op
- the update operation.revision
- the commit for which a collision was detected.other
- the revision for the commit, which detected the collision.
-
removeCollision
public static void removeCollision(@NotNull @NotNull UpdateOp op, @NotNull @NotNull Revision revision)
-
setLastRev
public static void setLastRev(@NotNull @NotNull UpdateOp op, @NotNull @NotNull Revision revision)
-
setCommitRoot
public static void setCommitRoot(@NotNull @NotNull UpdateOp op, @NotNull @NotNull Revision revision, int commitRootDepth)
-
removeCommitRoot
public static void removeCommitRoot(@NotNull @NotNull UpdateOp op, @NotNull @NotNull Revision revision)
-
unsetCommitRoot
public static void unsetCommitRoot(@NotNull @NotNull UpdateOp op, @NotNull @NotNull Revision revision)
-
setDeleted
public static void setDeleted(@NotNull @NotNull UpdateOp op, @NotNull @NotNull Revision revision, boolean deleted)
-
setDeletedOnce
public static void setDeletedOnce(@NotNull @NotNull UpdateOp op)
-
removeDeleted
public static void removeDeleted(@NotNull @NotNull UpdateOp op, @NotNull @NotNull Revision revision)
-
setPrevious
public static void setPrevious(@NotNull @NotNull UpdateOp op, @NotNull @NotNull org.apache.jackrabbit.oak.plugins.document.Range range)
-
removePrevious
public static void removePrevious(@NotNull @NotNull UpdateOp op, @NotNull @NotNull org.apache.jackrabbit.oak.plugins.document.Range range)
-
removePrevious
public static void removePrevious(@NotNull @NotNull UpdateOp op, @NotNull @NotNull Revision revision)
-
setStalePrevious
public static void setStalePrevious(@NotNull @NotNull UpdateOp op, @NotNull @NotNull Revision revision, int height)
-
removeStalePrevious
public static void removeStalePrevious(@NotNull @NotNull UpdateOp op, @NotNull @NotNull Revision revision)
-
setHasBinary
public static void setHasBinary(@NotNull @NotNull UpdateOp op)
-
setBranchCommit
public static void setBranchCommit(@NotNull @NotNull UpdateOp op, @NotNull @NotNull Revision revision)
-
removeBranchCommit
public static void removeBranchCommit(@NotNull @NotNull UpdateOp op, @NotNull @NotNull Revision revision)
-
setSweepRevision
public static void setSweepRevision(@NotNull @NotNull UpdateOp op, @NotNull @NotNull Revision revision)
-
hasLastRev
public static void hasLastRev(@NotNull @NotNull UpdateOp op, @NotNull @NotNull Revision revision)
-
getPath
@NotNull public @NotNull Path getPath()
-
asString
public String asString()
-
fromString
public static NodeDocument fromString(DocumentStore store, String s)
-
-