public class LocalDocumentStore extends Object implements DocumentStore
DocumentStore
which always uses the local cache to store/retrieve data and which provides some
additional methods for exposing local cache information.Modifier and Type | Class and Description |
---|---|
static class |
LocalDocumentStore.DocumentOperationResults |
Constructor and Description |
---|
LocalDocumentStore(SchematicDb database,
RepositoryEnvironment repoEnv)
Creates a new local store with the given database
|
Modifier and Type | Method and Description |
---|---|
boolean |
containsKey(String key)
Determine whether the database contains an entry with the supplied key.
|
String |
createExternalProjection(String projectedNodeKey,
String sourceName,
String externalPath,
String alias)
Creates an external projection from the federated node with the given key, towards the external node from the given path,
from a source.
|
String |
databaseId()
Returns the id of the database.
|
EditableDocument |
edit(String key,
boolean createIfMissing)
Edit the existing document at the given key.
|
SchematicEntry |
get(String key)
Get the entry with the supplied key.
|
Document |
getChildReference(String parentKey,
String childKey)
Returns a document representing a single child reference from the supplied parent to the supplied child.
|
Document |
getChildrenBlock(String key)
Returns a document representing a block of children, that has the given key.
|
ExternalBinaryValue |
getExternalBinary(String sourceName,
String id)
Retrieves a binary value which has the given id and which is not stored by ModeShape.
|
String |
getLocalSourceKey()
Returns the value of the local repository source key.
|
List<String> |
keys()
Returns all the keys which are held by this store.
|
List<SchematicEntry> |
load(Collection<String> keys)
Loads a set of entries from the document store.
|
LocalDocumentStore |
localStore()
Returns a local store instance which is used to persist internal repository information.
|
boolean |
lockDocuments(Collection<String> keys)
Attempts to lock all of the documents with the given keys.
|
boolean |
lockDocuments(String... keys)
Attempts to lock all of the documents with the given keys.
|
String |
newDocumentKey(String parentKey,
Name documentName,
Name documentPrimaryType)
Generates a new key which will be assigned to a new child document when it is being added to its parent.
|
LocalDocumentStore.DocumentOperationResults |
performOnEachDocument(BiFunction<String,EditableDocument,Boolean> operation)
Perform the supplied operation on each stored document that is accessible within this process.
|
void |
put(Document entryDocument)
Store the supplied document in the local db
|
void |
put(String key,
Document document)
Store the supplied document and metadata at the given key.
|
boolean |
remove(String key)
Remove the existing document at the given key.
|
void |
removeAll()
Removes all the contents of the document store (i.e. all the documents)
Note that for this to work, it is expected that the caller will've already started a transaction.
|
<V> V |
runInTransaction(Callable<V> operation,
int retryCountOnLockTimeout,
String... keysToLock)
Runs the given operation within a transaction, after optionally locking some keys.
|
void |
setLocalSourceKey(String sourceKey)
Sets the value of the local repository source key.
|
SchematicEntry |
storeIfAbsent(String key,
Document document)
Store the supplied document at the given key.
|
void |
updateDocument(String key,
Document document,
SessionNode sessionNode)
Updates the content of the document at the given key with the given document.
|
public LocalDocumentStore(SchematicDb database, RepositoryEnvironment repoEnv)
database
- a SchematicDb
instance which must be non-null.repoEnv
- a RepositoryEnvironment
instance which must be non-nullpublic boolean containsKey(String key)
DocumentStore
containsKey
in interface DocumentStore
key
- the key or identifier for the documentSchematicDb.containsKey(String)
public List<String> keys()
Set
of keys, never null
public List<SchematicEntry> load(Collection<String> keys)
DocumentStore
load
in interface DocumentStore
keys
- a Set
of document keys; may not be nullCollection
of entries
; never null
public SchematicEntry get(String key)
DocumentStore
get
in interface DocumentStore
key
- the key or identifier for the documentSchematicDb.get(String)
public SchematicEntry storeIfAbsent(String key, Document document)
DocumentStore
storeIfAbsent
in interface DocumentStore
key
- the key or identifier for the documentdocument
- the document that is to be storedSchematicDb.putIfAbsent(String, Document)
public void updateDocument(String key, Document document, SessionNode sessionNode)
DocumentStore
updateDocument
in interface DocumentStore
key
- the key or identifier for the documentdocument
- the content with which the existing document should be updatedsessionNode
- the SessionNode
instance which contains the changes that caused the updatepublic String newDocumentKey(String parentKey, Name documentName, Name documentPrimaryType)
DocumentStore
newDocumentKey
in interface DocumentStore
parentKey
- a non-null
String
, the key of the existing parentdocumentName
- non-null
Name
, the name of the new child document.documentPrimaryType
- non-null
Name
, the name of the primary type of the new
child documentString
which will be assigned as key to the new child, or null
indicating that no preferred key
is to be used. If this is the case, the repository will assign a random key.@RequiresTransaction public void put(String key, Document document)
key
- the key or identifier for the documentdocument
- the document that is to be storedSchematicDb.put(String, Document)
@RequiresTransaction public void put(Document entryDocument)
entryDocument
- the document that contains the metadata document, content document, and keypublic boolean remove(String key)
DocumentStore
NOTE: This method does not perform any locking on that key. As such, the caller code should make sure
DocumentStore.lockDocuments(java.util.Collection<java.lang.String>)
is called first on all the keys that are about to be changed if the operation
can be performed from a concurrent context.
remove
in interface DocumentStore
key
- the key or identifier for the documentSchematicDb.remove(String)
@RequiresTransaction public void removeAll()
public boolean lockDocuments(Collection<String> keys)
DocumentStore
NOTE: This should only be called within an existing transaction. If this operation succeeds, all the locked keys will be released automatically when the transaction completes (regardless whether successfully or not).
lockDocuments
in interface DocumentStore
keys
- the set of keys identifying the documents that are to be updated via
DocumentStore.updateDocument(String, Document, SessionNode)
or via DocumentStore.edit(String,boolean)
.public boolean lockDocuments(String... keys)
DocumentStore
NOTE: This should only be called within an existing transaction. If this operation succeeds, all the locked keys will be released automatically when the transaction completes (regardless whether successfully or not)
lockDocuments
in interface DocumentStore
keys
- the set of keys identifying the documents that are to be updated via
DocumentStore.updateDocument(String, Document, SessionNode)
or via DocumentStore.edit(String,boolean)
.public EditableDocument edit(String key, boolean createIfMissing)
DocumentStore
NOTE: This method does not perform any locking on that key. As such, the caller code should make sure
DocumentStore.lockDocuments(java.util.Collection<java.lang.String>)
is called first on all the keys that are about to be changed if the operation
can be performed from a concurrent context.
edit
in interface DocumentStore
key
- the key or identifier for the documentcreateIfMissing
- true if a new entry should be created and added to the database if an existing entry does not existEditableDocument
instance if either a document exists at the given key or a new one was created and added
successfully. If a document does not already exist and cannot be created, then this will return null
SchematicDb.editContent(String, boolean)
public LocalDocumentStore localStore()
DocumentStore
localStore
in interface DocumentStore
LocalDocumentStore
instance.public void setLocalSourceKey(String sourceKey)
DocumentStore
setLocalSourceKey
in interface DocumentStore
sourceKey
- a non-null
stringpublic String getLocalSourceKey()
DocumentStore
getLocalSourceKey
in interface DocumentStore
non-null
stringpublic String createExternalProjection(String projectedNodeKey, String sourceName, String externalPath, String alias)
DocumentStore
createExternalProjection
in interface DocumentStore
projectedNodeKey
- a non-null
string, the key of the federated node which will contain the projectionsourceName
- a non-null
string, the name of an external source.externalPath
- a non-null
string, representing a path towards a node from the sourcealias
- a non-null
string, representing the alias given to the projection.non-null
string representing the node key of the external node located at externalPath
.public Document getChildrenBlock(String key)
DocumentStore
getChildrenBlock
in interface DocumentStore
key
- a non-null
String the key of the blockDocument
with children and possibly a pointer to the next block, or null
if there isn't a
block with such a key.public Document getChildReference(String parentKey, String childKey)
DocumentStore
getChildReference
in interface DocumentStore
parentKey
- the key for the parentchildKey
- the key for the childpublic ExternalBinaryValue getExternalBinary(String sourceName, String id)
DocumentStore
getExternalBinary
in interface DocumentStore
sourceName
- a non-null
String; the name of an external sourceid
- a non-null
String; the id of an external binary valueExternalBinaryValue
implementation or null
public String databaseId()
null
public LocalDocumentStore.DocumentOperationResults performOnEachDocument(BiFunction<String,EditableDocument,Boolean> operation)
Generally, this method executes the operation upon all documents. If there is an error processing a single document, that document is skipped and the execution will continue with the next document(s). However, if there is an exception with the transactions or another system failure, this method will terminate with an exception.
operation
- the operation to be performedpublic <V> V runInTransaction(Callable<V> operation, int retryCountOnLockTimeout, String... keysToLock)
V
- the return type of the operationoperation
- a Callable
instance; may not be nullretryCountOnLockTimeout
- the number of times the operation should be retried if a timeout occurs while trying
to obtain the lockskeysToLock
- an optional String[]
representing the keys to lock before performing the operationCopyright © 2008–2016 JBoss, a division of Red Hat. All rights reserved.