Class DBSTransactionState
- java.lang.Object
-
- org.nuxeo.ecm.core.storage.dbs.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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classDBSTransactionState.BlobKeysFinderIterates on aStateto find the blob keys.static classDBSTransactionState.ConditionalUpdatesLogic to get the conditions to use to match and update a change token.protected static classDBSTransactionState.DirtyPathsFinderIterates on a state diff to find the paths corresponding to dirty values.static classDBSTransactionState.FindReadAclsWorkDeprecated.since 2021.11 useUpdateReadAclsActioninsteadstatic classDBSTransactionState.UpdateReadAclsWorkDeprecated.since 2021.11 useUpdateReadAclsActioninstead
-
Field Summary
Fields Modifier and Type Field Description protected Set<String>browsePermissionsprotected DBSConnectionconnectionprotected BooleandisabledForTestingPurposeFor test purpose only.protected booleandisableReadVersionPermissionstatic StringREAD_ACL_ASYNC_ENABLED_DEFAULTstatic StringREAD_ACL_ASYNC_ENABLED_PROPERTYstatic StringREAD_ACL_ASYNC_THRESHOLD_DEFAULTstatic StringREAD_ACL_ASYNC_THRESHOLD_PROPERTYprotected static Set<String>READ_ACL_RECURSION_KEYSKeys used when computing Read ACLs.protected DBSRepositoryrepositoryprotected DBSSessionsessionprotected Set<String>transientCreatedIds of documents created but not yet saved.protected Map<String,DBSDocumentState>transientStatesRetrieved and created document state.protected Map<String,State>undoLogUndo log.protected Set<Serializable>userChangeIdsDocument ids modified as "user changes", which means that a change token should be checked.protected BaseSession.VersionAclModeversionAclMode
-
Constructor Summary
Constructors Constructor Description DBSTransactionState(DBSRepository repository, DBSSession session)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected voidapplyUndoLog()voidbegin()Called when created in a transaction.protected voidclearTransient()voidclose()voidcommit()Saves and flushes to database.protected voidcomputeBlobKeys(DBSDocumentState docState, DBSTransactionState.BlobKeysFinder blobKeysFinder)DBSDocumentStatecopy(String id)Copies the document into a newly-created object.DBSDocumentStatecreateChild(String id, String parentId, String name, Long pos, String typeName)booleanexists(String id)Returns whether or not the document with givenidexists in the storage.protected voidfindDirtyDocuments(Set<String> docsWithDirtyStrings, Set<String> docsWithDirtyBinaries)Finds the documents having dirty text or dirty binaries that have to be reindexed as fulltext.protected Object[]getAncestorIds(String id)Gets ancestors including id itself.List<String>getChildrenIds(String parentId)List<String>getChildrenIds(String parentId, boolean excludeSpecialChildren, boolean excludeRegularChildren)List<DBSDocumentState>getChildrenStates(String parentId)List<DBSDocumentState>getChildrenStates(String parentId, boolean excludeSpecialChildren, boolean excludeRegularChildren)DBSDocumentStategetChildState(String parentId, String name)protected DBSTransactionState.ConditionalUpdatesgetConditionalUpdateForChangeToken(DBSDocumentState docState)protected Stream<State>getDescendants(String id, Set<String> keys, int limit)protected List<Work>getFulltextWorks()Gets the fulltext updates to do.List<DBSDocumentState>getKeyValuedStates(String key, Object value)List<DBSDocumentState>getKeyValuedStates(String key1, Object value1, String key2, Object value2)LockgetLock(String id)Gets the lock on a document.protected String[]getReadACL(State state)Deprecated.since 2021.39 usematerializedKeys(State)insteadprotected intgetReadAclsAsyncThreshold()StringgetRootId()StategetStateForRead(String id)Returns a state which won't be modified.DBSDocumentStategetStateForUpdate(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).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).booleanhasChild(String parentId, String name)booleanhasChildren(String parentId)protected booleanisBlobKeysDisabledForTestingPurpose()For test purpose only.protected booleanisProxySpecific(String key, SchemaManager schemaManager)Things that we don't touch on a proxy when updating it.protected booleanisUnderSyncLimit(int limit, Set<String> ids)protected voidmarkIndexingInProgress(Set<String> ids)voidmarkUserChange(String id)protected StatematerializedKeys(State state)Returns materialized keys for a state: - Read ACL (flat list of users having browse permission, including inheritance) on a document - Ancestor idsprotected DBSDocumentStatenewTransientState(State state)New transient state for something just read from the repository.PartialList<Map<String,Serializable>>queryAndFetch(DBSExpressionEvaluator evaluator, OrderByClause orderByClause, boolean distinctDocuments, int limit, int offset, int countUpTo)LockremoveLock(String id, String owner)Removes the lock from a document.voidremoveStates(Set<String> ids)Removes a list of documents.voidrollback()Rolls back the save state by applying the undo log.voidsave()Writes transient state to database.protected voidscheduleWork(List<Work> works)ScrollResult<String>scroll(String scrollId)ScrollResult<String>scroll(DBSExpressionEvaluator evaluator, int batchSize, int keepAliveSeconds)LocksetLock(String id, Lock lock)Sets a lock on a document.voidupdateAncestors(String id, int ndel, Object[] ancestorIds)Updates ancestors recursively after a move.protected static LongupdateChangeToken(Long changeToken)protected voidupdateDenormalizedState()protected voidupdateDocumentReadAcls(String id)Updates the Read ACLs on a document (not recursively)protected voidupdateDocumentReadAclsNoCache(String id)Updates the Read ACLs on a document, without polluting caches.protected voidupdateProxies()Checks if the changed documents are proxy targets, and updates the proxies if that's the case.protected voidupdateProxies(DBSDocumentState target)protected voidupdateProxy(DBSDocumentState target, String proxyId)Updates the state of a proxy based on its target.voidupdateReadACLs(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).voidupdateTreeReadAcls(String id)Updates the Read ACLs recursively on a document.-
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.api.lock.LockManager
clearLockManagerCaches, closeLockManager
-
-
-
-
Field Detail
-
READ_ACL_RECURSION_KEYS
protected static final Set<String> READ_ACL_RECURSION_KEYS
Keys used when computing Read ACLs.
-
READ_ACL_ASYNC_ENABLED_PROPERTY
public static final String READ_ACL_ASYNC_ENABLED_PROPERTY
- See Also:
- Constant Field Values
-
READ_ACL_ASYNC_ENABLED_DEFAULT
public static final String READ_ACL_ASYNC_ENABLED_DEFAULT
- See Also:
- Constant Field Values
-
READ_ACL_ASYNC_THRESHOLD_PROPERTY
public static final String READ_ACL_ASYNC_THRESHOLD_PROPERTY
- See Also:
- Constant Field Values
-
READ_ACL_ASYNC_THRESHOLD_DEFAULT
public static final String READ_ACL_ASYNC_THRESHOLD_DEFAULT
- See Also:
- Constant Field Values
-
repository
protected final DBSRepository repository
-
connection
protected final DBSConnection connection
-
session
protected final DBSSession session
-
transientStates
protected Map<String,DBSDocumentState> transientStates
Retrieved and created document state.
-
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_CREATEthen 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.
-
versionAclMode
protected final BaseSession.VersionAclMode versionAclMode
-
disableReadVersionPermission
protected final boolean disableReadVersionPermission
-
-
Constructor Detail
-
DBSTransactionState
public DBSTransactionState(DBSRepository repository, DBSSession session)
-
-
Method Detail
-
close
public void close()
- Specified by:
closein interfaceAutoCloseable- 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).
-
exists
public boolean exists(String id)
Returns whether or not the document with givenidexists 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).
-
getChildState
public DBSDocumentState getChildState(String parentId, String name)
-
getChildrenStates
public List<DBSDocumentState> getChildrenStates(String parentId)
-
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)
-
createChild
public DBSDocumentState createChild(String id, String parentId, String name, Long pos, String typeName)
-
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.
-
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 usematerializedKeys(State)insteadGets 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
-
getKeyValuedStates
public List<DBSDocumentState> getKeyValuedStates(String key, Object value)
-
getKeyValuedStates
public List<DBSDocumentState> getKeyValuedStates(String key1, Object value1, String key2, Object value2)
-
queryAndFetch
public PartialList<Map<String,Serializable>> queryAndFetch(DBSExpressionEvaluator evaluator, OrderByClause orderByClause, boolean distinctDocuments, int limit, int offset, int countUpTo)
- Since:
- 11.1
-
scroll
public ScrollResult<String> scroll(DBSExpressionEvaluator evaluator, int batchSize, int keepAliveSeconds)
- Since:
- 11.1
-
scroll
public ScrollResult<String> scroll(String scrollId)
- Since:
- 11.1
-
getLock
public Lock getLock(String id)
Description copied from interface:LockManagerGets the lock on a document.If the document does not exist,
nullis returned.- Specified by:
getLockin interfaceLockManager- Parameters:
id- the document id- Returns:
- the existing lock, or
nullwhen there is no lock - Since:
- 11.1
-
setLock
public Lock setLock(String id, Lock lock)
Description copied from interface:LockManagerSets a lock on a document.If the document is already locked, returns its existing lock status (there is no re-locking,
LockManager.removeLock(java.lang.String, java.lang.String)must be called first).- Specified by:
setLockin interfaceLockManager- Parameters:
id- the document idlock- the lock to set- Returns:
nullif locking succeeded, or the existing lock if locking failed- Since:
- 11.1
-
removeLock
public Lock removeLock(String id, String owner)
Description copied from interface:LockManagerRemoves the lock from a document.The previous lock is returned.
If
ownerisnullthen the lock is unconditionally removed.If
owneris notnull, it must match the existing lock owner for the lock to be removed. If it doesn't match, the returned lock will returntrueforLock.getFailed().- Specified by:
removeLockin interfaceLockManager- Parameters:
id- the document idowner- the owner to check, ornullfor 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.
-
getConditionalUpdateForChangeToken
protected DBSTransactionState.ConditionalUpdates getConditionalUpdateForChangeToken(DBSDocumentState docState)
-
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.
-
updateProxies
protected void updateProxies(DBSDocumentState target)
-
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
-
computeBlobKeys
protected void computeBlobKeys(DBSDocumentState docState, DBSTransactionState.BlobKeysFinder blobKeysFinder)
-
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
Workinstances to schedule post-commit.
-
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 methoddocsWithDirtyBinaries- set of ids, updated by this method
-
-