public class DBSCachingRepository extends Object implements DBSRepository
Modifier and Type | Field and Description |
---|---|
protected com.codahale.metrics.MetricRegistry |
registry |
Constructor and Description |
---|
DBSCachingRepository(DBSRepository repository,
DBSRepositoryDescriptor descriptor) |
Modifier and Type | Method and Description |
---|---|
void |
begin()
Called when created a transaction.
|
void |
clearLockManagerCaches()
Clears any cache held by the lock manager.
|
void |
closeLockManager()
Closes the lock manager and releases resources.
|
void |
commit()
Saves and flushes to database.
|
protected DBSClusterInvalidator |
createClusterInvalidator(DBSRepositoryDescriptor descriptor) |
void |
createState(State state)
Creates a document.
|
void |
createStates(List<State> states)
Creates documents.
|
void |
deleteStates(Set<String> ids)
Deletes a set of document.
|
String |
generateNewId()
Generates a new id for a document.
|
int |
getActiveSessionsCount() |
BlobManager |
getBlobManager()
Gets the blob manager.
|
Stream<State> |
getDescendants(String id,
Set<String> keys)
Returns a stream of descendants from a given root document, in no particular order.
|
Stream<State> |
getDescendants(String id,
Set<String> keys,
int limit)
Returns a stream of descendants from a given root document, in no particular order.
|
FulltextConfiguration |
getFulltextConfiguration()
Gets the fulltext configuration.
|
Lock |
getLock(String id)
Gets the lock on a document.
|
LockManager |
getLockManager()
Gets the lock manager for this repository.
|
String |
getName() |
String |
getRootId()
Gets the root id.
|
Session |
getSession() |
boolean |
hasChild(String parentId,
String name,
Set<String> ignored)
Checks if a document has a child with the given name
|
protected void |
initClusterInvalidator(DBSRepositoryDescriptor descriptor) |
boolean |
isChangeTokenEnabled()
Checks if database-managed document change tokens are enabled.
|
boolean |
isFulltextDisabled()
Checks if fulltext indexing is disabled.
|
void |
markReferencedBinaries()
Marks the binaries in use by passing them to the binary manager(s)'s GC mark() method.
|
protected <T> com.google.common.cache.Cache<String,T> |
newCache(DBSRepositoryDescriptor descriptor) |
protected void |
processReceivedInvalidations() |
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.
|
void |
rollback()
Rolls back the save state by applying the undo log.
|
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. |
protected void |
sendInvalidationsToOther() |
Lock |
setLock(String id,
Lock lock)
Sets a lock on a document.
|
void |
shutdown() |
void |
updateState(String id,
State.StateDiff diff,
DBSTransactionState.ChangeTokenUpdater changeTokenUpdater)
Updates a document.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
canLockBeRemoved
protected final com.codahale.metrics.MetricRegistry registry
public DBSCachingRepository(DBSRepository repository, DBSRepositoryDescriptor descriptor)
protected <T> com.google.common.cache.Cache<String,T> newCache(DBSRepositoryDescriptor descriptor)
protected void initClusterInvalidator(DBSRepositoryDescriptor descriptor)
protected DBSClusterInvalidator createClusterInvalidator(DBSRepositoryDescriptor descriptor)
public void begin()
DBSRepository
begin
in interface DBSRepository
public void commit()
DBSRepository
commit
in interface DBSRepository
public void rollback()
DBSRepository
rollback
in interface DBSRepository
public void shutdown()
shutdown
in interface Repository
public State readState(String id)
DBSRepository
readState
in interface DBSRepository
id
- the document idnull
if not foundpublic State readPartialState(String id, Collection<String> keys)
DBSRepository
readPartialState
in interface 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.
readStates
in interface DBSRepository
ids
- the document idsnull
if not foundpublic void createState(State state)
DBSRepository
createState
in interface DBSRepository
state
- the document statepublic void createStates(List<State> states)
DBSRepository
createStates
in interface DBSRepository
states
- the document statespublic void updateState(String id, State.StateDiff diff, DBSTransactionState.ChangeTokenUpdater changeTokenUpdater)
DBSRepository
updateState
in interface 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
deleteStates
in interface DBSRepository
ids
- the document idspublic State readChildState(String parentId, String name, Set<String> ignored)
DBSRepository
readChildState
in interface 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 sendInvalidationsToOther()
protected void processReceivedInvalidations()
public BlobManager getBlobManager()
DBSRepository
getBlobManager
in interface DBSRepository
public FulltextConfiguration getFulltextConfiguration()
DBSRepository
getFulltextConfiguration
in interface DBSRepository
public boolean isFulltextDisabled()
DBSRepository
isFulltextDisabled
in interface DBSRepository
true
if fulltext indexing is disabled, false
if it is enabledpublic boolean isChangeTokenEnabled()
DBSRepository
isChangeTokenEnabled
in interface DBSRepository
true
if the database maintains document change tokenspublic String getRootId()
DBSRepository
getRootId
in interface DBSRepository
public String generateNewId()
DBSRepository
generateNewId
in interface DBSRepository
public boolean hasChild(String parentId, String name, Set<String> ignored)
DBSRepository
hasChild
in interface 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 notpublic List<State> queryKeyValue(String key, Object value, Set<String> ignored)
DBSRepository
queryKeyValue
in interface 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
queryKeyValue
in interface 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 id, Set<String> keys)
DBSRepository
THE STREAM MUST BE CLOSED WHEN DONE to release resources.
getDescendants
in interface DBSRepository
id
- 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 id, Set<String> keys, int limit)
DBSRepository
THE STREAM MUST BE CLOSED WHEN DONE to release resources.
getDescendants
in interface DBSRepository
id
- 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
queryKeyValuePresence
in interface 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 nothingpublic PartialList<Map<String,Serializable>> queryAndFetch(DBSExpressionEvaluator evaluator, OrderByClause orderByClause, boolean distinctDocuments, int limit, int offset, int countUpTo)
DBSRepository
queryAndFetch
in interface 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 LockManager getLockManager()
DBSRepository
getLockManager
in interface DBSRepository
public ScrollResult<String> scroll(DBSExpressionEvaluator evaluator, int batchSize, int keepAliveSeconds)
DBSRepository
keepAliveSeconds
delay.scroll
in interface DBSRepository
public ScrollResult<String> scroll(String scrollId)
DBSRepository
scrollId
is part of the previous
ScrollResult
response.scroll
in interface DBSRepository
public Lock getLock(String id)
LockManager
If the document does not exist, null
is returned.
getLock
in interface LockManager
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).
setLock
in interface LockManager
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()
.
removeLock
in interface LockManager
id
- the document idnull
), with a failed flag if locking failedpublic void closeLockManager()
LockManager
closeLockManager
in interface LockManager
public void clearLockManagerCaches()
LockManager
clearLockManagerCaches
in interface LockManager
public String getName()
getName
in interface Repository
public Session getSession()
getSession
in interface Repository
public int getActiveSessionsCount()
getActiveSessionsCount
in interface Repository
public void markReferencedBinaries()
Repository
markReferencedBinaries
in interface Repository
Copyright © 2018 Nuxeo. All rights reserved.