public class MongoDBRepository extends DBSRepositoryBase
Repository
.Modifier and Type | Class and Description |
---|---|
protected static class |
MongoDBRepository.MongoDBBlobFinder |
DBSRepositoryBase.BlobFinder, DBSRepositoryBase.DBSSessionInvoker, DBSRepositoryBase.IdType, DBSRepositoryBase.TransactionContext
Modifier and Type | Field and Description |
---|---|
protected org.bson.conversions.Bson |
binaryKeys
Keys used for document projection when marking all binaries for GC.
|
protected com.mongodb.client.MongoCollection<org.bson.Document> |
coll |
protected MongoDBConverter |
converter |
protected static String |
COUNTER_FIELD |
protected static String |
COUNTER_NAME_UUID |
protected com.mongodb.client.MongoCollection<org.bson.Document> |
countersColl |
protected CursorService<com.mongodb.client.MongoCursor<org.bson.Document>,org.bson.Document,String> |
cursorService |
protected String |
idKey
The key to use to store the id in the database.
|
protected static org.bson.conversions.Bson |
LOCK_FIELDS |
static Long |
LONG_ZERO |
static String |
MONGODB_EACH |
static String |
MONGODB_ID |
static String |
MONGODB_INC |
static String |
MONGODB_META |
static String |
MONGODB_PUSH |
static String |
MONGODB_SET |
static String |
MONGODB_TEXT_SCORE |
static String |
MONGODB_UNSET |
static Double |
ONE |
static String |
REPOSITORY_CONNECTION_PREFIX
Prefix used to retrieve a MongoDB connection from
MongoDBConnectionService . |
protected long |
sequenceBlockSize
Sequence allocation block size.
|
protected long |
sequenceLastValue
Last value used from the in-memory sequence.
|
protected long |
sequenceLeft
Number of values still available in the in-memory sequence.
|
protected static org.bson.conversions.Bson |
UNSET_LOCK_UPDATE |
protected boolean |
useCustomId
True if we don't use MongoDB's native "_id" key to store the id.
|
static Double |
ZERO |
blobManager, changeTokenEnabled, cm, DEBUG_UUIDS, fulltextConfiguration, idType, lockManager, repositoryName, selfRegisteredLockManager, transactionContexts, TYPE_ROOT
Constructor and Description |
---|
MongoDBRepository(javax.resource.spi.ConnectionManager cm,
MongoDBRepositoryDescriptor descriptor) |
Modifier and Type | Method and Description |
---|---|
protected void |
addIgnoredIds(org.bson.Document filter,
Set<String> ignored) |
protected void |
addPrincipals(org.bson.Document query,
Set<String> principals) |
void |
clearLockManagerCaches()
Clears any cache held by the lock manager.
|
void |
closeLockManager()
Closes the lock manager and releases resources.
|
void |
createState(State state)
Creates a document.
|
void |
createStates(List<State> states)
Creates documents.
|
void |
deleteStates(Set<String> ids)
Deletes a set of document.
|
protected boolean |
exists(org.bson.conversions.Bson filter) |
protected boolean |
exists(org.bson.conversions.Bson filter,
org.bson.conversions.Bson projection) |
protected List<State> |
findAll(org.bson.conversions.Bson filter) |
protected State |
findOne(org.bson.conversions.Bson filter) |
protected State |
findOne(org.bson.conversions.Bson filter,
org.bson.conversions.Bson projection) |
String |
generateNewId()
Generates a new id for a document.
|
List<DBSRepositoryBase.IdType> |
getAllowedIdTypes()
Gets the allowed id types for this DBS repository.
|
protected org.bson.Document |
getChildQuery(String parentId,
String name,
Set<String> ignored) |
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 Long |
getNextSequenceId() |
boolean |
hasChild(String parentId,
String name,
Set<String> ignored)
Checks if a document has a child with the given name
|
protected void |
initBlobsPaths() |
protected void |
initRepository() |
protected org.bson.Document |
justPresenceField() |
protected void |
logQuery(org.bson.conversions.Bson filter,
org.bson.conversions.Bson fields) |
protected void |
logQuery(org.bson.conversions.Bson query,
org.bson.conversions.Bson fields,
org.bson.conversions.Bson orderBy,
int limit,
int offset) |
protected void |
logQuery(String id,
org.bson.conversions.Bson fields) |
void |
markReferencedBinaries()
Marks the binaries in use by passing them to the binary manager(s)'s GC mark() method.
|
protected void |
markReferencedBinaries(org.bson.Document ob,
DocumentBlobManager blobManager) |
protected void |
markReferencedBinary(Object value,
DocumentBlobManager blobManager) |
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 key,
Object value,
Set<String> ignored)
Queries the repository for documents having key = value.
|
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.
|
boolean |
queryKeyValuePresence(String key,
String value,
Set<String> ignored)
Queries the repository to check if there are documents having key = value.
|
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.
|
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 the
keepAliveSeconds delay. |
ScrollResult<String> |
scroll(String scrollId)
Get the next batch of results containing id of documents, the
scrollId is part of the previous
ScrollResult response. |
Lock |
setLock(String id,
Lock lock)
Sets a lock on a document.
|
void |
shutdown() |
protected Stream<State> |
stream(org.bson.conversions.Bson filter) |
protected Stream<State> |
stream(org.bson.conversions.Bson filter,
org.bson.conversions.Bson projection) |
protected Stream<State> |
stream(org.bson.conversions.Bson filter,
org.bson.conversions.Bson projection,
int limit)
Logs, runs request and constructs a closeable
Stream on top of MongoCursor . |
void |
updateState(String id,
State.StateDiff diff,
DBSTransactionState.ChangeTokenUpdater changeTokenUpdater)
Updates a document.
|
getActiveSessionsCount, getBlobManager, getFulltextConfiguration, getLockManager, getLockManagerName, getName, getRootId, getSession, getSession, initLockManager, initRoot, isChangeTokenEnabled, isFulltextDisabled, isFulltextSearchDisabled, newSession
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
begin, commit, rollback
canLockBeRemoved
public static final String REPOSITORY_CONNECTION_PREFIX
MongoDBConnectionService
.
The connection id will be repository/[REPOSITORY_NAME]
.public static final String MONGODB_ID
public static final String MONGODB_INC
public static final String MONGODB_SET
public static final String MONGODB_UNSET
public static final String MONGODB_PUSH
public static final String MONGODB_EACH
public static final String MONGODB_META
public static final String MONGODB_TEXT_SCORE
protected static final String COUNTER_NAME_UUID
protected static final String COUNTER_FIELD
protected final com.mongodb.client.MongoCollection<org.bson.Document> coll
protected final com.mongodb.client.MongoCollection<org.bson.Document> countersColl
protected boolean useCustomId
protected long sequenceLeft
protected long sequenceLastValue
protected long sequenceBlockSize
protected final MongoDBConverter converter
protected final CursorService<com.mongodb.client.MongoCursor<org.bson.Document>,org.bson.Document,String> cursorService
protected org.bson.conversions.Bson binaryKeys
protected static final org.bson.conversions.Bson LOCK_FIELDS
protected static final org.bson.conversions.Bson UNSET_LOCK_UPDATE
public MongoDBRepository(javax.resource.spi.ConnectionManager cm, MongoDBRepositoryDescriptor descriptor)
public List<DBSRepositoryBase.IdType> getAllowedIdTypes()
DBSRepositoryBase
getAllowedIdTypes
in class DBSRepositoryBase
public void shutdown()
shutdown
in interface Repository
shutdown
in class DBSRepositoryBase
protected void initRepository()
protected Long getNextSequenceId()
public String generateNewId()
DBSRepository
public void createState(State state)
DBSRepository
state
- the document statepublic void createStates(List<State> states)
DBSRepository
states
- the document statespublic State readState(String id)
DBSRepository
id
- the document idnull
if not foundpublic State readPartialState(String id, Collection<String> keys)
DBSRepository
id
- the document idkeys
- the keys to readnull
if not foundpublic List<State> readStates(List<String> ids)
DBSRepository
The returned states may be in a different order than the ids.
ids
- the document idsnull
if not foundpublic void updateState(String id, State.StateDiff diff, DBSTransactionState.ChangeTokenUpdater changeTokenUpdater)
DBSRepository
id
- the document iddiff
- the diff to applychangeTokenUpdater
- how to get and update the change token (may be null
)public void deleteStates(Set<String> ids)
DBSRepository
ids
- the document idspublic State readChildState(String parentId, String name, Set<String> ignored)
DBSRepository
parentId
- the parent document idname
- the name of the childignored
- a set of document ids that should not be considerednull
if not foundprotected void logQuery(org.bson.conversions.Bson filter, org.bson.conversions.Bson fields)
protected void logQuery(org.bson.conversions.Bson query, org.bson.conversions.Bson fields, org.bson.conversions.Bson orderBy, int limit, int offset)
public boolean hasChild(String parentId, String name, Set<String> ignored)
DBSRepository
parentId
- the parent document idname
- the name of the childignored
- a set of document ids that should not be consideredtrue
if the child exists, false
if notprotected org.bson.Document getChildQuery(String parentId, String name, Set<String> ignored)
protected void addIgnoredIds(org.bson.Document filter, Set<String> ignored)
public List<State> queryKeyValue(String key, Object value, Set<String> ignored)
DBSRepository
key
- the keyvalue
- the valueignored
- a set of document ids that should not be consideredpublic List<State> queryKeyValue(String key1, Object value1, String key2, Object value2, Set<String> ignored)
DBSRepository
key1
- the first keyvalue1
- the first valuekey2
- the second keyvalue2
- the second valueignored
- a set of document ids that should not be consideredpublic Stream<State> getDescendants(String rootId, Set<String> keys)
DBSRepository
THE STREAM MUST BE CLOSED WHEN DONE to release resources.
rootId
- the root document idkeys
- what to collect about the descendants in addition to their idsState
s; THE STREAM MUST BE CLOSED WHEN DONEpublic Stream<State> getDescendants(String rootId, Set<String> keys, int limit)
DBSRepository
THE STREAM MUST BE CLOSED WHEN DONE to release resources.
rootId
- the root document idkeys
- what to collect about the descendants in addition to their idslimit
- the maximum number of descendants to returnState
s; THE STREAM MUST BE CLOSED WHEN DONEpublic boolean queryKeyValuePresence(String key, String value, Set<String> ignored)
DBSRepository
key
- the keyvalue
- the valueignored
- a set of document ids that should not be consideredtrue
if the query matches at least one document, false
if the query matches nothingprotected boolean exists(org.bson.conversions.Bson filter)
protected boolean exists(org.bson.conversions.Bson filter, org.bson.conversions.Bson projection)
protected State findOne(org.bson.conversions.Bson filter, org.bson.conversions.Bson projection)
protected Stream<State> stream(org.bson.conversions.Bson filter, org.bson.conversions.Bson projection)
protected Stream<State> stream(org.bson.conversions.Bson filter, org.bson.conversions.Bson projection, int limit)
Stream
on top of MongoCursor
.
We should rely on this method, because it correctly handles cursor closed state.
Note: Looping on FindIterable
or MongoIterable
could lead to cursor leaks. This is also the case
on some call to MongoIterable.first()
.Stream
instance linked to MongoCursor
protected org.bson.Document justPresenceField()
public PartialList<Map<String,Serializable>> queryAndFetch(DBSExpressionEvaluator evaluator, OrderByClause orderByClause, boolean distinctDocuments, int limit, int offset, int countUpTo)
DBSRepository
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.0
, don't count the total size, set it to -1
.n
, count the total number if there are less than n documents otherwise set the total size
to -2
.public ScrollResult<String> scroll(DBSExpressionEvaluator evaluator, int batchSize, int keepAliveSeconds)
DBSRepository
keepAliveSeconds
delay.public ScrollResult<String> scroll(String scrollId)
DBSRepository
scrollId
is part of the previous
ScrollResult
response.protected void addPrincipals(org.bson.Document query, Set<String> principals)
protected void initBlobsPaths()
initBlobsPaths
in class DBSRepositoryBase
public void markReferencedBinaries()
Repository
protected void markReferencedBinaries(org.bson.Document ob, DocumentBlobManager blobManager)
protected void markReferencedBinary(Object value, DocumentBlobManager blobManager)
public Lock getLock(String id)
LockManager
If the document does not exist, null
is returned.
id
- the document idnull
when there is no lockpublic Lock setLock(String id, Lock lock)
LockManager
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).
id
- the document idlock
- the lock to setnull
if locking succeeded, or the existing lock if locking failedpublic Lock removeLock(String id, String owner)
LockManager
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()
.
id
- the document idnull
), with a failed flag if locking failedpublic void closeLockManager()
LockManager
public void clearLockManagerCaches()
LockManager
Copyright © 2018 Nuxeo. All rights reserved.