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 class
DBSTransactionState.BlobKeysFinder
Iterates on aState
to find the blob keys.static class
DBSTransactionState.ConditionalUpdates
Logic to get the conditions to use to match and update a change token.protected static class
DBSTransactionState.DirtyPathsFinder
Iterates on a state diff to find the paths corresponding to dirty values.static class
DBSTransactionState.FindReadAclsWork
Deprecated.since 2021.11 useUpdateReadAclsAction
insteadstatic class
DBSTransactionState.UpdateReadAclsWork
Deprecated.since 2021.11 useUpdateReadAclsAction
instead
-
Field Summary
Fields Modifier and Type Field Description protected Set<String>
browsePermissions
protected DBSConnection
connection
protected Boolean
disabledForTestingPurpose
For test purpose only.protected boolean
disableReadVersionPermission
static String
READ_ACL_ASYNC_ENABLED_DEFAULT
static String
READ_ACL_ASYNC_ENABLED_PROPERTY
static String
READ_ACL_ASYNC_THRESHOLD_DEFAULT
static String
READ_ACL_ASYNC_THRESHOLD_PROPERTY
protected static Set<String>
READ_ACL_RECURSION_KEYS
Keys used when computing Read ACLs.protected DBSRepository
repository
protected DBSSession
session
protected Set<String>
transientCreated
Ids of documents created but not yet saved.protected Map<String,DBSDocumentState>
transientStates
Retrieved and created document state.protected Map<String,State>
undoLog
Undo log.protected Set<Serializable>
userChangeIds
Document ids modified as "user changes", which means that a change token should be checked.protected BaseSession.VersionAclMode
versionAclMode
-
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 void
applyUndoLog()
void
begin()
Called when created in a transaction.protected void
clearTransient()
void
close()
void
commit()
Saves and flushes to database.protected void
computeBlobKeys(DBSDocumentState docState, DBSTransactionState.BlobKeysFinder blobKeysFinder)
DBSDocumentState
copy(String id)
Copies the document into a newly-created object.DBSDocumentState
createChild(String id, String parentId, String name, Long pos, String typeName)
boolean
exists(String id)
Returns whether or not the document with givenid
exists in the storage.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.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)
DBSDocumentState
getChildState(String parentId, String name)
protected DBSTransactionState.ConditionalUpdates
getConditionalUpdateForChangeToken(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)
Lock
getLock(String id)
Gets the lock on a document.protected String[]
getReadACL(State state)
Deprecated.since 2021.39 usematerializedKeys(State)
insteadprotected int
getReadAclsAsyncThreshold()
String
getRootId()
State
getStateForRead(String id)
Returns a state which won't be modified.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).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).boolean
hasChild(String parentId, String name)
boolean
hasChildren(String parentId)
protected boolean
isBlobKeysDisabledForTestingPurpose()
For test purpose only.protected boolean
isProxySpecific(String key, SchemaManager schemaManager)
Things that we don't touch on a proxy when updating it.protected boolean
isUnderSyncLimit(int limit, Set<String> ids)
protected void
markIndexingInProgress(Set<String> ids)
void
markUserChange(String id)
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 idsprotected DBSDocumentState
newTransientState(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)
Lock
removeLock(String id, String owner)
Removes the lock from a document.void
removeStates(Set<String> ids)
Removes a list of documents.void
rollback()
Rolls back the save state by applying the undo log.void
save()
Writes transient state to database.protected void
scheduleWork(List<Work> works)
ScrollResult<String>
scroll(String scrollId)
ScrollResult<String>
scroll(DBSExpressionEvaluator evaluator, int batchSize, int keepAliveSeconds)
Lock
setLock(String id, Lock lock)
Sets a lock on a document.void
updateAncestors(String id, int ndel, Object[] ancestorIds)
Updates ancestors recursively after a move.protected static Long
updateChangeToken(Long changeToken)
protected void
updateDenormalizedState()
protected void
updateDocumentReadAcls(String id)
Updates the Read ACLs on a document (not recursively)protected void
updateDocumentReadAclsNoCache(String id)
Updates the Read ACLs on a document, without polluting caches.protected void
updateProxies()
Checks if the changed documents are proxy targets, and updates the proxies if that's the case.protected void
updateProxies(DBSDocumentState target)
protected void
updateProxy(DBSDocumentState target, String proxyId)
Updates the state of a proxy based on its target.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).void
updateTreeReadAcls(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_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.
-
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:
close
in 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 givenid
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).
-
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:LockManager
Gets the lock on a document.If the document does not exist,
null
is returned.- Specified by:
getLock
in interfaceLockManager
- Parameters:
id
- the document id- Returns:
- the existing lock, or
null
when there is no lock - Since:
- 11.1
-
setLock
public Lock setLock(String id, Lock lock)
Description copied from interface:LockManager
Sets 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:
setLock
in interfaceLockManager
- Parameters:
id
- the document idlock
- the lock to set- Returns:
null
if locking succeeded, or the existing lock if locking failed- 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
isnull
then the lock is unconditionally removed.If
owner
is notnull
, it must match the existing lock owner for the lock to be removed. If it doesn't match, the returned lock will returntrue
forLock.getFailed()
.- Specified by:
removeLock
in interfaceLockManager
- Parameters:
id
- the document idowner
- the owner to check, ornull
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.
-
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
Work
instances 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
-
-