org.modeshape.jcr.cache

## Class SessionCacheWrapper

- java.lang.Object
- - org.modeshape.jcr.cache.SessionCacheWrapper

- All Implemented Interfaces:
    CachedNodeSupplier, NodeCache, SessionCache
  Direct Known Subclasses:
    JcrSession.SystemSessionCache

      public class SessionCacheWrapper
      extends Object
      implements SessionCache

  A `SessionCache` implementation that wraps another and is suitable to extend and overwrite only those methods that are required.

- - ### Nested Class Summary

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

      `SessionCache.PreSave, SessionCache.SaveContext`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `SessionCacheWrapper(SessionCache delegate)`

  - ### 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()` Clears all changes in the cache.
    `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.
    `Iterator<NodeKey>` | `getAllNodeKeys()` Get an iterator over all node keys within this cache.
    `Iterator<NodeKey>` | `getAllNodeKeysAtAndBelow(NodeKey startingKey)` Get an iterator over all keys for the supplied node and all its descendants.
    `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.
    `CachedNode` | `getNode(ChildReference reference)` Get the cached representation of the node as represented by the supplied child reference.
    `CachedNode` | `getNode(NodeKey key)` Get the cached representation of the node with the supplied node key.
    `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.
    `NodeKey` | `getRootKey()` Get the node key for the root node.
    `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 class java.lang.Object

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

- - ### Constructor Detail

    - #### SessionCacheWrapper

          public SessionCacheWrapper(SessionCache delegate)

  - ### Method Detail

    - #### unwrap

          public SessionCache unwrap()

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

    - #### clear

          public void clear()

      Description copied from interface: `NodeCache`
      Clears all changes in the cache.
      Specified by:
        `clear` in interface `NodeCache`

    - #### getRootKey

          public NodeKey getRootKey()

      Description copied from interface: `NodeCache`
      Get the node key for the root node.
      Specified by:
        `getRootKey` in interface `NodeCache`
      Returns:
        the root node's key; never null

    - #### 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`
      Parameters:
        `key` - the node key; may not be null
      Returns:
        the cached node, or null if there is no such node

    - #### getNode

          public CachedNode getNode(ChildReference reference)

      Description copied from interface: `NodeCache`
      Get the cached representation of the node as represented by the supplied child reference. This is a convenience method that is equivalent to calling:

           getNode(reference.getKey());

      Specified by:
        `getNode` in interface `NodeCache`
      Parameters:
        `reference` - the child node reference; may not be null
      Returns:
        the cached node to which the reference points, or null if the child reference no longer points to a valid node

    - #### getAllNodeKeys

          public Iterator<NodeKey> getAllNodeKeys()

      Description copied from interface: `NodeCache`
      Get an iterator over all node keys within this cache. The order of the keys is not defined.
      Specified by:
        `getAllNodeKeys` in interface `NodeCache`
      Returns:
        an iterator over all the cache's node keys; never null

    - #### getAllNodeKeysAtAndBelow

          public Iterator<NodeKey> getAllNodeKeysAtAndBelow(NodeKey startingKey)

      Description copied from interface: `NodeCache`
      Get an iterator over all keys for the supplied node and all its descendants. The order of the keys is not defined.
      Specified by:
        `getAllNodeKeysAtAndBelow` in interface `NodeCache`
      Parameters:
        `startingKey` - the key for the node to start; may not be null
      Returns:
        an iterator over all the cache's node keys; never null

    - #### getContext

          public ExecutionContext getContext()

      Description copied from interface: `SessionCache`
      Get the context for this session.
      Specified by:
        `getContext` in interface `SessionCache`
      Returns:
        the session's context; never null

    - #### addContextData

          public void addContextData(String key,
                            String value)

      Description copied from interface: `SessionCache`
      Adds a [key,value] data pair for this cache's context
      Specified by:
        `addContextData` in interface `SessionCache`
      Parameters:
        `key` - the key for the context data
        `value` - the value for the context data

    - #### save

          public void save()

      Description copied from interface: `SessionCache`
      Saves all changes made within this session.
      Specified by:
        `save` in interface `SessionCache`

    - #### save

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

      Description copied from interface: `SessionCache`
      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()`.
      Specified by:
        `save` in interface `SessionCache`
      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

    - #### save

          public void save(SessionCache otherSession,
                  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.
      Specified by:
        `save` in interface `SessionCache`
      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

    - #### hasChanges

          public boolean hasChanges()

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

    - #### 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.
      Specified by:
        `getChangedNodeKeys` in interface `SessionCache`
      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 node)
                                                   throws NodeNotFoundException

      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
      Specified by:
        `getChangedNodeKeysAtOrBelow` in interface `SessionCache`
      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

          public Set<NodeKey> getNodeKeysAtAndBelow(NodeKey nodeKey)

      Description copied from interface: `SessionCache`
      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
      Specified by:
        `getNodeKeysAtAndBelow` in interface `SessionCache`
      Parameters:
        `nodeKey` - the key of node which will be considered the root node
      Returns:
        a Set of nodekeys or an empty set

    - #### clear

          public void clear(CachedNode node)

      Description copied from interface: `SessionCache`
      Clears all changes in the cache that are at or below the supplied node.
      Specified by:
        `clear` in interface `SessionCache`
      Parameters:
        `node` - the node at or below which all changes should be cleared; may not be null

    - #### getWorkspace

          public NodeCache getWorkspace()

      Description copied from interface: `SessionCache`
      Get the cache the reflects the workspace content, without any of the transient, unsaved changes of this session.
      Specified by:
        `getWorkspace` in interface `SessionCache`
      Returns:
        the workspace cache; never null

    - #### mutable

          public MutableCachedNode mutable(NodeKey key)
                                    throws NodeNotFoundException,
                                           UnsupportedOperationException

      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`
      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

          public void destroy(NodeKey key)
                       throws NodeNotFoundException,
                              UnsupportedOperationException

      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`.
      Specified by:
        `destroy` in interface `SessionCache`
      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

          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.
      Specified by:
        `isDestroyed` in interface `SessionCache`
      Parameters:
        `key` - the for the node; may not be null
      Returns:
        true if the node was removed in this session, or false otherwise

    - #### createNodeKey

          public NodeKey createNodeKey()

      Description copied from interface: `SessionCache`
      Create a new node key for the current source and workspace.
      Specified by:
        `createNodeKey` in interface `SessionCache`
      Returns:
        a new node key; never null

    - #### createNodeKeyWithIdentifier

          public NodeKey createNodeKeyWithIdentifier(String identifier)

      Description copied from interface: `SessionCache`
      Create a new node key for the current source and workspace.
      Specified by:
        `createNodeKeyWithIdentifier` in interface `SessionCache`
      Parameters:
        `identifier` - the unique identifier for the key; if null, a generated identifier will be used
      Returns:
        a new node key; never null

    - #### isReadOnly

          public boolean isReadOnly()

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

    - #### createNodeKeyWithSource

          public NodeKey createNodeKeyWithSource(String sourceName)

      Description copied from interface: `SessionCache`
      Create a new node key for the current source and workspace.
      Specified by:
        `createNodeKeyWithSource` in interface `SessionCache`
      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

          public NodeKey createNodeKey(String sourceName,
                              String identifier)

      Description copied from interface: `SessionCache`
      Create a new node key for the current source and workspace.
      Specified by:
        `createNodeKey` in interface `SessionCache`
      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

          public void checkForTransaction()

      Description copied from interface: `SessionCache`
      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.
      Specified by:
        `checkForTransaction` in interface `SessionCache`

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