public class MongoDBRepository extends DBSRepositoryBase
Repository
.Modifier and Type | Class and Description |
---|---|
protected static class |
MongoDBRepository.MongoDBBlobFinder |
protected static class |
MongoDBRepository.UpdateListBuilder
Update list builder to prevent several updates of the same field.
|
static class |
MongoDBRepository.Updates |
DBSRepositoryBase.BlobFinder, DBSRepositoryBase.DBSSessionInvoker, DBSRepositoryBase.TransactionContext
Modifier and Type | Field and Description |
---|---|
protected com.mongodb.DBObject |
binaryKeys
Keys used for document projection when marking all binaries for GC.
|
protected com.mongodb.DBCollection |
coll |
protected static String |
COUNTER_FIELD |
protected static String |
COUNTER_NAME_UUID |
protected com.mongodb.DBCollection |
countersColl |
static String |
DB_DEFAULT |
protected static com.mongodb.DBObject |
LOCK_FIELDS |
protected com.mongodb.MongoClient |
mongoClient |
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 |
protected static com.mongodb.DBObject |
UNSET_LOCK_UPDATE |
blobManager, DEBUG_UUIDS, fulltextConfiguration, lockManager, repositoryName, selfRegisteredLockManager, transactionContexts, TYPE_ROOT
Constructor and Description |
---|
MongoDBRepository(MongoDBRepositoryDescriptor descriptor) |
Modifier and Type | Method and Description |
---|---|
protected void |
addIgnoredIds(com.mongodb.DBObject query,
Set<String> ignored) |
protected void |
addPrincipals(com.mongodb.DBObject query,
Set<String> principals) |
protected State |
bsonToState(com.mongodb.DBObject ob) |
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 |
deleteStates(Set<String> ids)
Deletes a set of document.
|
protected List<com.mongodb.DBObject> |
diffToBson(State.StateDiff diff)
Constructs a list of MongoDB updates from the given
State.StateDiff . |
protected void |
diffToUpdates(Delta delta,
String prefix,
MongoDBRepository.Updates updates) |
protected void |
diffToUpdates(State.ListDiff listDiff,
String prefix,
MongoDBRepository.Updates updates) |
protected void |
diffToUpdates(State.StateDiff diff,
String prefix,
MongoDBRepository.Updates updates) |
protected List<State> |
findAll(com.mongodb.DBObject query,
int sizeHint) |
protected State |
findOne(com.mongodb.DBObject query) |
protected void |
flatten(Map<String,Serializable> map,
State state,
String prefix) |
protected Map<String,Serializable> |
flatten(State state)
Flatten and convert from internal names to NXQL.
|
String |
generateNewId()
Generates a new id for a document.
|
protected com.mongodb.DBObject |
getChildQuery(String parentId,
String name,
Set<String> ignored) |
protected static com.mongodb.DBCollection |
getCollection(com.mongodb.MongoClient mongoClient,
String dbname,
String collection) |
static com.mongodb.DBCollection |
getCollection(MongoDBRepositoryDescriptor descriptor,
com.mongodb.MongoClient mongoClient) |
static com.mongodb.DBCollection |
getCountersCollection(MongoDBRepositoryDescriptor descriptor,
com.mongodb.MongoClient mongoClient) |
Lock |
getLock(String id)
Gets the lock on a document.
|
protected Long |
getNextUuidSeq() |
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 com.mongodb.DBObject |
justPresenceField() |
protected List<Object> |
listToBson(List<Object> values) |
protected void |
logQuery(com.mongodb.DBObject query,
com.mongodb.DBObject fields) |
protected void |
logQuery(com.mongodb.DBObject query,
com.mongodb.DBObject fields,
com.mongodb.DBObject orderBy,
int limit,
int offset) |
protected void |
logQuery(String id,
com.mongodb.DBObject fields) |
void |
markReferencedBinaries()
Marks the binaries in use by passing them to the binary manager(s)'s GC mark() method.
|
protected void |
markReferencedBinaries(com.mongodb.DBObject ob,
BlobManager blobManager) |
protected void |
markReferencedBinary(Object value,
BlobManager blobManager) |
static com.mongodb.MongoClient |
newMongoClient(MongoDBRepositoryDescriptor descriptor) |
PartialList<Map<String,Serializable>> |
queryAndFetch(DBSExpressionEvaluator evaluator,
OrderByClause orderByClause,
boolean selectDocuments,
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.
|
void |
queryKeyValueArray(String key,
Object value,
Set<String> ids,
Map<String,String> proxyTargets,
Map<String,Object[]> targetProxies)
Queries the repository for document ids having value in key (an array).
|
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 |
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.
|
protected Serializable |
scalarToSerializable(Object val) |
protected Class<?> |
scalarToSerializableClass(Class<?> klass) |
protected Object |
serializableToBson(Object value) |
Lock |
setLock(String id,
Lock lock)
Sets a lock on a document.
|
void |
shutdown() |
protected com.mongodb.DBObject |
stateToBson(State state) |
void |
updateState(String id,
State.StateDiff diff)
Updates a document.
|
protected Object |
valueToBson(Object value) |
getActiveSessionsCount, getBlobManager, getFulltextConfiguration, getLockManager, getLockManagerName, getName, getRootId, getSession, initLockManager, initRoot, isFulltextDisabled, newSession
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
canLockBeRemoved
public static final String DB_DEFAULT
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 com.mongodb.MongoClient mongoClient
protected com.mongodb.DBCollection coll
protected com.mongodb.DBCollection countersColl
protected com.mongodb.DBObject binaryKeys
protected static final com.mongodb.DBObject LOCK_FIELDS
protected static final com.mongodb.DBObject UNSET_LOCK_UPDATE
public MongoDBRepository(MongoDBRepositoryDescriptor descriptor)
public void shutdown()
shutdown
in interface Repository
shutdown
in class DBSRepositoryBase
public static com.mongodb.MongoClient newMongoClient(MongoDBRepositoryDescriptor descriptor) throws UnknownHostException
UnknownHostException
protected static com.mongodb.DBCollection getCollection(com.mongodb.MongoClient mongoClient, String dbname, String collection)
public static com.mongodb.DBCollection getCollection(MongoDBRepositoryDescriptor descriptor, com.mongodb.MongoClient mongoClient)
public static com.mongodb.DBCollection getCountersCollection(MongoDBRepositoryDescriptor descriptor, com.mongodb.MongoClient mongoClient)
protected Object valueToBson(Object value)
protected com.mongodb.DBObject stateToBson(State state)
protected List<Object> listToBson(List<Object> values)
protected State bsonToState(com.mongodb.DBObject ob)
protected List<com.mongodb.DBObject> diffToBson(State.StateDiff diff)
State.StateDiff
.
We need a list because some cases need two operations to avoid conflicts.
protected void diffToUpdates(State.StateDiff diff, String prefix, MongoDBRepository.Updates updates)
protected void diffToUpdates(State.ListDiff listDiff, String prefix, MongoDBRepository.Updates updates)
protected void diffToUpdates(Delta delta, String prefix, MongoDBRepository.Updates updates)
protected Object serializableToBson(Object value)
protected Serializable scalarToSerializable(Object val)
protected Class<?> scalarToSerializableClass(Class<?> klass)
protected void initRepository()
protected Long getNextUuidSeq()
public String generateNewId()
DBSRepository
public void createState(State state)
DBSRepository
state
- the document statepublic State readState(String id)
DBSRepository
id
- the document idnull
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)
DBSRepository
id
- the document iddiff
- the diff to applypublic 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(com.mongodb.DBObject query, com.mongodb.DBObject fields)
protected void logQuery(com.mongodb.DBObject query, com.mongodb.DBObject fields, com.mongodb.DBObject 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 com.mongodb.DBObject getChildQuery(String parentId, String name, Set<String> ignored)
protected void addIgnoredIds(com.mongodb.DBObject query, 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 void queryKeyValueArray(String key, Object value, Set<String> ids, Map<String,String> proxyTargets, Map<String,Object[]> targetProxies)
DBSRepository
key
- the keyvalue
- the valueids
- the set which receives the documents idsproxyTargets
- returns a map of proxy to target among the documents foundtargetProxies
- returns a map of target to proxies among the document foundpublic 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 com.mongodb.DBObject justPresenceField()
public PartialList<Map<String,Serializable>> queryAndFetch(DBSExpressionEvaluator evaluator, OrderByClause orderByClause, boolean selectDocuments, int limit, int offset, int countUpTo)
DBSRepository
evaluator
- the map-based evaluator for the queryorderByClause
- an ORDER BY clauseselectDocuments
- the projection should return only distinct document idslimit
- 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
.protected void addPrincipals(com.mongodb.DBObject query, Set<String> principals)
protected Map<String,Serializable> flatten(State state)
protected void initBlobsPaths()
initBlobsPaths
in class DBSRepositoryBase
public void markReferencedBinaries()
Repository
protected void markReferencedBinaries(com.mongodb.DBObject ob, BlobManager blobManager)
protected void markReferencedBinary(Object value, BlobManager 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 © 2016 Nuxeo SA. All rights reserved.