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 classBaseDocument.BlobWriteContext<T extends StateAccessor>protected static classBaseDocument.BlobWriteInfo<T extends StateAccessor>protected classBaseDocument.StateBlobAccessorprotected classBaseDocument.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 booleanallowNewRetention(Calendar current, Calendar retainUntil)static StringbuildUserVisibleChangeToken(Long sysChangeToken, Long changeToken)Builds the user-visible change token from low-level change token and system change token information.protected static StringcanonicalXPath(String xpath)Canonicalizes a Nuxeo xpath.protected booleancheckReadOnlyIgnoredWrite(Property property, T state)Checks for ignored writes.protected static voidclearDirtyFlags(Property property)protected BlobInfogetBlobInfo(T state)protected abstract TgetChild(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 TgetChildForWrite(T state, String name, Type type)Gets a child state into which we will want to write data.protected static DocumentBlobManagergetDocumentBlobManager()protected abstract LockgetDocumentLock()Gets the lock from this recently created and unsaved document.protected StringgetLegacyChangeToken(Calendar modified)Gets the legacy change token for the given timestamp.LockgetLock()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 SchemagetTopLevelSchema(Property property)protected BlobgetValueBlob(T state, String xpath)protected ObjectgetValueComplex(T state, ComplexType complexType, String xpath)protected ObjectgetValueField(T state, Field field, String xpath)protected ObjectgetValueObject(T state, String xpath)Gets a value (may be complex/list) from the document at the given xpath.Document.WriteContextgetWriteContext()Gets a write context for the current document.protected abstract StringinternalName(String name)Finds the internal name to use to refer to this property.booleanisRetainable(String xp)Can the property be put under retention or legal hold.booleanisRetained(String xp)Is the property under retention or legal hold.booleanisUnderRetentionOrLegalHold()Checks if the document has a retention date in the future or has a legal hold.protected static booleanisVersionWritableProperty(String name)protected static voidnotifySetRetainUntil(Document doc, Calendar retainUntil, Calendar previous)protected voidreadComplexProperty(T state, ComplexProperty complexProperty)Reads state into a complex property.protected voidreadComplexProperty(T state, ComplexProperty complexProperty, String xpath)protected abstract LockremoveDocumentLock(String owner)Removes a lock from this recently created and unsaved document.LockremoveLock(String owner)Removes a lock from this document.protected voidsetBlobInfo(T state, BlobInfo blobInfo)protected abstract LocksetDocumentLock(Lock lock)Sets a lock on this recently created and unsaved document.LocksetLock(Lock lock)Sets a lock on this document.protected voidsetPropertyBlobData(String xpath, String string)protected voidsetValueBlob(T state, Blob blob, String xpath)protected voidsetValueBlob(T state, Blob blob, String xpath, boolean gcOldBlob)protected voidsetValueComplex(T state, Field field, String xpath, Object value)protected voidsetValueField(T state, Field field, String xpath, Object value)protected voidsetValueObject(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 LongupdateChangeToken(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 voidupdateList(T state, String name, Field field, String xpath, List<Object> values)Update a list.protected booleanvalidateLegacyChangeToken(Calendar modified, String userVisibleChangeToken)Validates that the passed user-visible change token is compatible with the current legacy change token.static booleanvalidateUserVisibleChangeToken(Long sysChangeToken, Long changeToken, String userVisibleChangeToken)Validates that the passed user-visible change token is compatible with the current change token.protected voidvisitBlobs(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 booleanwriteComplexProperty(T state, ComplexProperty complexProperty, String xpath, boolean writeAll, boolean writeAllChildren, Document.WriteContext wc)Writes state from a complex property.protected booleanwriteComplexProperty(T state, ComplexProperty complexProperty, Document.WriteContext writeContext)Deprecated.protected booleanwriteDocumentPart(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
nullif 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]/bwitha/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:DocumentGets a write context for the current document.- Specified by:
getWriteContextin 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:
trueif something changed- Throws:
PropertyException
-
isRetainable
public boolean isRetainable(String xp)
Description copied from interface:DocumentCan the property be put under retention or legal hold.- Specified by:
isRetainablein interfaceDocument- Parameters:
xp- the xpath- Returns:
- true if the property is retainable
-
isRetained
public boolean isRetained(String xp)
Description copied from interface:DocumentIs the property under retention or legal hold.- Specified by:
isRetainedin 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:
trueif 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:DocumentGets the lock if one set on this document.
-
setLock
public Lock setLock(Lock lock)
Description copied from interface:DocumentSets a lock on this document.
-
removeLock
public Lock removeLock(String owner)
Description copied from interface:DocumentRemoves a lock from this document.- Specified by:
removeLockin interfaceDocument- Parameters:
owner- the owner to check, ornullfor no check- Returns:
nullif 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
nullif 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:
nullif 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, ornullfor no check- Returns:
nullif 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:
falseif 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:modifiedtimestampuserVisibleChangeToken- the user-visible change token- Returns:
falseif 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:modifiedtimestamp- 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:DocumentChecks if the document has a retention date in the future or has a legal hold.- Specified by:
isUnderRetentionOrLegalHoldin interfaceDocument- Returns:
trueif the document has a retention date in the future or if it has a legal hold,falseotherwise- See Also:
Document.getRetainUntil(),Document.hasLegalHold()
-
getDocumentBlobManager
protected static DocumentBlobManager getDocumentBlobManager()
-
-