org.modeshape.jcr.cache

## Interface SessionCache

- All Superinterfaces:
    CachedNodeSupplier, NodeCache
  All Known Implementing Classes:
    AbstractSessionCache, JcrSession.SystemSessionCache, ReadOnlySessionCache, SessionCacheWrapper, WritableSessionCache

      public interface SessionCache
      extends NodeCache

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Interface and Description
    --- | ---
    `static interface` | `SessionCache.PreSave` The definition of a callback that can be implemented and passed to `save(SessionCache, PreSave)` and `save(Set, SessionCache, PreSave)`, allowing the caller to recieve a hook where they can interrogate each of the changed nodes and perform additional logic prior to the actual persisting of the changes.
    `static interface` | `SessionCache.SaveContext` The context of a save operation, created during each call to `save()` and passed to the `PreSave#process(MutableCachedNode, SaveContext)` invocations.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addContextData(String key, String value)` Adds a [key,value] data pair for this cache's context
    `void` | `checkForTransaction()` Check whether this session is running within a transaction.
    `void` | `clear(CachedNode node)` Clears all changes in the cache that are at or below the supplied node.
    `NodeKey` | `createNodeKey()` Create a new node key for the current source and workspace.
    `NodeKey` | `createNodeKey(String sourceName, String identifier)` Create a new node key for the current source and workspace.
    `NodeKey` | `createNodeKeyWithIdentifier(String identifier)` Create a new node key for the current source and workspace.
    `NodeKey` | `createNodeKeyWithSource(String sourceName)` Create a new node key for the current source and workspace.
    `void` | `destroy(NodeKey key)` Destroy the subgraph with the supplied node as the top node in the subgraph.
    `Set<NodeKey>` | `getChangedNodeKeys()` Returns a set with the `NodeKey`s of the transient nodes from this cache.
    `Set<NodeKey>` | `getChangedNodeKeysAtOrBelow(CachedNode node)` 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
    `ExecutionContext` | `getContext()` Get the context for this session.
    `Set<NodeKey>` | `getNodeKeysAtAndBelow(NodeKey nodeKey)` Returns a set with the `NodeKey`s of the existing nodes (persistent not transient & new) which are at and below the path of the node with the given key.
    `NodeCache` | `getWorkspace()` Get the cache the reflects the workspace content, without any of the transient, unsaved changes of this session.
    `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.
    `MutableCachedNode` | `mutable(NodeKey key)` Get a mutable form of the node with the supplied key.
    `void` | `save()` Saves all changes made within this session.
    `void` | `save(SessionCache otherSession, 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 otherSession, SessionCache.PreSave preSaveOperation)` Saves all of this session's changes that were made at or below the specified path.
    `SessionCache` | `unwrap()` Unwrap this instance.

    - ### Methods inherited from interface org.modeshape.jcr.cache.NodeCache

      `clear, getAllNodeKeys, getAllNodeKeysAtAndBelow, getNode, getRootKey`

    - ### Methods inherited from interface org.modeshape.jcr.cache.CachedNodeSupplier

      `getNode`

