org.modeshape.jcr.cache.document

## Class WritableSessionCache

- java.lang.Object
- - org.modeshape.jcr.cache.document.AbstractSessionCache
  - - org.modeshape.jcr.cache.document.WritableSessionCache

- All Implemented Interfaces:
    CachedNodeSupplier, DocumentCache, NodeCache, SessionCache

      @ThreadSafe
      public class WritableSessionCache
      extends AbstractSessionCache

  A writable `SessionCache` implementation capable of making transient changes and saving them.

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class org.modeshape.jcr.cache.document.AbstractSessionCache

      `AbstractSessionCache.BasicSaveContext`

    - ### Nested classes/interfaces inherited from interface org.modeshape.jcr.cache.SessionCache

      `SessionCache.PreSave, SessionCache.SaveContext`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `WritableSessionCache(ExecutionContext context, WorkspaceCache workspaceCache, SessionEnvironment sessionContext)` Create a new SessionCache that can be used for making changes to the workspace.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected SessionNode` | `add(SessionNode newNode)`
    `protected void` | `assertInSession(SessionNode node)`
    `protected void` | `clearState()`
    `protected void` | `clearState(Iterable<NodeKey> savedNodesInOrder)`
    `void` | `destroy(NodeKey key)` Destroy the subgraph with the supplied node as the top node in the subgraph.
    `protected void` | `doClear()`
    `protected void` | `doClear(CachedNode node)`
    `Set<NodeKey>` | `getChangedNodeKeys()` Returns a set with the `NodeKey`s of the transient nodes from this cache.
    `Set<NodeKey>` | `getChangedNodeKeysAtOrBelow(CachedNode srcNode)` Returns a set with the `NodeKey`s of the transient nodes from this cache which are at or below the path of the given node
    `CachedNode` | `getNode(NodeKey key)` Get the cached representation of the node with the supplied node key.
    `boolean` | `hasChanges()` Determine whether this session has any transient, unsaved changes.
    `boolean` | `isDestroyed(NodeKey key)` Return whether the node with the supplied key has been removed using this session but not yet persisted.
    `boolean` | `isReadOnly()` Returns whether this cache is readonly.
    `protected void` | `logChangesBeingSaved(Iterable<NodeKey> firstNodesInOrder, Map<NodeKey,SessionNode> firstNodes, Iterable<NodeKey> secondNodesInOrder, Map<NodeKey,SessionNode> secondNodes)`
    `protected Logger` | `logger()`
    `SessionNode` | `mutable(NodeKey key)` Get a mutable form of the node with the supplied key.
    `protected ChangeSet` | `persistChanges(Iterable<NodeKey> changedNodesInOrder, SessionEnvironment.Monitor monitor)` Persist the changes within an already-established transaction.
    `void` | `save()` Persist the changes within a transaction.
    `protected void` | `save(SessionCache.PreSave preSaveOperation)`
    `void` | `save(SessionCache other, SessionCache.PreSave preSaveOperation)` Saves all changes made within this session and the supplied session, using a single transaction for both.
    `void` | `save(Set<NodeKey> toBeSaved, SessionCache other, SessionCache.PreSave preSaveOperation)` This method saves the changes made by both sessions within a single transaction.
    `String` | `toString()`

    - ### Methods inherited from class org.modeshape.jcr.cache.document.AbstractSessionCache

      `addContextData, checkForTransaction, clear, clear, completeTransaction, createNodeKey, createNodeKey, createNodeKeyWithIdentifier, createNodeKeyWithSource, generateIdentifier, getAllNodeKeys, getAllNodeKeysAtAndBelow, getContext, getNode, getNodeKeysAtAndBelow, getRootKey, getWorkspace, unwrap, workspaceCache, workspaceName`

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

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

- - ### Constructor Detail

    - #### WritableSessionCache

          public WritableSessionCache(ExecutionContext context,
                              WorkspaceCache workspaceCache,
                              SessionEnvironment sessionContext)

      Create a new SessionCache that can be used for making changes to the workspace.
      Parameters:
        `context` - the execution context; may not be null
        `workspaceCache` - the (shared) workspace cache; may not be null
        `sessionContext` - the context for the session; may not be null

  - ### Method Detail

    - #### assertInSession

          protected final void assertInSession(SessionNode node)

    - #### logger

          protected Logger logger()

      Specified by:
        `logger` in class `AbstractSessionCache`

    - #### getNode

          public CachedNode getNode(NodeKey key)

      Description copied from interface: `CachedNodeSupplier`
      Get the cached representation of the node with the supplied node key.
      Specified by:
        `getNode` in interface `CachedNodeSupplier`
      Overrides:
        `getNode` in class `AbstractSessionCache`
      Parameters:
        `key` - the node key; may not be null
      Returns:
        the cached node, or null if there is no such node

    - #### mutable

          public SessionNode mutable(NodeKey key)

      Description copied from interface: `SessionCache`
      Get a mutable form of the node with the supplied key. If this session already has a mutable node in its cache, that existing mutable node is returned; otherwise, a new mutable node is created and added to the session's cache.
      Specified by:
        `mutable` in interface `SessionCache`
      Specified by:
        `mutable` in class `AbstractSessionCache`
      Parameters:
        `key` - the key for the node; may not be null
      Returns:
        the mutable child node

    - #### isReadOnly

          public boolean isReadOnly()

      Description copied from interface: `SessionCache`
      Returns whether this cache is readonly.
      Returns:
        true if this cache is readonly, or false otherwise

    - #### doClear

          protected void doClear()

      Specified by:
        `doClear` in class `AbstractSessionCache`

    - #### doClear

          protected void doClear(CachedNode node)

      Specified by:
        `doClear` in class `AbstractSessionCache`

    - #### getChangedNodeKeys

          public Set<NodeKey> getChangedNodeKeys()

      Description copied from interface: `SessionCache`
      Returns a set with the `NodeKey`s of the transient nodes from this cache. Please note that there may be nodes which have been removed by another session.
      Returns:
        a `Set` with the changed keys, or an empty set if `SessionCache.hasChanges()` is false. The returned set is a mutable copy of the underlying set.

    - #### getChangedNodeKeysAtOrBelow

          public Set<NodeKey> getChangedNodeKeysAtOrBelow(CachedNode srcNode)

      Description copied from interface: `SessionCache`
      Returns a set with the `NodeKey`s of the transient nodes from this cache which are at or below the path of the given node
      Parameters:
        `srcNode` - a non-null `CachedNode` instance
      Returns:
        a Set of nodekeys, or an empty set if no nodes are found

    - #### hasChanges

          public boolean hasChanges()

      Description copied from interface: `SessionCache`
      Determine whether this session has any transient, unsaved changes.
      Returns:
        true if there are unsaved changes, or false otherwise

    - #### logChangesBeingSaved

          protected final void logChangesBeingSaved(Iterable<NodeKey> firstNodesInOrder,
                                  Map<NodeKey,SessionNode> firstNodes,
                                  Iterable<NodeKey> secondNodesInOrder,
                                  Map<NodeKey,SessionNode> secondNodes)

    - #### save

          public void save()

      Persist the changes within a transaction.
      Throws:
        `LockFailureException` - if a requested lock could not be made
        `DocumentAlreadyExistsException` - if this session attempts to create a document that has the same key as an existing document
        `DocumentNotFoundException` - if one of the modified documents was removed by another session

    - #### save

          protected void save(SessionCache.PreSave preSaveOperation)

    - #### clearState

          protected void clearState()

    - #### clearState

          protected void clearState(Iterable<NodeKey> savedNodesInOrder)

    - #### save

          public void save(SessionCache other,
                  SessionCache.PreSave preSaveOperation)

      Description copied from interface: `SessionCache`
      Saves all changes made within this session and the supplied session, using a single transaction for both.
      Parameters:
        `other` - another session whose changes should be saved with this session's changes; may not be null
        `preSaveOperation` - the set of operations to run against the new and changed nodes prior to saving; may be null

    - #### save

          public void save(Set<NodeKey> toBeSaved,
                  SessionCache other,
                  SessionCache.PreSave preSaveOperation)

      This method saves the changes made by both sessions within a single transaction. Note that this must be used with caution, as this method attempts to get write locks on both sessions, meaning they cannot be concurrently used elsewhere (otherwise deadlocks might occur).
      Parameters:
        `toBeSaved` - the set of keys identifying the nodes whose changes should be saved; may not be null
        `other` - the other session
        `preSaveOperation` - the pre-save operation
      Throws:
        `LockFailureException` - if a requested lock could not be made
        `DocumentAlreadyExistsException` - if this session attempts to create a document that has the same key as an existing document
        `DocumentNotFoundException` - if one of the modified documents was removed by another session
        `DocumentStoreException` - if there is a problem storing or retrieving a document

    - #### persistChanges

          protected ChangeSet persistChanges(Iterable<NodeKey> changedNodesInOrder,
                                 SessionEnvironment.Monitor monitor)

      Persist the changes within an already-established transaction.
      Parameters:
        `changedNodesInOrder` - the nodes that are to be persisted; may not be null
        `monitor` - the monitor for these changes; may be null if not needed
      Returns:
        the ChangeSet encapsulating the changes that were made
      Throws:
        `LockFailureException` - if a requested lock could not be made
        `DocumentAlreadyExistsException` - if this session attempts to create a document that has the same key as an existing document
        `DocumentNotFoundException` - if one of the modified documents was removed by another session

    - #### add

          protected SessionNode add(SessionNode newNode)

    - #### destroy

          public void destroy(NodeKey key)

      Description copied from interface: `SessionCache`
      Destroy the subgraph with the supplied node as the top node in the subgraph. This method should be called after the node is already `removed from its parent node`.
      Parameters:
        `key` - the key for the top node in the subgraph; may not be null

    - #### isDestroyed

          public boolean isDestroyed(NodeKey key)

      Description copied from interface: `SessionCache`
      Return whether the node with the supplied key has been removed using this session but not yet persisted.
      Parameters:
        `key` - the for the node; may not be null
      Returns:
        true if the node was removed in this session, or false otherwise

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

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