org.modeshape.jcr.query

## Class QueryContext

- java.lang.Object
- - org.modeshape.jcr.query.QueryContext

-     @ThreadSafe
      public class QueryContext
      extends Object

  An immutable context in which queries are to be executed. Each query context defines the information that is available during query execution.

  The only mutable state on this context is whether the query has been `cancelled`.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected BufferManager` | `bufferManager`
    `protected ExecutionContext` | `context`
    `protected PlanHints` | `hints`
    `protected RepositoryIndexes` | `indexDefns`
    `protected NodeTypes` | `nodeTypes`
    `protected Map<String,NodeCache>` | `overriddenNodeCachesByWorkspaceName`
    `protected Problems` | `problems`
    `protected static AtomicLong` | `QUERY_COUNTER`
    `protected RepositoryCache` | `repositoryCache`
    `protected Schemata` | `schemata`
    `protected TypeSystem` | `typeSystem`
    `protected Map<String,Object>` | `variables`
    `protected Set<String>` | `workspaceNames`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `` | `QueryContext(ExecutionContext context, RepositoryCache repositoryCache, Set<String> workspaceNames, Map<String,NodeCache> overriddenNodeCachesByWorkspaceName, Schemata schemata, RepositoryIndexes indexDefns, NodeTypes nodeTypes, BufferManager bufferManager, PlanHints hints, Problems problems, Map<String,Object> variables)` Create a new context for query execution.
    `protected` | `QueryContext(ExecutionContext context, RepositoryCache repositoryCache, Set<String> workspaceNames, Map<String,NodeCache> overriddenNodeCachesByWorkspaceName, Schemata schemata, RepositoryIndexes indexDefns, NodeTypes nodeTypes, BufferManager bufferManager, PlanHints hints, Problems problems, Map<String,Object> variables, long id)` Create a new context for query execution.
    `` | `QueryContext(ExecutionContext context, RepositoryCache repositoryCache, Set<String> workspaceNames, Schemata schemata, RepositoryIndexes indexDefns, NodeTypes nodeTypes, BufferManager bufferManager)` Create a new context for query execution.
    `` | `QueryContext(ExecutionContext context, RepositoryCache repositoryCache, Set<String> workspaceNames, Schemata schemata, RepositoryIndexes indexDefns, NodeTypes nodeTypes, BufferManager bufferManager, PlanHints hints, Problems problems)` Create a new context for query execution.
    `protected` | `QueryContext(QueryContext original)` Create a new context that is a copy of the supplied context.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `cancel()` Cancel the query if it is currently running.
    `boolean` | `equals(Object obj)`
    `BufferManager` | `getBufferManager()`
    `ExecutionContext` | `getExecutionContext()` Get the execution context in which the query is to be evaluated
    `PlanHints` | `getHints()` Get the plan hints.
    `RepositoryIndexes` | `getIndexDefinitions()` Get the current index definitions.
    `NamespaceRegistry` | `getNamespaceRegistry()` Get the namespace registry with durable prefixes as used by the query indexes.
    `NodeCache` | `getNodeCache(String workspaceName)` Get the NodeCache for the given workspace name.
    `NodeTypes` | `getNodeTypes()` Get an immutable snapshot of the node types.
    `Problems` | `getProblems()` Get the problem container used by this query context.
    `RepositoryCache` | `getRepositoryCache()` Get the RepositoryCache instance that should be used to load the result tuple values.
    `Schemata` | `getSchemata()` Get the definition of the tables available within this query context.
    `TypeSystem` | `getTypeSystem()` Get the interface for working with literal values and types.
    `Map<String,Object>` | `getVariables()` Get the variables that are to be substituted into the `BindVariableName` used in the query.
    `Set<String>` | `getWorkspaceNames()` Get the names of each workspace that is to be queried.
    `int` | `hashCode()`
    `long` | `id()` Get the local identifier used within the query engine to identify a query context.
    `boolean` | `isCancelled()`
    `QueryContext` | `with(Map<String,Object> variables)` Obtain a copy of this context, except that the copy uses the supplied variables.
    `QueryContext` | `with(PlanHints hints)` Obtain a copy of this context, except that the copy uses the supplied hints.
    `QueryContext` | `with(Problems problems)` Obtain a copy of this context, except that the copy uses the supplied problem container.
    `QueryContext` | `with(Schemata schemata)` Obtain a copy of this context, except that the copy uses the supplied schemata.

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

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

- - ### Field Detail

    - #### QUERY_COUNTER

          protected static final AtomicLong QUERY_COUNTER

    - #### context

          protected final ExecutionContext context

    - #### repositoryCache

          protected final RepositoryCache repositoryCache

    - #### typeSystem

          protected final TypeSystem typeSystem

    - #### hints

          protected final PlanHints hints

    - #### nodeTypes

          protected final NodeTypes nodeTypes

    - #### schemata

          protected final Schemata schemata

    - #### indexDefns

          protected final RepositoryIndexes indexDefns

    - #### problems

          protected final Problems problems

    - #### variables

          protected final Map<String,Object> variables

    - #### workspaceNames

          protected final Set<String> workspaceNames

    - #### overriddenNodeCachesByWorkspaceName

          protected final Map<String,NodeCache> overriddenNodeCachesByWorkspaceName

    - #### bufferManager

          protected final BufferManager bufferManager

  - ### Constructor Detail

    - #### QueryContext

          protected QueryContext(ExecutionContext context,
                      RepositoryCache repositoryCache,
                      Set<String> workspaceNames,
                      Map<String,NodeCache> overriddenNodeCachesByWorkspaceName,
                      Schemata schemata,
                      RepositoryIndexes indexDefns,
                      NodeTypes nodeTypes,
                      BufferManager bufferManager,
                      PlanHints hints,
                      Problems problems,
                      Map<String,Object> variables,
                      long id)

      Create a new context for query execution.
      Parameters:
        `context` - the context in which the query is being executed; may not be null
        `repositoryCache` - the repository cache that should be used to load results; may be null if no results are to be loaded
        `workspaceNames` - the name of each workspace to be queried, or an empty set if all the workspaces should be queried; may not be null
        `overriddenNodeCachesByWorkspaceName` - the NodeCache instances that should be used to load results, which will be used instead of the RepositoryCache's NodeCache for a given workspace name; may be null or empty
        `schemata` - the schemata
        `indexDefns` - the definitions for the currently-defined indexes; never null
        `nodeTypes` - the snapshot of the node types; may not be null
        `bufferManager` - the buffer manager; may not be null
        `hints` - the hints, or null if there are no hints
        `problems` - the problems container, or null if a new problems container should be created
        `variables` - the mapping of variables and values, or null if there are no such variables
        `id` - the identifier for this query context
      Throws:
        `IllegalArgumentException` - if the context, workspace name, or schemata are null

    - #### QueryContext

          public QueryContext(ExecutionContext context,
                      RepositoryCache repositoryCache,
                      Set<String> workspaceNames,
                      Map<String,NodeCache> overriddenNodeCachesByWorkspaceName,
                      Schemata schemata,
                      RepositoryIndexes indexDefns,
                      NodeTypes nodeTypes,
                      BufferManager bufferManager,
                      PlanHints hints,
                      Problems problems,
                      Map<String,Object> variables)

      Create a new context for query execution.
      Parameters:
        `context` - the context in which the query is being executed; may not be null
        `repositoryCache` - the repository cache that should be used to load results; may be null if no results are to be loaded
        `workspaceNames` - the name of each workspace to be queried, or an empty set if all the workspaces should be queried; may not be null
        `overriddenNodeCachesByWorkspaceName` - the NodeCache instances that should be used to load results, which will be used instead of the RepositoryCache's NodeCache for a given workspace name; may be null or empty
        `schemata` - the schemata
        `indexDefns` - the definitions for the currently-defined indexes; never null
        `nodeTypes` - the snapshot of the node types; may not be null
        `bufferManager` - the buffer manager; may not be null
        `hints` - the hints, or null if there are no hints
        `problems` - the problems container, or null if a new problems container should be created
        `variables` - the mapping of variables and values, or null if there are no such variables
      Throws:
        `IllegalArgumentException` - if the context, workspace name, or schemata are null

    - #### QueryContext

          public QueryContext(ExecutionContext context,
                      RepositoryCache repositoryCache,
                      Set<String> workspaceNames,
                      Schemata schemata,
                      RepositoryIndexes indexDefns,
                      NodeTypes nodeTypes,
                      BufferManager bufferManager,
                      PlanHints hints,
                      Problems problems)

      Create a new context for query execution.
      Parameters:
        `context` - the context in which the query is being executed; may not be null
        `repositoryCache` - the repository cache that should be used to load results; may not be null
        `workspaceNames` - the name of each workspace to be queried, or an empty set if all the workspaces should be queried; may not be null
        `schemata` - the schemata
        `indexDefns` - the definitions for the currently-defined indexes; never null
        `nodeTypes` - the snapshot of the node types; may not be null
        `bufferManager` - the buffer manager; may not be null
        `hints` - the hints, or null if there are no hints
        `problems` - the problems container, or null if a new problems container should be created
      Throws:
        `IllegalArgumentException` - if the context, workspace name, or schemata are null

    - #### QueryContext

          public QueryContext(ExecutionContext context,
                      RepositoryCache repositoryCache,
                      Set<String> workspaceNames,
                      Schemata schemata,
                      RepositoryIndexes indexDefns,
                      NodeTypes nodeTypes,
                      BufferManager bufferManager)

      Create a new context for query execution.
      Parameters:
        `context` - the context in which the query is being executed; may not be null
        `repositoryCache` - the repository cache that should be used to load results; may not be null
        `workspaceNames` - the name of each workspace to be queried, or an empty set if all the workspaces should be queried; may not be null
        `schemata` - the schemata
        `indexDefns` - the definitions for the currently-defined indexes; never null
        `nodeTypes` - the snapshot of the node types; may not be null
        `bufferManager` - the buffer manager; may not be null
      Throws:
        `IllegalArgumentException` - if the context, workspace name, or schemata are null

    - #### QueryContext

          protected QueryContext(QueryContext original)

      Create a new context that is a copy of the supplied context. This constructor is useful for subclasses that wish to add store additional fields in a QueryContext.
      Parameters:
        `original` - the original context
      Throws:
        `IllegalArgumentException` - if the original is null

  - ### Method Detail

    - #### cancel

          public final boolean cancel()

      Cancel the query if it is currently running. Note that this method does not block until the query is cancelled; it merely marks the query as being cancelled, and the query will terminate at its next available opportunity.
      Returns:
        true if the query was executing and will be cancelled, or false if the query was no longer running (because it had finished successfully or had already been cancelled) and could not be cancelled.

    - #### isCancelled

          public final boolean isCancelled()

    - #### id

          public final long id()

      Get the local identifier used within the query engine to identify a query context. These identifiers are neither durable nor guaranteed to be unique over extended periods of time.
      Returns:
        the identifier

    - #### getNodeCache

          public NodeCache getNodeCache(String workspaceName)
                                 throws WorkspaceNotFoundException

      Get the NodeCache for the given workspace name. The result will either be the overridden value supplied in the constructor or the workspace cache from the referenced RepositoryCache.
      Parameters:
        `workspaceName` - the name of the workspace
      Returns:
        the node cache; never null
      Throws:
        `WorkspaceNotFoundException` - if there is no workspace with the supplied name

    - #### getNamespaceRegistry

          public NamespaceRegistry getNamespaceRegistry()

      Get the namespace registry with durable prefixes as used by the query indexes.
      Returns:
        the durable namespace registry; never null

    - #### getRepositoryCache

          public RepositoryCache getRepositoryCache()

      Get the RepositoryCache instance that should be used to load the result tuple values.
      Returns:
        the node cache

    - #### getIndexDefinitions

          public RepositoryIndexes getIndexDefinitions()

      Get the current index definitions.
      Returns:
        the immutable index definitions; never null

    - #### getExecutionContext

          public ExecutionContext getExecutionContext()

      Get the execution context in which the query is to be evaluated
      Returns:
        the execution context; never null

    - #### getWorkspaceNames

          public Set<String> getWorkspaceNames()

      Get the names of each workspace that is to be queried.
      Returns:
        the workspace name; never null

    - #### getTypeSystem

          public TypeSystem getTypeSystem()

      Get the interface for working with literal values and types.
      Returns:
        the type system; never null

    - #### getHints

          public final PlanHints getHints()

      Get the plan hints.
      Returns:
        the plan hints; never null

    - #### getProblems

          public final Problems getProblems()

      Get the problem container used by this query context. Any problems that have been encountered will be accumlated in this container.
      Returns:
        the problem container; never null

    - #### getSchemata

          public Schemata getSchemata()

      Get the definition of the tables available within this query context.
      Returns:
        the schemata; never null

    - #### getNodeTypes

          public NodeTypes getNodeTypes()

      Get an immutable snapshot of the node types.
      Returns:
        the node types; never null

    - #### getBufferManager

          public BufferManager getBufferManager()

    - #### getVariables

          public Map<String,Object> getVariables()

      Get the variables that are to be substituted into the `BindVariableName` used in the query.
      Returns:
        immutable map of variable values keyed by their name; never null but possibly empty

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `Object`

    - #### equals

          public boolean equals(Object obj)

      Overrides:
        `equals` in class `Object`
      See Also:
        `Object.equals(java.lang.Object)`

    - #### with

          public QueryContext with(Schemata schemata)

      Obtain a copy of this context, except that the copy uses the supplied schemata.
      Parameters:
        `schemata` - the schemata that should be used in the new context
      Returns:
        the new context; never null
      Throws:
        `IllegalArgumentException` - if the schemata reference is null

    - #### with

          public QueryContext with(PlanHints hints)

      Obtain a copy of this context, except that the copy uses the supplied hints.
      Parameters:
        `hints` - the hints that should be used in the new context
      Returns:
        the new context; never null
      Throws:
        `IllegalArgumentException` - if the hints reference is null

    - #### with

          public QueryContext with(Problems problems)

      Obtain a copy of this context, except that the copy uses the supplied problem container.
      Parameters:
        `problems` - the problems that should be used in the new context; may be null if a new problem container should be used
      Returns:
        the new context; never null

    - #### with

          public QueryContext with(Map<String,Object> variables)

      Obtain a copy of this context, except that the copy uses the supplied variables.
      Parameters:
        `variables` - the variables that should be used in the new context; may be null if there are no such variables
      Returns:
        the new context; never null

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