org.modeshape.jcr.cache.document

## Class LocalDocumentStore

- java.lang.Object
- - org.modeshape.jcr.cache.document.LocalDocumentStore

- All Implemented Interfaces:
    DocumentStore

      public class LocalDocumentStore
      extends Object
      implements DocumentStore

  An implementation of `DocumentStore` which always uses the local cache to store/retrieve data and which provides some additional methods for exposing local cache information.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `protected static class` | `LocalDocumentStore.DistributedOperation`
    `static class` | `LocalDocumentStore.DocumentOperation` An operation upon a persisted document.
    `static class` | `LocalDocumentStore.DocumentOperationResults`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `LocalDocumentStore(SchematicDb database)` Creates a new local store with the given database

  - ### Method Summary

    Methods
    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.
    `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.
    `Cache<String,SchematicEntry>` | `localCache()` Returns the local Infinispan cache.
    `LocalDocumentStore` | `localStore()` Returns a local store instance which will use the local Infinispan cache to store/retrieve information.
    `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(LocalDocumentStore.DocumentOperation operation)` Perform the supplied operation on each stored document that is accessible within this process.
    `boolean` | `prepareDocumentsForUpdate(Collection<String> keys)` Prepare to update all of the documents with the given keys.
    `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.
    `SchematicEntry` | `putIfAbsent(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` | `replace(String key, Document document)` Replace the existing document and metadata at the given key with the document that is supplied.
    `void` | `setLocalSourceKey(String sourceKey)` Sets the value of the local repository source key.
    `SchematicEntry` | `storeDocument(String key, Document document)` Store the supplied document at the given key.
    `TransactionManager` | `transactionManager()` Returns a transaction manager instance which can be used to manage transactions for this document store.
    `void` | `updateDocument(String key, Document document, SessionNode sessionNode)` Updates the content of the document at the given key with the given document.
    `boolean` | `updatesRequirePreparing()` Return whether `DocumentStore.prepareDocumentsForUpdate(Collection)` should be called before updating the documents.
    `XAResource` | `xaResource()` Returns a resource used in distributed transactions

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### LocalDocumentStore

          public LocalDocumentStore(SchematicDb database)

      Creates a new local store with the given database
      Parameters:
        `database` - a `SchematicDb` instance which must be non-null.

  - ### Method Detail

    - #### containsKey

          public boolean containsKey(String key)

      Description copied from interface: `DocumentStore`
      Determine whether the database contains an entry with the supplied key.
      Specified by:
        `containsKey` in interface `DocumentStore`
      Parameters:
        `key` - the key or identifier for the document
      Returns:
        true if the database contains an entry with this key, or false otherwise

    - #### get

          public SchematicEntry get(String key)

      Description copied from interface: `DocumentStore`
      Get the entry with the supplied key.
      Specified by:
        `get` in interface `DocumentStore`
      Parameters:
        `key` - the key or identifier for the document
      Returns:
        the entry, or null if there was no document with the supplied key

    - #### storeDocument

          public SchematicEntry storeDocument(String key,
                                     Document document)

      Description copied from interface: `DocumentStore`
      Store the supplied document at the given key.
      Specified by:
        `storeDocument` in interface `DocumentStore`
      Parameters:
        `key` - the key or identifier for the document
        `document` - the document that is to be stored
      Returns:
        the existing entry for the supplied key, or null if there was no entry and the put was successful

    - #### updateDocument

          public void updateDocument(String key,
                            Document document,
                            SessionNode sessionNode)

      Description copied from interface: `DocumentStore`
      Updates the content of the document at the given key with the given document.
      Specified by:
        `updateDocument` in interface `DocumentStore`
      Parameters:
        `key` - the key or identifier for the document
        `document` - the content with which the existing document should be updated
        `sessionNode` - the `SessionNode` instance which contains the changes that caused the update

    - #### newDocumentKey

          public String newDocumentKey(String parentKey,
                              Name documentName,
                              Name documentPrimaryType)

      Description copied from interface: `DocumentStore`
      Generates a new key which will be assigned to a new child document when it is being added to its parent.
      Specified by:
        `newDocumentKey` in interface `DocumentStore`
      Parameters:
        `parentKey` - a `non-null` `String`, the key of the existing parent
        `documentName` - `non-null` `Name`, the name of the new child document.
        `documentPrimaryType` - `non-null` `Name`, the name of the primary type of the new child document
      Returns:
        a `String` 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.

    - #### putIfAbsent

          public SchematicEntry putIfAbsent(String key,
                                   Document document)

      Store the supplied document and metadata at the given key.
      Parameters:
        `key` - the key or identifier for the document
        `document` - the document that is to be stored
      Returns:
        the existing entry for the supplied key, or null if there was no entry and the put was successful
      See Also:
        `SchematicDb.putIfAbsent(String, org.infinispan.schematic.document.Document, org.infinispan.schematic.document.Document)`

    - #### put

          public void put(String key,
                 Document document)

      Store the supplied document and metadata at the given key.
      Parameters:
        `key` - the key or identifier for the document
        `document` - the document that is to be stored
      See Also:
        `SchematicDb.put(String, org.infinispan.schematic.document.Document, org.infinispan.schematic.document.Document)`

    - #### put

          public void put(Document entryDocument)

      Store the supplied document in the local db
      Parameters:
        `entryDocument` - the document that contains the metadata document, content document, and key

    - #### replace

          public void replace(String key,
                     Document document)

      Replace the existing document and metadata at the given key with the document that is supplied. This method does nothing if there is not an existing entry at the given key.
      Parameters:
        `key` - the key or identifier for the document
        `document` - the new document that is to replace the existing document (or binary content) the replacement

    - #### remove

          public boolean remove(String key)

      Description copied from interface: `DocumentStore`
      Remove the existing document at the given key.
      Specified by:
        `remove` in interface `DocumentStore`
      Parameters:
        `key` - the key or identifier for the document
      Returns:
        true if a document was removed, or false if there was no document with that key

    - #### prepareDocumentsForUpdate

          public boolean prepareDocumentsForUpdate(Collection<String> keys)

      Description copied from interface: `DocumentStore`
      Prepare to update all of the documents with the given keys.
      Specified by:
        `prepareDocumentsForUpdate` in interface `DocumentStore`
      Parameters:
        `keys` - the set of keys identifying the documents that are to be updated via `DocumentStore.updateDocument(String, Document, SessionNode)` or via `DocumentStore.get(String)` followed by `SchematicEntry.editDocumentContent()`.
      Returns:
        true if the documents were locked, or false if not all of the documents could be locked

    - #### updatesRequirePreparing

          public boolean updatesRequirePreparing()

      Description copied from interface: `DocumentStore`
      Return whether `DocumentStore.prepareDocumentsForUpdate(Collection)` should be called before updating the documents.
      Specified by:
        `updatesRequirePreparing` in interface `DocumentStore`
      Returns:
        true if `DocumentStore.prepareDocumentsForUpdate(Collection)` should be called, or false otherwise

    - #### localStore

          public LocalDocumentStore localStore()

      Description copied from interface: `DocumentStore`
      Returns a local store instance which will use the local Infinispan cache to store/retrieve information.
      Specified by:
        `localStore` in interface `DocumentStore`
      Returns:
        a non-null `LocalDocumentStore` instance.

    - #### transactionManager

          public TransactionManager transactionManager()

      Description copied from interface: `DocumentStore`
      Returns a transaction manager instance which can be used to manage transactions for this document store.
      Specified by:
        `transactionManager` in interface `DocumentStore`
      Returns:
        a `TransactionManager` instance, never null.

    - #### xaResource

          public XAResource xaResource()

      Description copied from interface: `DocumentStore`
      Returns a resource used in distributed transactions
      Specified by:
        `xaResource` in interface `DocumentStore`
      Returns:
        an `instance` or `null`

    - #### setLocalSourceKey

          public void setLocalSourceKey(String sourceKey)

      Description copied from interface: `DocumentStore`
      Sets the value of the local repository source key.
      Specified by:
        `setLocalSourceKey` in interface `DocumentStore`
      Parameters:
        `sourceKey` - a `non-null` string

    - #### getLocalSourceKey

          public String getLocalSourceKey()

      Description copied from interface: `DocumentStore`
      Returns the value of the local repository source key.
      Specified by:
        `getLocalSourceKey` in interface `DocumentStore`
      Returns:
        a `non-null` string

    - #### createExternalProjection

          public String createExternalProjection(String projectedNodeKey,
                                        String sourceName,
                                        String externalPath,
                                        String alias)

      Description copied from interface: `DocumentStore`
      Creates an external projection from the federated node with the given key, towards the external node from the given path, from a source.
      Specified by:
        `createExternalProjection` in interface `DocumentStore`
      Parameters:
        `projectedNodeKey` - a `non-null` string, the key of the federated node which will contain the projection
        `sourceName` - a `non-null` string, the name of an external source.
        `externalPath` - a `non-null` string, representing a path towards a node from the source
        `alias` - a `non-null` string, representing the alias given to the projection.
      Returns:
        a `non-null` string representing the node key of the external node located at `externalPath`.

    - #### getChildrenBlock

          public Document getChildrenBlock(String key)

      Description copied from interface: `DocumentStore`
      Returns a document representing a block of children, that has the given key.
      Specified by:
        `getChildrenBlock` in interface `DocumentStore`
      Parameters:
        `key` - a `non-null` String the key of the block
      Returns:
        either a `Document` with children and possibly a pointer to the next block, or `null` if there isn't a block with such a key.

    - #### getChildReference

          public Document getChildReference(String parentKey,
                                   String childKey)

      Description copied from interface: `DocumentStore`
      Returns a document representing a single child reference from the supplied parent to the supplied child. This method is called when it is too expensive to find the child reference within the child references.
      Specified by:
        `getChildReference` in interface `DocumentStore`
      Parameters:
        `parentKey` - the key for the parent
        `childKey` - the key for the child
      Returns:
        the document representation of a child reference, or null if the implementation doesn't support this method or the parent does not contain a child with the given key

    - #### localCache

          public Cache<String,SchematicEntry> localCache()

      Returns the local Infinispan cache.
      Returns:
        a `non-null` `Cache` instance.

    - #### getExternalBinary

          public ExternalBinaryValue getExternalBinary(String sourceName,
                                              String id)

      Description copied from interface: `DocumentStore`
      Retrieves a binary value which has the given id and which is not stored by ModeShape.
      Specified by:
        `getExternalBinary` in interface `DocumentStore`
      Parameters:
        `sourceName` - a `non-null` String; the name of an external source
        `id` - a `non-null` String; the id of an external binary value
      Returns:
        either an `ExternalBinaryValue` implementation or `null`

    - #### performOnEachDocument

          public LocalDocumentStore.DocumentOperationResults performOnEachDocument(LocalDocumentStore.DocumentOperation operation)
                                                                            throws InterruptedException,
                                                                                   ExecutionException

      Perform the supplied operation on each stored document that is accessible within this process. Each document will be operated upon in a separate transaction, which will be committed if the operation is successful or rolledback if the operation cannot be complete successfully.

      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.

      Parameters:
        `operation` - the operation to be performed
      Returns:
        the summary of the number of documents that were affected
      Throws:
        `InterruptedException` - if the process is interrupted
        `ExecutionException` - if there is an error while getting executing the operation

Copyright © 2008-2014 JBoss, a division of Red Hat. All Rights Reserved.