- - ### Method Detail

    - #### getContext

          ExecutionContext getContext()

      Get the context for this session.
      Returns:
        the session's context; never null

    - #### addContextData

          void addContextData(String key,
                            String value)

      Adds a [key,value] data pair for this cache's context
      Parameters:
        `key` - the key for the context data
        `value` - the value for the context data

    - #### save

          void save()

      Saves all changes made within this session.
      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

    - #### save

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

      Saves all of this session's changes that were made at or below the specified path. Note that this is not terribly efficient, but is done to implement the deprecated `Item.save()`.
      Parameters:
        `toBeSaved` - the set of keys identifying the nodes whose changes should be saved; may not be null
        `otherSession` - 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
      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

    - #### save

          void save(SessionCache otherSession,
                  SessionCache.PreSave preSaveOperation)

      Saves all changes made within this session and the supplied session, using a single transaction for both.
      Parameters:
        `otherSession` - 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
      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

    - #### hasChanges

          boolean hasChanges()

      Determine whether this session has any transient, unsaved changes.
      Returns:
        true if there are unsaved changes, or false otherwise

    - #### getChangedNodeKeys

          Set<NodeKey> getChangedNodeKeys()

      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 `hasChanges()` is false. The returned set is a mutable copy of the underlying set.

    - #### getChangedNodeKeysAtOrBelow

          Set<NodeKey> getChangedNodeKeysAtOrBelow(CachedNode node)
                                                   throws NodeNotFoundException

      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:
        `node` - a non-null `CachedNode` instance
      Returns:
        a Set of nodekeys, or an empty set if no nodes are found
      Throws:
        `NodeNotFoundException` - if any of changes registered in this cache refer to nodes that have been removed in the meantime.

    - #### getNodeKeysAtAndBelow

          Set<NodeKey> getNodeKeysAtAndBelow(NodeKey nodeKey)

      Returns a set with the `NodeKey`s of the existing nodes (persistent not transient & new) which are at and below the path of the node with the given key. Note that this method will attempt to load each node
      Parameters:
        `nodeKey` - the key of node which will be considered the root node
      Returns:
        a Set of nodekeys or an empty set

    - #### clear

          void clear(CachedNode node)

      Clears all changes in the cache that are at or below the supplied node.
      Parameters:
        `node` - the node at or below which all changes should be cleared; may not be null

    - #### getWorkspace

          NodeCache getWorkspace()

      Get the cache the reflects the workspace content, without any of the transient, unsaved changes of this session.
      Returns:
        the workspace cache; never null

    - #### mutable

          MutableCachedNode mutable(NodeKey key)
                                    throws NodeNotFoundException,
                                           UnsupportedOperationException

      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.
      Parameters:
        `key` - the key for the node; may not be null
      Returns:
        the mutable child node
      Throws:
        `NodeNotFoundException` - if there is no existing node in the session cache or workspace cache
        `UnsupportedOperationException` - if this session is marked for read-only operations

    - #### destroy

          void destroy(NodeKey key)
                       throws NodeNotFoundException,
                              UnsupportedOperationException

      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
      Throws:
        `NodeNotFoundException` - if there is no existing node in the session cache or workspace cache
        `UnsupportedOperationException` - if this session is marked for read-only operations

    - #### isDestroyed

          boolean isDestroyed(NodeKey key)

      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

    - #### createNodeKey

          NodeKey createNodeKey()

      Create a new node key for the current source and workspace.
      Returns:
        a new node key; never null

    - #### createNodeKeyWithIdentifier

          NodeKey createNodeKeyWithIdentifier(String identifier)

      Create a new node key for the current source and workspace.
      Parameters:
        `identifier` - the unique identifier for the key; if null, a generated identifier will be used
      Returns:
        a new node key; never null

    - #### isReadOnly

          boolean isReadOnly()

      Returns whether this cache is readonly.
      Returns:
        true if this cache is readonly, or false otherwise

    - #### createNodeKeyWithSource

          NodeKey createNodeKeyWithSource(String sourceName)

      Create a new node key for the current source and workspace.
      Parameters:
        `sourceName` - the name (not key) for the source; if null, the key for the current source is used
      Returns:
        a new node key; never null

    - #### createNodeKey

          NodeKey createNodeKey(String sourceName,
                              String identifier)

      Create a new node key for the current source and workspace.
      Parameters:
        `sourceName` - the name (not key) for the source; if null, the key for the current source is used
        `identifier` - the unique identifier for the key; if null, a generated identifier will be used
      Returns:
        a new node key; never null

    - #### checkForTransaction

          void checkForTransaction()

      Check whether this session is running within a transaction. This is commonly called by components that change persistent state. Such persistent state might not be noticed by this session cache.

    - #### unwrap

          SessionCache unwrap()

      Description copied from interface: `NodeCache`
      Unwrap this instance.
      Specified by:
        `unwrap` in interface `NodeCache`
      Returns:
        the unwrapped SessionCache instance, or this object if there is no wrapper.

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