Class DBSTransactionState

  • All Implemented Interfaces:
    AutoCloseable, LockManager

    public class DBSTransactionState
    extends Object
    implements LockManager, AutoCloseable
    Transactional state for a session.

    Until save() is called, data lives in the transient map.

    Upon save, data is written to the repository connection.

    If the connection is transactional, usual behavior occurs.

    If the connection is not transactional, then at this means that other sessions can read uncommitted data. To allow rollback, save data is also kept in an undo log in order for rollback to be possible. On commit, the undo log is forgotten. On rollback, the undo log is replayed.

    Since:
    5.9.4
    • Field Detail

      • READ_ACL_RECURSION_KEYS

        protected static final Set<String> READ_ACL_RECURSION_KEYS
        Keys used when computing Read ACLs.
      • transientCreated

        protected Set<String> transientCreated
        Ids of documents created but not yet saved.
      • userChangeIds

        protected final Set<Serializable> userChangeIds
        Document ids modified as "user changes", which means that a change token should be checked.
        Since:
        9.2
      • disabledForTestingPurpose

        protected Boolean disabledForTestingPurpose
        For test purpose only.
        Since:
        2023.0
      • undoLog

        protected Map<String,​State> undoLog
        Undo log.

        A map of document ids to null or State. The value is null when the document has to be deleted when applying the undo log. Otherwise the value is a State. If the State contains the key KEY_UNDOLOG_CREATE then the state must be re-created completely when applying the undo log, otherwise just applied as an update.

        Null when there is no active transaction.

      • browsePermissions

        protected final Set<String> browsePermissions
      • disableReadVersionPermission

        protected final boolean disableReadVersionPermission
    • Method Detail

      • close

        public void close()
        Specified by:
        close in interface AutoCloseable
        Since:
        11.1
      • getRootId

        public String getRootId()
        Since:
        11.1
      • newTransientState

        protected DBSDocumentState newTransientState​(State state)
        New transient state for something just read from the repository.
      • getStateForUpdate

        public DBSDocumentState getStateForUpdate​(String id)
        Returns a state and marks it as transient, because it's about to be modified or returned to user code (where it may be modified).
      • getStateForRead

        public State getStateForRead​(String id)
        Returns a state which won't be modified.
      • exists

        public boolean exists​(String id)
        Returns whether or not the document with given id exists in the storage.
        Since:
        2021.12
      • getStatesForUpdate

        public List<DBSDocumentState> getStatesForUpdate​(Collection<String> ids)
        Returns states and marks them transient, because they're about to be returned to user code (where they may be modified).
      • hasChild

        public boolean hasChild​(String parentId,
                                String name)
      • getChildrenStates

        public List<DBSDocumentState> getChildrenStates​(String parentId,
                                                        boolean excludeSpecialChildren,
                                                        boolean excludeRegularChildren)
      • getChildrenIds

        public List<String> getChildrenIds​(String parentId,
                                           boolean excludeSpecialChildren,
                                           boolean excludeRegularChildren)
      • hasChildren

        public boolean hasChildren​(String parentId)
      • getAncestorIds

        protected Object[] getAncestorIds​(String id)
        Gets ancestors including id itself.
      • copy

        public DBSDocumentState copy​(String id)
        Copies the document into a newly-created object.

        The copy is automatically saved.

      • updateAncestors

        public void updateAncestors​(String id,
                                    int ndel,
                                    Object[] ancestorIds)
        Updates ancestors recursively after a move.

        Recursing from given doc, replace the first ndel ancestors with those passed.

        Doesn't check transient (assumes save is done). The modifications are automatically saved.

      • getReadAclsAsyncThreshold

        protected int getReadAclsAsyncThreshold()
      • updateTreeReadAcls

        public void updateTreeReadAcls​(String id)
        Updates the Read ACLs recursively on a document.
      • isUnderSyncLimit

        protected boolean isUnderSyncLimit​(int limit,
                                           Set<String> ids)
      • updateReadACLs

        public void updateReadACLs​(Collection<String> docIds)
        Updates the Read ACLs on a document (not recursively), bypassing transient space and caches for the document itself (not the ancestors, needed for ACL inheritance and for which caching is useful).
      • updateDocumentReadAcls

        protected void updateDocumentReadAcls​(String id)
        Updates the Read ACLs on a document (not recursively)
      • updateDocumentReadAclsNoCache

        protected void updateDocumentReadAclsNoCache​(String id)
        Updates the Read ACLs on a document, without polluting caches.

        When fetching parents recursively to compute inheritance, the regular transient space and repository caching are used.

      • getReadACL

        @Deprecated
        protected String[] getReadACL​(State state)
        Deprecated.
        since 2021.39 use materializedKeys(State) instead
        Gets the Read ACL (flat list of users having browse permission, including inheritance) on a document.
      • materializedKeys

        protected State materializedKeys​(State state)
        Returns materialized keys for a state: - Read ACL (flat list of users having browse permission, including inheritance) on a document - Ancestor ids
      • getLock

        public Lock getLock​(String id)
        Description copied from interface: LockManager
        Gets the lock on a document.

        If the document does not exist, null is returned.

        Specified by:
        getLock in interface LockManager
        Parameters:
        id - the document id
        Returns:
        the existing lock, or null when there is no lock
        Since:
        11.1
      • removeLock

        public Lock removeLock​(String id,
                               String owner)
        Description copied from interface: LockManager
        Removes the lock from a document.

        The previous lock is returned.

        If owner is null then the lock is unconditionally removed.

        If owner is not null, it must match the existing lock owner for the lock to be removed. If it doesn't match, the returned lock will return true for Lock.getFailed().

        Specified by:
        removeLock in interface LockManager
        Parameters:
        id - the document id
        owner - the owner to check, or null for no check
        Returns:
        the previous lock (may be null), with a failed flag if locking failed
        Since:
        11.1
      • removeStates

        public void removeStates​(Set<String> ids)
        Removes a list of documents.

        Called after a save() has been done.

      • markUserChange

        public void markUserChange​(String id)
      • save

        public void save()
        Writes transient state to database.

        An undo log is kept in order to rollback the transaction later if needed.

      • updateChangeToken

        protected static Long updateChangeToken​(Long changeToken)
      • applyUndoLog

        protected void applyUndoLog()
      • updateProxies

        protected void updateProxies()
        Checks if the changed documents are proxy targets, and updates the proxies if that's the case.
      • updateProxy

        protected void updateProxy​(DBSDocumentState target,
                                   String proxyId)
        Updates the state of a proxy based on its target.
      • isProxySpecific

        protected boolean isProxySpecific​(String key,
                                          SchemaManager schemaManager)
        Things that we don't touch on a proxy when updating it.
      • updateDenormalizedState

        protected void updateDenormalizedState()
      • isBlobKeysDisabledForTestingPurpose

        protected boolean isBlobKeysDisabledForTestingPurpose()
        For test purpose only.
        Since:
        2023.0
      • begin

        public void begin()
        Called when created in a transaction.
        Since:
        7.4
      • commit

        public void commit()
        Saves and flushes to database.
      • rollback

        public void rollback()
        Rolls back the save state by applying the undo log.
      • clearTransient

        protected void clearTransient()
      • getFulltextWorks

        protected List<Work> getFulltextWorks()
        Gets the fulltext updates to do. Called at save() time.
        Returns:
        a list of Work instances to schedule post-commit.
      • markIndexingInProgress

        protected void markIndexingInProgress​(Set<String> ids)
      • findDirtyDocuments

        protected void findDirtyDocuments​(Set<String> docsWithDirtyStrings,
                                          Set<String> docsWithDirtyBinaries)
        Finds the documents having dirty text or dirty binaries that have to be reindexed as fulltext.
        Parameters:
        docsWithDirtyStrings - set of ids, updated by this method
        docsWithDirtyBinaries - set of ids, updated by this method
      • scheduleWork

        protected void scheduleWork​(List<Work> works)