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
  • Field Details

  • Constructor Details

    • BaseDocument

      public BaseDocument()
  • Method Details

    • 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 state
      name - the child name
      type - 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 state
      name - the child name
      type - 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 state
      name - 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 state
      name - the child name
      field - the list element type
      xpath - the xpath of this list
      values - 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 state
      name - the child name
      property - 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 with a/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
    • getTopLevelSchema

      protected Schema getTopLevelSchema(Property property)
      Gets the Schema at the top-level of the type hierarchy for this Property.
      Since:
      9.3
    • 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
    • setPropertyBlobData

      protected void setPropertyBlobData(String xpath, String string)
    • 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 interface Document
    • writeComplexProperty

      @Deprecated protected boolean writeComplexProperty(T state, ComplexProperty complexProperty, Document.WriteContext writeContext) throws PropertyException
      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 interface Document
      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 interface Document
      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.
      Specified by:
      getLock in interface Document
      Returns:
      the lock, or null if no lock is set
    • setLock

      public Lock setLock(Lock lock)
      Description copied from interface: Document
      Sets a lock on this document.
      Specified by:
      setLock in interface Document
      Parameters:
      lock - the lock to set
      Returns:
      null if locking succeeded, or the existing lock if locking failed
    • removeLock

      public Lock removeLock(String owner)
      Description copied from interface: Document
      Removes a lock from this document.
      Specified by:
      removeLock in interface Document
      Parameters:
      owner - the owner to check, or null 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, or null 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 token
      changeToken - 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 token
      changeToken - the change token
      userVisibleChangeToken - 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 - the dc:modified timestamp
      userVisibleChangeToken - 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 - the dc: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 (not null)
      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 interface Document
      Returns:
      true if the document has a retention date in the future or if it has a legal hold, false otherwise
      See Also:
    • allowNewRetention

      protected boolean allowNewRetention(Calendar current, Calendar retainUntil)