Package org.nuxeo.ecm.core.storage.mem
Class MemConnection
- java.lang.Object
-
- org.nuxeo.ecm.core.storage.dbs.DBSConnectionBase
-
- org.nuxeo.ecm.core.storage.mem.MemConnection
-
- All Implemented Interfaces:
AutoCloseable
,LockManager
,DBSConnection
public class MemConnection extends DBSConnectionBase
In-memory implementation of aDBSConnection
.- Since:
- 11.1 (introduced in 5.9.4 as MemRepository)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.nuxeo.ecm.core.storage.dbs.DBSConnection
DBSConnection.DBSQueryOperator
-
-
Field Summary
Fields Modifier and Type Field Description protected static String
NOSCROLL_ID
protected Map<String,State>
states
-
Fields inherited from class org.nuxeo.ecm.core.storage.dbs.DBSConnectionBase
repository
-
-
Constructor Summary
Constructors Constructor Description MemConnection(MemRepository repository)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Serializable
applyDiff(Serializable value, State.ListDiff listDiff)
Applies aState.ListDiff
onto an array orList
, and returns the resulting value.protected static void
applyDiff(State state, String key, Serializable value)
Applies a key/value diff in-place onto a baseState
.static void
applyDiff(State state, State.StateDiff stateDiff)
Applies aState.StateDiff
in-place onto a baseState
.void
begin()
Starts a new transaction.void
close()
Closes this connection.void
commit()
Commits the current transaction.void
createState(State state)
Creates a document.void
deleteStates(Set<String> ids)
Deletes a set of document.String
generateNewId()
Generates a new id for a document.Stream<State>
getDescendants(String rootId, Set<String> keys)
Returns a stream of descendants from a given root document, in no particular order.Stream<State>
getDescendants(String rootId, Set<String> keys, int limit)
Returns a stream of descendants from a given root document, in no particular order.Lock
getLock(String id)
Gets the lock on a document.protected static boolean
hasAncestor(State state, String id)
boolean
hasChild(String parentId, String name, Set<String> ignored)
Checks if a document has a child with the given nameprotected void
initRepository()
PartialList<Map<String,Serializable>>
queryAndFetch(DBSExpressionEvaluator evaluator, OrderByClause orderByClause, boolean distinctDocuments, int limit, int offset, int countUpTo)
Queries the repository for documents matching a NXQL query, and returns a projection of the documents.List<State>
queryKeyValue(String key1, Object value1, String key2, Object value2, Set<String> ignored)
Queries the repository for documents having key1 = value1 and key2 = value2.List<State>
queryKeyValue(String key, Object value, Set<String> ignored)
Queries the repository for documents having key = value.boolean
queryKeyValuePresence(String key, String value, Set<String> ignored)
Queries the repository to check if there are documents having key = value.List<State>
queryKeyValueWithOperator(String key1, Object value1, String key2, DBSConnection.DBSQueryOperator operator, Object value2, Set<String> ignored)
Queries the repository for documents having key1 = value1 and key2 ${operator} value2.State
readChildState(String parentId, String name, Set<String> ignored)
Reads the state of a child document.State
readPartialState(String id, Collection<String> keys)
Reads the partial state of a document.State
readState(String id)
Reads the state of a document.List<State>
readStates(List<String> ids)
Reads the states of several documents.Lock
removeLock(String id, String owner)
Removes the lock from a document.void
rollback()
Rolls back the current transaction.ScrollResult<String>
scroll(String scrollId)
Get the next batch of results containing id of documents, thescrollId
is part of the previousScrollResult
response.ScrollResult<String>
scroll(DBSExpressionEvaluator evaluator, int batchSize, int keepAliveSeconds)
Executes the given query and returns the first batch of results containing id of documents, next batch must be requested within thekeepAliveSeconds
delay.Lock
setLock(String id, Lock lock)
Sets a lock on a document.void
updateState(String id, State.StateDiff diff, DBSTransactionState.ConditionalUpdates conditionalUpdates)
Updates a document.-
Methods inherited from class org.nuxeo.ecm.core.storage.dbs.DBSConnectionBase
getRootACP, getRootId, initRoot
-
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.storage.dbs.DBSConnection
createStates
-
Methods inherited from interface org.nuxeo.ecm.core.api.lock.LockManager
clearLockManagerCaches, closeLockManager
-
-
-
-
Field Detail
-
NOSCROLL_ID
protected static final String NOSCROLL_ID
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
MemConnection
public MemConnection(MemRepository repository)
-
-
Method Detail
-
begin
public void begin()
Description copied from interface:DBSConnection
Starts a new transaction.- See Also:
DBSRepository.supportsTransactions()
-
commit
public void commit()
Description copied from interface:DBSConnection
Commits the current transaction.- See Also:
DBSRepository.supportsTransactions()
-
rollback
public void rollback()
Description copied from interface:DBSConnection
Rolls back the current transaction.- See Also:
DBSRepository.supportsTransactions()
-
initRepository
protected void initRepository()
-
close
public void close()
Description copied from interface:DBSConnection
Closes this connection.
-
generateNewId
public String generateNewId()
Description copied from interface:DBSConnection
Generates a new id for a document.- Returns:
- the new id
-
readState
public State readState(String id)
Description copied from interface:DBSConnection
Reads the state of a document.- Parameters:
id
- the document id- Returns:
- the document state, or
null
if not found
-
readPartialState
public State readPartialState(String id, Collection<String> keys)
Description copied from interface:DBSConnection
Reads the partial state of a document.- Parameters:
id
- the document idkeys
- the keys to read- Returns:
- the document partial state, or
null
if not found
-
readStates
public List<State> readStates(List<String> ids)
Description copied from interface:DBSConnection
Reads the states of several documents.The returned states may be in a different order than the ids.
- Parameters:
ids
- the document ids- Returns:
- the document states, an element by be
null
if not found
-
createState
public void createState(State state)
Description copied from interface:DBSConnection
Creates a document.- Parameters:
state
- the document state
-
updateState
public void updateState(String id, State.StateDiff diff, DBSTransactionState.ConditionalUpdates conditionalUpdates)
Description copied from interface:DBSConnection
Updates a document.- Parameters:
id
- the document iddiff
- the diff to applyconditionalUpdates
- the conditional updates, ornull
-
deleteStates
public void deleteStates(Set<String> ids)
Description copied from interface:DBSConnection
Deletes a set of document.- Parameters:
ids
- the document ids
-
readChildState
public State readChildState(String parentId, String name, Set<String> ignored)
Description copied from interface:DBSConnection
Reads the state of a child document.- Parameters:
parentId
- the parent document idname
- the name of the childignored
- a set of document ids that should not be considered- Returns:
- the state of the child document, or
null
if not found
-
hasChild
public boolean hasChild(String parentId, String name, Set<String> ignored)
Description copied from interface:DBSConnection
Checks if a document has a child with the given name- Parameters:
parentId
- the parent document idname
- the name of the childignored
- a set of document ids that should not be considered- Returns:
true
if the child exists,false
if not
-
queryKeyValue
public List<State> queryKeyValue(String key, Object value, Set<String> ignored)
Description copied from interface:DBSConnection
Queries the repository for documents having key = value.- Parameters:
key
- the keyvalue
- the valueignored
- a set of document ids that should not be considered- Returns:
- the document states matching the query
-
queryKeyValue
public List<State> queryKeyValue(String key1, Object value1, String key2, Object value2, Set<String> ignored)
Description copied from interface:DBSConnection
Queries the repository for documents having key1 = value1 and key2 = value2.- Parameters:
key1
- the first keyvalue1
- the first valuekey2
- the second keyvalue2
- the second valueignored
- a set of document ids that should not be considered- Returns:
- the document states matching the query
-
getDescendants
public Stream<State> getDescendants(String rootId, Set<String> keys)
Description copied from interface:DBSConnection
Returns a stream of descendants from a given root document, in no particular order. This does not include information about the root document itself.THE STREAM MUST BE CLOSED WHEN DONE to release resources.
- Parameters:
rootId
- the root document idkeys
- what to collect about the descendants in addition to their ids- Returns:
- a stream of
State
s; THE STREAM MUST BE CLOSED WHEN DONE
-
getDescendants
public Stream<State> getDescendants(String rootId, Set<String> keys, int limit)
Description copied from interface:DBSConnection
Returns a stream of descendants from a given root document, in no particular order. This does not include information about the root document itself.THE STREAM MUST BE CLOSED WHEN DONE to release resources.
- Parameters:
rootId
- the root document idkeys
- what to collect about the descendants in addition to their idslimit
- the maximum number of descendants to return- Returns:
- a stream of
State
s; THE STREAM MUST BE CLOSED WHEN DONE
-
queryKeyValuePresence
public boolean queryKeyValuePresence(String key, String value, Set<String> ignored)
Description copied from interface:DBSConnection
Queries the repository to check if there are documents having key = value.- Parameters:
key
- the keyvalue
- the valueignored
- a set of document ids that should not be considered- Returns:
true
if the query matches at least one document,false
if the query matches nothing
-
queryAndFetch
public PartialList<Map<String,Serializable>> queryAndFetch(DBSExpressionEvaluator evaluator, OrderByClause orderByClause, boolean distinctDocuments, int limit, int offset, int countUpTo)
Description copied from interface:DBSConnection
Queries the repository for documents matching a NXQL query, and returns a projection of the documents.- Parameters:
evaluator
- the map-based evaluator for the queryorderByClause
- an ORDER BY clausedistinctDocuments
-true
if the projection should return a maximum of one row per documentlimit
- the limit on the number of documents to returnoffset
- the offset in the list of documents to returncountUpTo
- if-1
, count the total size without offset/limit.
If0
, don't count the total size, set it to-1
.
Ifn
, count the total number if there are less than n documents otherwise set the total size to-2
.- Returns:
- a partial list of maps containing the NXQL projections requested, and the total size according to countUpTo
-
scroll
public ScrollResult<String> scroll(DBSExpressionEvaluator evaluator, int batchSize, int keepAliveSeconds)
Description copied from interface:DBSConnection
Executes the given query and returns the first batch of results containing id of documents, next batch must be requested within thekeepAliveSeconds
delay.
-
scroll
public ScrollResult<String> scroll(String scrollId)
Description copied from interface:DBSConnection
Get the next batch of results containing id of documents, thescrollId
is part of the previousScrollResult
response.
-
applyDiff
public static void applyDiff(State state, State.StateDiff stateDiff)
-
applyDiff
protected static void applyDiff(State state, String key, Serializable value)
Applies a key/value diff in-place onto a baseState
.Uses thread-safe datastructures.
-
applyDiff
public static Serializable applyDiff(Serializable value, State.ListDiff listDiff)
Applies aState.ListDiff
onto an array orList
, and returns the resulting value.Uses thread-safe datastructures.
-
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.- Parameters:
id
- the document id- Returns:
- the existing lock, or
null
when there is no lock
-
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).- Parameters:
id
- the document idlock
- the lock to set- Returns:
null
if locking succeeded, or the existing lock if locking failed
-
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()
.- 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
-
queryKeyValueWithOperator
public List<State> queryKeyValueWithOperator(String key1, Object value1, String key2, DBSConnection.DBSQueryOperator operator, Object value2, Set<String> ignored)
Description copied from interface:DBSConnection
Queries the repository for documents having key1 = value1 and key2 ${operator} value2.- Parameters:
key1
- the first keyvalue1
- the first valuekey2
- the second keyoperator
- the operator to apply between key2 and value2value2
- the second valueignored
- a set of document ids that should not be considered- Returns:
- the document states matching the query
-
-