Package org.nuxeo.ecm.core.storage
Class BaseDocument<T extends StateAccessor>
- java.lang.Object
-
- org.nuxeo.ecm.core.storage.BaseDocument<T>
-
- All Implemented Interfaces:
Document
- Direct Known Subclasses:
DBSDocument
,SQLDocumentLive
public abstract class BaseDocument<T extends StateAccessor> extends Object implements Document
Base implementation for a Document.Knows how to read and write values. It is generic in terms of a base State class from which one can read and write values.
- Since:
- 7.3
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
BaseDocument.BlobWriteContext<T extends StateAccessor>
protected static class
BaseDocument.BlobWriteInfo<T extends StateAccessor>
protected class
BaseDocument.StateBlobAccessor
protected class
BaseDocument.Visit
-
Nested classes/interfaces inherited from interface org.nuxeo.ecm.core.model.Document
Document.BlobAccessor, Document.WriteContext
-
-
Field Summary
-
Constructor Summary
Constructors Constructor Description BaseDocument()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected boolean
allowNewRetention(Calendar current, Calendar retainUntil)
static String
buildUserVisibleChangeToken(Long sysChangeToken, Long changeToken)
Builds the user-visible change token from low-level change token and system change token information.protected static String
canonicalXPath(String xpath)
Canonicalizes a Nuxeo xpath.protected boolean
checkReadOnlyIgnoredWrite(Property property, T state)
Checks for ignored writes.protected static void
clearDirtyFlags(Property property)
protected BlobInfo
getBlobInfo(T state)
protected abstract T
getChild(T state, String name, Type type)
Gets a child state.protected abstract List<T>
getChildAsList(T state, String name)
Gets a child state which is a list.protected abstract T
getChildForWrite(T state, String name, Type type)
Gets a child state into which we will want to write data.protected abstract Lock
getDocumentLock()
Gets the lock from this recently created and unsaved document.protected String
getLegacyChangeToken(Calendar modified)
Gets the legacy change token for the given timestamp.Lock
getLock()
Gets the lock if one set on this document.protected abstract List<Schema>
getProxySchemas()
Gets the list of proxy schemas, if this is a proxy.protected Schema
getTopLevelSchema(Property property)
protected Blob
getValueBlob(T state, String xpath)
protected Object
getValueComplex(T state, ComplexType complexType, String xpath)
protected Object
getValueField(T state, Field field, String xpath)
protected Object
getValueObject(T state, String xpath)
Gets a value (may be complex/list) from the document at the given xpath.Document.WriteContext
getWriteContext()
Gets a write context for the current document.protected abstract String
internalName(String name)
Finds the internal name to use to refer to this property.boolean
isRetainable(String xp)
Can the property be put under retention or legal hold.boolean
isRetained(String xp)
Is the property under retention or legal hold.boolean
isUnderRetentionOrLegalHold()
Checks if the document has a retention date in the future or has a legal hold.protected static boolean
isVersionWritableProperty(String name)
protected void
readComplexProperty(T state, ComplexProperty complexProperty)
Reads state into a complex property.protected void
readComplexProperty(T state, ComplexProperty complexProperty, String xpath)
protected abstract Lock
removeDocumentLock(String owner)
Removes a lock from this recently created and unsaved document.Lock
removeLock(String owner)
Removes a lock from this document.protected void
setBlobInfo(T state, BlobInfo blobInfo)
protected abstract Lock
setDocumentLock(Lock lock)
Sets a lock on this recently created and unsaved document.Lock
setLock(Lock lock)
Sets a lock on this document.protected void
setPropertyBlobData(String xpath, String string)
protected void
setValueBlob(T state, Blob blob, String xpath)
protected void
setValueBlob(T state, Blob blob, String xpath, boolean gcOldBlob)
protected void
setValueComplex(T state, Field field, String xpath, Object value)
protected void
setValueField(T state, Field field, String xpath, Object value)
protected void
setValueObject(T state, String xpath, Object value)
Sets a value (may be complex/list) into the document at the given xpath.protected static Object[]
typedArray(Type type, Object[] array)
Copies the array with an appropriate class depending on the type.static Long
updateChangeToken(Long changeToken)
Updates a change token to its new value.protected abstract List<T>
updateList(T state, String name, Property property)
Update a list.protected abstract void
updateList(T state, String name, Field field, String xpath, List<Object> values)
Update a list.protected boolean
validateLegacyChangeToken(Calendar modified, String userVisibleChangeToken)
Validates that the passed user-visible change token is compatible with the current legacy change token.static boolean
validateUserVisibleChangeToken(Long sysChangeToken, Long changeToken, String userVisibleChangeToken)
Validates that the passed user-visible change token is compatible with the current change token.protected void
visitBlobs(T state, Consumer<Document.BlobAccessor> blobVisitor, Runnable markDirty)
Visits all the blobs of this document and calls the passed blob visitor on each one.protected boolean
writeComplexProperty(T state, ComplexProperty complexProperty, String xpath, boolean writeAll, boolean writeAllChildren, Document.WriteContext wc)
Writes state from a complex property.protected boolean
writeComplexProperty(T state, ComplexProperty complexProperty, Document.WriteContext writeContext)
Deprecated.protected boolean
writeDocumentPart(T state, DocumentPart dp, Document.WriteContext writeContext, boolean create)
Writes state from a document part.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.nuxeo.ecm.core.model.Document
addChild, addFacet, checkIn, checkOut, followTransition, getAllFacets, getAllowedStateTransitions, getBaseVersion, getBlobKeys, getChangeToken, getCheckinComment, getChild, getChildren, getChildrenIds, getFacets, getLastVersion, getLifeCyclePolicy, getLifeCycleState, getName, getParent, getPath, getPos, getPropertyValue, getRepositoryName, getRetainedProperties, getRetainUntil, getSession, getSourceDocument, getSystemProp, getTargetDocument, getType, getUUID, getValue, getVersion, getVersionCreationDate, getVersionLabel, getVersions, getVersionSeriesId, getVersionsIds, getWorkingCopy, hasChild, hasChildren, hasFacet, hasLegalHold, isCheckedOut, isEnforcedRecord, isFlexibleRecord, isFolder, isLatestMajorVersion, isLatestVersion, isMajorVersion, isProxy, isReadOnly, isRecord, isRetentionActive, isVersion, isVersionSeriesCheckedOut, makeFlexibleRecord, makeRecord, markUserChange, orderBefore, readDocumentPart, remove, remove, removeFacet, removeSingleton, replaceBlobDigest, restore, setCurrentLifeCycleState, setLegalHold, setLifeCyclePolicy, setPropertyValue, setReadOnly, setRetainUntil, setRetentionActive, setSystemProp, setTargetDocument, setValue, validateUserVisibleChangeToken, visitBlobs, writeDocumentPart, writeDocumentPart
-
-
-
-
Field Detail
-
LIST_INDEX_PATTERN
protected static final Pattern LIST_INDEX_PATTERN
-
EMPTY_STRING_ARRAY
public static final String[] EMPTY_STRING_ARRAY
-
BLOB_NAME
public static final String BLOB_NAME
- See Also:
- Constant Field Values
-
BLOB_MIME_TYPE
public static final String BLOB_MIME_TYPE
- See Also:
- Constant Field Values
-
BLOB_ENCODING
public static final String BLOB_ENCODING
- See Also:
- Constant Field Values
-
BLOB_DIGEST
public static final String BLOB_DIGEST
- See Also:
- Constant Field Values
-
BLOB_LENGTH
public static final String BLOB_LENGTH
- See Also:
- Constant Field Values
-
BLOB_DATA
public static final String BLOB_DATA
- See Also:
- Constant Field Values
-
DC_PREFIX
public static final String DC_PREFIX
- See Also:
- Constant Field Values
-
DC_ISSUED
public static final String DC_ISSUED
- See Also:
- Constant Field Values
-
DC_MODIFIED
public static final String DC_MODIFIED
- See Also:
- Constant Field Values
-
RELATED_TEXT_RESOURCES
public static final String RELATED_TEXT_RESOURCES
- See Also:
- Constant Field Values
-
RELATED_TEXT_ID
public static final String RELATED_TEXT_ID
- See Also:
- Constant Field Values
-
RELATED_TEXT
public static final String RELATED_TEXT
- See Also:
- Constant Field Values
-
FULLTEXT_JOBID_PROP
public static final String FULLTEXT_JOBID_PROP
- See Also:
- Constant Field Values
-
FULLTEXT_SIMPLETEXT_PROP
public static final String FULLTEXT_SIMPLETEXT_PROP
- See Also:
- Constant Field Values
-
FULLTEXT_BINARYTEXT_PROP
public static final String FULLTEXT_BINARYTEXT_PROP
- See Also:
- Constant Field Values
-
IS_TRASHED_PROP
public static final String IS_TRASHED_PROP
- See Also:
- Constant Field Values
-
MISC_LIFECYCLE_STATE_PROP
public static final String MISC_LIFECYCLE_STATE_PROP
- See Also:
- Constant Field Values
-
LOCK_OWNER_PROP
public static final String LOCK_OWNER_PROP
- See Also:
- Constant Field Values
-
LOCK_CREATED_PROP
public static final String LOCK_CREATED_PROP
- See Also:
- Constant Field Values
-
IS_RECORD_PROP
public static final String IS_RECORD_PROP
- Since:
- 11.1
- See Also:
- Constant Field Values
-
IS_FLEXIBLE_RECORD_PROP
public static final String IS_FLEXIBLE_RECORD_PROP
- Since:
- 2023.1
- See Also:
- Constant Field Values
-
RETAIN_UNTIL_PROP
public static final String RETAIN_UNTIL_PROP
- Since:
- 11.1
- See Also:
- Constant Field Values
-
HAS_LEGAL_HOLD_PROP
public static final String HAS_LEGAL_HOLD_PROP
- Since:
- 11.1
- See Also:
- Constant Field Values
-
RETAINED_PROPERTIES_PROP
public static final String RETAINED_PROPERTIES_PROP
- Since:
- 2021.32
- See Also:
- Constant Field Values
-
NON_CANONICAL_INDEX
protected static final Pattern NON_CANONICAL_INDEX
-
NO_DIRTY
protected static final Runnable NO_DIRTY
-
TOKEN_SEP
public static final String TOKEN_SEP
- See Also:
- Constant Field Values
-
-
Method Detail
-
getProxySchemas
protected abstract List<Schema> getProxySchemas()
Gets the list of proxy schemas, if this is a proxy.- Returns:
- the proxy schemas, or
null
-
getChild
protected abstract T getChild(T state, String name, Type type) throws PropertyException
Gets a child state.- Parameters:
state
- the parent statename
- the child nametype
- the child's type- Returns:
- the child state, or
null
if it doesn't exist - Throws:
PropertyException
-
getChildForWrite
protected abstract T getChildForWrite(T state, String name, Type type) throws PropertyException
Gets a child state into which we will want to write data.Creates it if needed.
- Parameters:
state
- the parent statename
- the child nametype
- the child's type- Returns:
- the child state, never
null
- Throws:
PropertyException
- Since:
- 7.4
-
getChildAsList
protected abstract List<T> getChildAsList(T state, String name) throws PropertyException
Gets a child state which is a list.- Parameters:
state
- the parent statename
- the child name- Returns:
- the child state, never
null
- Throws:
PropertyException
-
updateList
protected abstract void updateList(T state, String name, Field field, String xpath, List<Object> values) throws PropertyException
Update a list.- Parameters:
state
- the parent statename
- the child namefield
- the list element typexpath
- the xpath of this listvalues
- the values- Throws:
PropertyException
-
updateList
protected abstract List<T> updateList(T state, String name, Property property) throws PropertyException
Update a list.- Parameters:
state
- the parent statename
- the child nameproperty
- the property- Returns:
- the list of states to write
- Throws:
PropertyException
-
internalName
protected abstract String internalName(String name)
Finds the internal name to use to refer to this property.
-
canonicalXPath
protected static String canonicalXPath(String xpath)
Canonicalizes a Nuxeo xpath.Replaces
a/foo[123]/b
witha/123/b
- Parameters:
xpath
- the xpath- Returns:
- the canonicalized xpath.
-
typedArray
protected static Object[] typedArray(Type type, Object[] array)
Copies the array with an appropriate class depending on the type.
-
isVersionWritableProperty
protected static boolean isVersionWritableProperty(String name)
-
clearDirtyFlags
protected static void clearDirtyFlags(Property property)
-
checkReadOnlyIgnoredWrite
protected boolean checkReadOnlyIgnoredWrite(Property property, T state) throws PropertyException
Checks for ignored writes. May throw.- Throws:
PropertyException
-
getBlobInfo
protected BlobInfo getBlobInfo(T state) throws PropertyException
- Throws:
PropertyException
-
setBlobInfo
protected void setBlobInfo(T state, BlobInfo blobInfo) throws PropertyException
- Throws:
PropertyException
-
getValueObject
protected Object getValueObject(T state, String xpath) throws PropertyException
Gets a value (may be complex/list) from the document at the given xpath.- Throws:
PropertyException
-
getValueField
protected Object getValueField(T state, Field field, String xpath) throws PropertyException
- Throws:
PropertyException
-
getValueComplex
protected Object getValueComplex(T state, ComplexType complexType, String xpath) throws PropertyException
- Throws:
PropertyException
-
getValueBlob
protected Blob getValueBlob(T state, String xpath) throws PropertyException
- Throws:
PropertyException
-
setValueObject
protected void setValueObject(T state, String xpath, Object value) throws PropertyException
Sets a value (may be complex/list) into the document at the given xpath.- Throws:
PropertyException
-
setValueField
protected void setValueField(T state, Field field, String xpath, Object value) throws PropertyException
- Throws:
PropertyException
-
setValueComplex
protected void setValueComplex(T state, Field field, String xpath, Object value) throws PropertyException
- Throws:
PropertyException
-
setValueBlob
protected void setValueBlob(T state, Blob blob, String xpath) throws PropertyException
- Throws:
PropertyException
-
setValueBlob
protected void setValueBlob(T state, Blob blob, String xpath, boolean gcOldBlob) throws PropertyException
- Throws:
PropertyException
-
readComplexProperty
protected void readComplexProperty(T state, ComplexProperty complexProperty) throws PropertyException
Reads state into a complex property.- Throws:
PropertyException
-
readComplexProperty
protected void readComplexProperty(T state, ComplexProperty complexProperty, String xpath) throws PropertyException
- Throws:
PropertyException
-
getWriteContext
public Document.WriteContext getWriteContext()
Description copied from interface:Document
Gets a write context for the current document.- Specified by:
getWriteContext
in interfaceDocument
-
writeComplexProperty
@Deprecated protected boolean writeComplexProperty(T state, ComplexProperty complexProperty, Document.WriteContext writeContext) throws PropertyException
Deprecated.Writes state from a complex property.- Throws:
PropertyException
-
writeDocumentPart
protected boolean writeDocumentPart(T state, DocumentPart dp, Document.WriteContext writeContext, boolean create) throws PropertyException
Writes state from a document part.- Returns:
true
if something changed- Throws:
PropertyException
-
isRetainable
public boolean isRetainable(String xp)
Description copied from interface:Document
Can the property be put under retention or legal hold.- Specified by:
isRetainable
in interfaceDocument
- Parameters:
xp
- the xpath- Returns:
- true if the property is retainable
-
isRetained
public boolean isRetained(String xp)
Description copied from interface:Document
Is the property under retention or legal hold.- Specified by:
isRetained
in interfaceDocument
- Parameters:
xp
- the xpath- Returns:
- true if the property is retained and cannot be deleted/edited
-
writeComplexProperty
protected boolean writeComplexProperty(T state, ComplexProperty complexProperty, String xpath, boolean writeAll, boolean writeAllChildren, Document.WriteContext wc) throws PropertyException
Writes state from a complex property.Writes only properties that are dirty, unless writeAll is true in which case everything is written.
- Returns:
true
if something changed- Throws:
PropertyException
-
visitBlobs
protected void visitBlobs(T state, Consumer<Document.BlobAccessor> blobVisitor, Runnable markDirty) throws PropertyException
Visits all the blobs of this document and calls the passed blob visitor on each one.- Throws:
PropertyException
-
getLock
public Lock getLock()
Description copied from interface:Document
Gets the lock if one set on this document.
-
setLock
public Lock setLock(Lock lock)
Description copied from interface:Document
Sets a lock on this document.
-
removeLock
public Lock removeLock(String owner)
Description copied from interface:Document
Removes a lock from this document.- Specified by:
removeLock
in interfaceDocument
- Parameters:
owner
- the owner to check, ornull
for no check- Returns:
null
if there was no lock or if removal succeeded, or a lock if it blocks removal due to owner mismatch
-
getDocumentLock
protected abstract Lock getDocumentLock()
Gets the lock from this recently created and unsaved document.- Returns:
- the lock, or
null
if no lock is set - Since:
- 7.4
-
setDocumentLock
protected abstract Lock setDocumentLock(Lock lock)
Sets a lock on this recently created and unsaved document.- Parameters:
lock
- the lock to set- Returns:
null
if locking succeeded, or the existing lock if locking failed- Since:
- 7.4
-
removeDocumentLock
protected abstract Lock removeDocumentLock(String owner)
Removes a lock from this recently created and unsaved document.- Parameters:
owner
- the owner to check, ornull
for no check- Returns:
null
if there was no lock or if removal succeeded, or a lock if it blocks removal due to owner mismatch- Since:
- 7.4
-
buildUserVisibleChangeToken
public static String buildUserVisibleChangeToken(Long sysChangeToken, Long changeToken)
Builds the user-visible change token from low-level change token and system change token information.- Parameters:
sysChangeToken
- the system change tokenchangeToken
- the change token- Returns:
- the user-visible change token
- Since:
- 9.2
-
validateUserVisibleChangeToken
public static boolean validateUserVisibleChangeToken(Long sysChangeToken, Long changeToken, String userVisibleChangeToken)
Validates that the passed user-visible change token is compatible with the current change token.- Parameters:
sysChangeToken
- the system change tokenchangeToken
- the change tokenuserVisibleChangeToken
- the user-visible change token- Returns:
false
if the change token is not valid- Since:
- 9.2
-
validateLegacyChangeToken
protected boolean validateLegacyChangeToken(Calendar modified, String userVisibleChangeToken)
Validates that the passed user-visible change token is compatible with the current legacy change token.- Parameters:
modified
- thedc:modified
timestampuserVisibleChangeToken
- the user-visible change token- Returns:
false
if the change token is not valid- Since:
- 9.2
-
getLegacyChangeToken
protected String getLegacyChangeToken(Calendar modified)
Gets the legacy change token for the given timestamp.- Parameters:
modified
- thedc:modified
timestamp- Returns:
- the legacy change token
- Since:
- 9.2
-
updateChangeToken
public static Long updateChangeToken(Long changeToken)
Updates a change token to its new value.- Parameters:
changeToken
- the change token (notnull
)- Returns:
- the updated change token
- Since:
- 9.2
-
isUnderRetentionOrLegalHold
public boolean isUnderRetentionOrLegalHold()
Description copied from interface:Document
Checks if the document has a retention date in the future or has a legal hold.- Specified by:
isUnderRetentionOrLegalHold
in interfaceDocument
- Returns:
true
if the document has a retention date in the future or if it has a legal hold,false
otherwise- See Also:
Document.getRetainUntil()
,Document.hasLegalHold()
-
-