Class BaseDocument<T extends StateAccessor>

  • 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
    • Constructor Detail

      • BaseDocument

        public BaseDocument()
    • 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 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)
      • getTopLevelSchema

        protected Schema getTopLevelSchema​(Property property)
        Gets the Schema at the top-level of the type hierarchy for this Property.
        Since:
        9.3
      • setPropertyBlobData

        protected void setPropertyBlobData​(String xpath,
                                           String string)
      • 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
      • 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
      • allowNewRetention

        protected boolean allowNewRetention​(Calendar current,
                                            Calendar retainUntil)