org.datanucleus.store.query
Class Query

java.lang.Object
  extended by org.datanucleus.store.query.Query
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
AbstractJavaQuery, AbstractSQLQuery

public abstract class Query
extends java.lang.Object
implements java.io.Serializable

Abstract implementation for all queries in DataNucleus. Implementations of JDOQL, SQL, JPQL, etc should extend this.

See Also:
Serialized Form

Nested Class Summary
 class Query.SubqueryDefinition
          Simple representation of a subquery, its candidate, params and variables.
 
Field Summary
static short BULK_DELETE
           
static short BULK_UPDATE
           
protected  java.lang.Class candidateClass
          The candidate class for this query.
protected  java.lang.String candidateClassName
          Name of the candidate class (used when specified via Single-String).
protected  QueryCompilation compilation
          Query compilation (when using the generic query compiler).
protected  java.lang.String explicitParameters
          Any explicit parameters defined for this query.
protected  java.lang.String explicitVariables
          Any explicit variables defined for this query.
protected  java.util.Map extensions
          Any extensions
protected  java.lang.String filter
          The filter for the query.
protected  java.lang.String from
          From clause of the query (optional).
protected  long fromInclNo
          Query result range start position (included).
protected  java.lang.String grouping
          Grouping clause for the query, for use with aggregate expressions.
protected  java.lang.String having
          Having clause for the query
protected  boolean ignoreCache
          Whether to ignore dirty instances in the query.
static java.lang.String IMPLICIT_POSITIONAL_PARAM_PREFIX
          Prefix to add to names of positional implicit parameters, when passed in via execute call.
protected  java.util.HashMap implicitParameters
          Map of implicit parameters, keyed by the name/number(as String).
protected  java.lang.String imports
          Any import declarations for the types used in the query.
protected static Localiser LOCALISER
          Localiser for messages.
protected  ObjectManager om
          Object Manager managing this query.
protected  java.lang.String ordering
          Ordering clause for the query, governing the order objects are returned.
protected  java.lang.String[] parameterNames
          Array of (explicit) parameter names.
protected  Imports parsedImports
          The imports definition.
protected  java.util.HashSet queryResults
          All query results obtained from this query.
protected  java.lang.String range
          String form of the query result range.
protected  java.lang.String result
          Specification of the result of the query e.g aggregates etc.
protected  java.lang.Class resultClass
          User-defined class that best represents the results of a query.
protected  java.lang.String resultClassName
          Name of user-defined class to use as the result class.
protected  boolean resultDistinct
          Whether the results are marked as distinct.
static short SELECT
           
protected  boolean subclasses
          Whether to allow subclasses of the candidate class be returned.
protected  java.util.Map subqueries
          Any subqueries, keyed by the variable name that they represent.
protected  long toExclNo
          Query result range end position (excluded).
protected  short type
          Type of query.
protected  boolean unique
          Whether to return single value, or collection from the query.
protected  boolean unmodifiable
          Whether the query can be modified
protected  java.lang.String update
          UPDATE clause of a query (JPQL).
 
Constructor Summary
Query(ObjectManager om)
          Constructs a new query instance that uses the given persistence manager.
 
Method Summary
 void addExtension(java.lang.String key, java.lang.Object value)
          Add a vendor-specific extension this query.
 void addSubquery(Query sub, java.lang.String variableDecl, java.lang.String candidateExpr, java.util.Map paramMap)
          Method to add a subquery to this query.
protected  boolean applyRangeChecks()
          Method to return if the query results should have the range checked and unnecessary rows discarded.
protected  void assertIsModifiable()
          Method to throw an exception if the query is currently not modifiable.
 void close(java.lang.Object queryResult)
          Close a query result and release any resources associated with it.
 void closeAll()
          Close all query results associated with this Query instance, and release all resources associated with them.
 void compile()
          Verify the elements of the query and provide a hint to the query to prepare and optimize an execution plan.
protected abstract  void compileInternal(boolean forExecute, java.util.Map parameterValues)
          Method to compile the query.
 void declareExplicitParameters(java.lang.String parameters)
          Method to define the explicit parameters.
 void declareExplicitVariables(java.lang.String variables)
          Method to define the explicit variables for the query.
 void declareImports(java.lang.String imports)
          Set the import statements to be used to identify the fully qualified name of variables or parameters.
 long deletePersistentAll()
          Method to delete all objects found by this query, catering for cascade changes and updates to in-memory objects.
 long deletePersistentAll(java.util.Map parameters)
          Method to delete all objects found by this query, catering for cascade changes and updates to in-memory objects.
 long deletePersistentAll(java.lang.Object[] parameterValues)
          Method to delete all objects found by this query, catering for cascade changes and updates to in-memory objects.
protected  void discardCompiled()
          Utility to remove any previous compilation of this Query.
 boolean equals(java.lang.Object obj)
          Equality operator.
 java.lang.Object execute()
          Execute the query and return the filtered List.
 java.lang.Object execute(java.lang.Object p1)
          Execute the query and return the filtered List.
 java.lang.Object execute(java.lang.Object p1, java.lang.Object p2)
          Execute the query and return the filtered List.
 java.lang.Object execute(java.lang.Object p1, java.lang.Object p2, java.lang.Object p3)
          Execute the query and return the filtered List.
protected  java.lang.Object executeQuery(java.util.Map parameters)
          Method to execute the actual query.
 java.lang.Object executeWithArray(java.lang.Object[] parameterValues)
          Execute the query and return the filtered List.
 java.lang.Object executeWithMap(java.util.Map parameters)
          Execute the query and return the filtered result(s).
 java.lang.Class getCandidateClass()
          Accessor for the class of the candidate instances of the query.
 java.lang.String getCandidateClassName()
          Accessor for the candidate class name.
 java.lang.String getExplicitParameters()
          Accessor for the explicit parameters specification.
 java.lang.String getExplicitVariables()
          Accessor for the explicit variables specification.
 java.lang.Object getExtension(java.lang.String key)
          Accessor for the value of an extension for this query.
 java.util.Map getExtensions()
          Accessor for the extensions defined for this query.
 FetchPlan getFetchPlan()
          This method retrieves the fetch plan associated with the Query.
 java.lang.String getFilter()
          Accessor for the filter specification.
 java.lang.String getFrom()
          Accessor for the FROM clause of the query.
 java.lang.String getGrouping()
          Accessor for the grouping string for the query.
 java.lang.String getHaving()
          Accessor for the having string for the query.
 boolean getIgnoreCache()
          Accessor for the ignoreCache option setting.
 java.util.Map getImplicitParameters()
          Accessor for the implicit parameters.
 java.lang.String getImports()
          Accessor for the imports specification.
 java.util.Map getInputParameters()
          Accessor for the input parameters for this query.
 ObjectManager getObjectManager()
          Accessor for the ObjectManager associated with this Query.
 java.lang.String getOrdering()
          Accessor for the ordering string for the query.
protected  java.util.Map getParameterMapForValues(java.lang.Object[] parameterValues)
          Convenience method to convert the input parameters into a parameter map keyed by the parameter name.
 Imports getParsedImports()
          Accessor for the parsed imports.
 java.lang.String getRange()
          Accessor for the range specification.
 long getRangeFromIncl()
          Accessor for the range lower limit (inclusive).
 long getRangeToExcl()
          Accessor for the range upper limit (exclusive).
 java.lang.String getResult()
          Accessor for the result specification string.
 java.lang.Class getResultClass()
          Accessor for the result class.
 java.lang.String getResultClassName()
          Accessor for the name of the result class.
 boolean getResultDistinct()
          Accessor for whether the results are distinct.
 StoreManager getStoreManager()
          Accessor for the StoreManager associated with this Query.
 Query.SubqueryDefinition getSubqueryForVariable(java.lang.String variableName)
          Accessor for the subquery for the supplied variable.
 short getType()
          Accessor for the query type.
 java.lang.String getUpdate()
          Accessor for the UPDATE clause of the JPQL query.
 int hashCode()
          Hashcode generator.
 boolean hasSubqueryForVariable(java.lang.String variableName)
          Accessor for whether there is a subquery for the specified variable name.
protected  boolean isCompiled()
          Method to return if the query is compiled.
 boolean isSubclasses()
          Accessor for whether this query includes subclasses
 boolean isUnique()
          Accessor for whether the query results are unique.
 boolean isUnmodifiable()
          Accessor for unmodifiable.
protected abstract  long performDeletePersistentAll(java.util.Map parameters)
          Method to actually execute the deletion of objects.
protected abstract  java.lang.Object performExecute(java.util.Map parameters)
          Method to actually execute the query.
protected  void prepareDatastore()
          Convenience method that will flush any outstanding updates to the datastore.
 java.lang.Class resolveClassDeclaration(java.lang.String classDecl)
          Utility to resolve the declaration to a particular class.
 boolean resultHasOnlyAggregates(java.lang.String result)
          Convenience method to simple-parse the "result" clause returning if it includes solely aggregates.
 void setCandidateClassName(java.lang.String candidateClassName)
          Convenience method to set the name of the candidate class.
abstract  void setCandidates(java.util.Collection pcs)
          Set the candidate Collection to query.
abstract  void setCandidates(Extent pcs)
          Set the candidate Extent to query.
 void setClass(java.lang.Class candidateClass)
          Mutator for the class of the candidate instances of the query.
 void setExtensions(java.util.Map extensions)
          Set multiple extensions, or use null to clear extensions.
 void setFetchPlan(FetchPlan fp)
          Mutator for the FetchPlan of the query.
 void setFilter(java.lang.String filter)
          Set the filter for the query.
 void setFrom(java.lang.String from)
          Set the candidates to the query.
 void setGrouping(java.lang.String grouping)
          Set the grouping specification for the result Collection.
 void setHaving(java.lang.String having)
          Set the having specification for the result Collection.
 void setIgnoreCache(boolean ignoreCache)
          Set the ignoreCache option.
 void setImplicitParameter(int position, java.lang.Object value)
          Method to set the value of a numbered implicit parameter where known before execution.
 void setImplicitParameter(java.lang.String name, java.lang.Object value)
          Method to set the value of a named implicit parameter where known before execution.
 void setOrdering(java.lang.String ordering)
          Set the ordering specification for the result Collection.
 void setRange(long fromIncl, long toExcl)
          Set the range of the results.
 void setRange(java.lang.String range)
          Set the range of the results.
 void setResult(java.lang.String result)
          Set the result for the results.
 void setResultClass(java.lang.Class result_cls)
          Set the result class for the results.
 void setResultClassName(java.lang.String resultClassName)
          Convenience method to set the name of the result class.
 void setResultDistinct(boolean distinct)
          Mark the result as distinct (or not).
 void setResultMetaData(QueryResultMetaData qrmd)
          Method to set the MetaData defining the result.
 void setSubclasses(boolean subclasses)
          Mutator for whether this query includes subclasses
 void setType(short type)
          Mutator to set the query type.
 void setUnique(boolean unique)
          Set the uniqueness of the results.
 void setUnmodifiable()
          Mutator for unmodifiable.
 void setUpdate(java.lang.String update)
          Set the UPDATE clause of the query.
protected  boolean shouldReturnSingleRow()
          Convenience method to return whether the query should return a single row.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOCALISER

protected static final Localiser LOCALISER
Localiser for messages.


om

protected final transient ObjectManager om
Object Manager managing this query.


IMPLICIT_POSITIONAL_PARAM_PREFIX

public static final java.lang.String IMPLICIT_POSITIONAL_PARAM_PREFIX
Prefix to add to names of positional implicit parameters, when passed in via execute call.

See Also:
Constant Field Values

SELECT

public static final short SELECT
See Also:
Constant Field Values

BULK_UPDATE

public static final short BULK_UPDATE
See Also:
Constant Field Values

BULK_DELETE

public static final short BULK_DELETE
See Also:
Constant Field Values

type

protected short type
Type of query.


candidateClass

protected java.lang.Class candidateClass
The candidate class for this query.


candidateClassName

protected java.lang.String candidateClassName
Name of the candidate class (used when specified via Single-String).


subclasses

protected boolean subclasses
Whether to allow subclasses of the candidate class be returned.


unique

protected boolean unique
Whether to return single value, or collection from the query.


from

protected transient java.lang.String from
From clause of the query (optional).


update

protected transient java.lang.String update
UPDATE clause of a query (JPQL).


result

protected java.lang.String result
Specification of the result of the query e.g aggregates etc. Doesn't include any "distinct".


resultDistinct

protected boolean resultDistinct
Whether the results are marked as distinct. This is extracted out of the result for clarity.


resultClass

protected java.lang.Class resultClass
User-defined class that best represents the results of a query. Populated if specified via setResultClass().


resultClassName

protected java.lang.String resultClassName
Name of user-defined class to use as the result class.


filter

protected java.lang.String filter
The filter for the query.


imports

protected java.lang.String imports
Any import declarations for the types used in the query.


explicitVariables

protected java.lang.String explicitVariables
Any explicit variables defined for this query.


explicitParameters

protected java.lang.String explicitParameters
Any explicit parameters defined for this query.


ordering

protected java.lang.String ordering
Ordering clause for the query, governing the order objects are returned.


grouping

protected java.lang.String grouping
Grouping clause for the query, for use with aggregate expressions.


having

protected java.lang.String having
Having clause for the query


range

protected java.lang.String range
String form of the query result range. Only populated if specified via String.


fromInclNo

protected long fromInclNo
Query result range start position (included). Either specified, or compiled from "range".


toExclNo

protected long toExclNo
Query result range end position (excluded). Either specified, or compiled from "range".


unmodifiable

protected boolean unmodifiable
Whether the query can be modified


ignoreCache

protected boolean ignoreCache
Whether to ignore dirty instances in the query.


extensions

protected java.util.Map extensions
Any extensions


subqueries

protected java.util.Map subqueries
Any subqueries, keyed by the variable name that they represent.


implicitParameters

protected transient java.util.HashMap implicitParameters
Map of implicit parameters, keyed by the name/number(as String).


parsedImports

protected transient Imports parsedImports
The imports definition.


parameterNames

protected transient java.lang.String[] parameterNames
Array of (explicit) parameter names.


compilation

protected transient QueryCompilation compilation
Query compilation (when using the generic query compiler).


queryResults

protected transient java.util.HashSet queryResults
All query results obtained from this query. This is required because the query can be executed multiple times changing the input slightly each time for example.

Constructor Detail

Query

public Query(ObjectManager om)
Constructs a new query instance that uses the given persistence manager.

Parameters:
om - The ObjectManager for this query.
Method Detail

discardCompiled

protected void discardCompiled()
Utility to remove any previous compilation of this Query.


equals

public boolean equals(java.lang.Object obj)
Equality operator.

Overrides:
equals in class java.lang.Object
Parameters:
obj - Object to compare against
Returns:
Whether this and the other object are equal.

hashCode

public int hashCode()
Hashcode generator.

Overrides:
hashCode in class java.lang.Object
Returns:
The Hashcode for this object.

getType

public short getType()
Accessor for the query type.

Returns:
The query type

setType

public void setType(short type)
Mutator to set the query type.

Parameters:
type - The query type

getStoreManager

public StoreManager getStoreManager()
Accessor for the StoreManager associated with this Query.

Returns:
the StoreManager associated with this Query.

getObjectManager

public ObjectManager getObjectManager()
Accessor for the ObjectManager associated with this Query.

Returns:
the ObjectManager associated with this Query.

addExtension

public void addExtension(java.lang.String key,
                         java.lang.Object value)
Add a vendor-specific extension this query. The key and value are not standard. An implementation must ignore keys that are not recognized.

Parameters:
key - the extension key
value - the extension value

setExtensions

public void setExtensions(java.util.Map extensions)
Set multiple extensions, or use null to clear extensions. Map keys and values are not standard. An implementation must ignore entries that are not recognized.

Parameters:
extensions -
See Also:
addExtension(java.lang.String, java.lang.Object)

getExtension

public java.lang.Object getExtension(java.lang.String key)
Accessor for the value of an extension for this query.

Parameters:
key - The key
Returns:
The value (if this extension is specified)

getExtensions

public java.util.Map getExtensions()
Accessor for the extensions defined for this query.

Returns:
Extensions

getFetchPlan

public FetchPlan getFetchPlan()
This method retrieves the fetch plan associated with the Query. It always returns the identical instance for the same Query instance. Any change made to the fetch plan affects subsequent query execution. Fetch plan is described in JDO2 $12.7

Returns:
the FetchPlan

setFetchPlan

public void setFetchPlan(FetchPlan fp)
Mutator for the FetchPlan of the query. This is called when applying a named FetchPlan.

Parameters:
fp - The FetchPlan

setUpdate

public void setUpdate(java.lang.String update)
Set the UPDATE clause of the query.

Parameters:
update - the update clause

getUpdate

public java.lang.String getUpdate()
Accessor for the UPDATE clause of the JPQL query.

Returns:
Update clause

getCandidateClass

public java.lang.Class getCandidateClass()
Accessor for the class of the candidate instances of the query.

Returns:
the Class of the candidate instances.

setClass

public void setClass(java.lang.Class candidateClass)
Mutator for the class of the candidate instances of the query.

Parameters:
candidateClass - the Class of the candidate instances.

setCandidateClassName

public void setCandidateClassName(java.lang.String candidateClassName)
Convenience method to set the name of the candidate class.

Parameters:
candidateClassName - Name of the candidate class

getCandidateClassName

public java.lang.String getCandidateClassName()
Accessor for the candidate class name.

Returns:
Name of the candidate class (if any)

setFrom

public void setFrom(java.lang.String from)
Set the candidates to the query.

Parameters:
from - the candidates

getFrom

public java.lang.String getFrom()
Accessor for the FROM clause of the query.

Returns:
From clause

setCandidates

public abstract void setCandidates(Extent pcs)
Set the candidate Extent to query. To be implemented by extensions.

Parameters:
pcs - the Candidate Extent.

setCandidates

public abstract void setCandidates(java.util.Collection pcs)
Set the candidate Collection to query. To be implemented by extensions.

Parameters:
pcs - the Candidate collection.

setFilter

public void setFilter(java.lang.String filter)
Set the filter for the query.

Parameters:
filter - the query filter.

getFilter

public java.lang.String getFilter()
Accessor for the filter specification.

Returns:
Filter specification

declareImports

public void declareImports(java.lang.String imports)
Set the import statements to be used to identify the fully qualified name of variables or parameters.

Parameters:
imports - import statements separated by semicolons.

getImports

public java.lang.String getImports()
Accessor for the imports specification.

Returns:
Imports specification

declareExplicitParameters

public void declareExplicitParameters(java.lang.String parameters)
Method to define the explicit parameters.

Parameters:
parameters - the list of parameters separated by commas

getExplicitParameters

public java.lang.String getExplicitParameters()
Accessor for the explicit parameters specification.

Returns:
Explicit parameters specification

setImplicitParameter

public void setImplicitParameter(java.lang.String name,
                                 java.lang.Object value)
Method to set the value of a named implicit parameter where known before execution.

Parameters:
name - Name of the parameter
value - Value of the parameter
Throws:
QueryInvalidParametersException - if the parameter is invalid

setImplicitParameter

public void setImplicitParameter(int position,
                                 java.lang.Object value)
Method to set the value of a numbered implicit parameter where known before execution.

Parameters:
position - Position of the parameter
value - Value of the parameter
Throws:
QueryInvalidParametersException - if the parameter is invalid

getImplicitParameters

public java.util.Map getImplicitParameters()
Accessor for the implicit parameters. Named params are keyed by the name. Positional params are keyed by the Integer(position).

Returns:
Implicit params

declareExplicitVariables

public void declareExplicitVariables(java.lang.String variables)
Method to define the explicit variables for the query.

Parameters:
variables - the variables separated by semicolons.

getExplicitVariables

public java.lang.String getExplicitVariables()
Accessor for the explicit variables specification.

Returns:
Explicit variables specification

setOrdering

public void setOrdering(java.lang.String ordering)
Set the ordering specification for the result Collection.

Parameters:
ordering - the ordering specification.

getOrdering

public java.lang.String getOrdering()
Accessor for the ordering string for the query.

Returns:
Ordering specification

setGrouping

public void setGrouping(java.lang.String grouping)
Set the grouping specification for the result Collection.

Parameters:
grouping - the grouping specification.

getGrouping

public java.lang.String getGrouping()
Accessor for the grouping string for the query.

Returns:
Grouping specification

setHaving

public void setHaving(java.lang.String having)
Set the having specification for the result Collection.

Parameters:
having - the having specification.

getHaving

public java.lang.String getHaving()
Accessor for the having string for the query.

Returns:
Having specification

setUnique

public void setUnique(boolean unique)
Set the uniqueness of the results. A value of true will return a single value (or null) where the application knows that there are 0 or 1 objects to be returned. See JDO 2.0 specification $14.6

Parameters:
unique - whether the result is unique

isUnique

public boolean isUnique()
Accessor for whether the query results are unique.

Returns:
Whether it is unique

setRange

public void setRange(long fromIncl,
                     long toExcl)
Set the range of the results. By default all results are returned but this allows specification of a range of elements required. See JDO 2.0 specification section 14.6.8

Parameters:
fromIncl - From element no (inclusive) to return
toExcl - To element no (exclusive) to return

setRange

public void setRange(java.lang.String range)
Set the range of the results. By default all results are returned but this allows specification of a range of elements required. See JDO 2.0 specification section 14.6.8

Parameters:
range - Range string

getRange

public java.lang.String getRange()
Accessor for the range specification.

Returns:
Range specification

getRangeFromIncl

public long getRangeFromIncl()
Accessor for the range lower limit (inclusive).

Returns:
Range lower limit

getRangeToExcl

public long getRangeToExcl()
Accessor for the range upper limit (exclusive).

Returns:
Range upper limit

setResult

public void setResult(java.lang.String result)
Set the result for the results.

Parameters:
result - Comma-separated result expressions

getResult

public java.lang.String getResult()
Accessor for the result specification string.

Returns:
Result specification

setResultDistinct

public void setResultDistinct(boolean distinct)
Mark the result as distinct (or not). This is not part of JDOQL/JPQL but provided for convenience.

Parameters:
distinct - Whether to treat as distinct

getResultDistinct

public boolean getResultDistinct()
Accessor for whether the results are distinct. By default this is extracted from the "result" clause.

Returns:
Whether distinct

setResultClass

public void setResultClass(java.lang.Class result_cls)
Set the result class for the results. The result class must obey various things as per the JDO 2.0 spec 14.6.12.

Parameters:
result_cls - The result class

getResultClass

public java.lang.Class getResultClass()
Accessor for the result class.

Returns:
Result class

setResultClassName

public void setResultClassName(java.lang.String resultClassName)
Convenience method to set the name of the result class.

Parameters:
resultClassName - Name of the result class

getResultClassName

public java.lang.String getResultClassName()
Accessor for the name of the result class.

Returns:
Result class name

setResultMetaData

public void setResultMetaData(QueryResultMetaData qrmd)
Method to set the MetaData defining the result. If the query doesn't support such a setting will throw a JPOXException.

Parameters:
qrmd - QueryResultMetaData

setIgnoreCache

public void setIgnoreCache(boolean ignoreCache)
Set the ignoreCache option. Currently this simply stores the ignoreCache value, and doesn't necessarily use it. The parameter is a "hint" to the query engine. TODO : Implement this fully.

Parameters:
ignoreCache - the setting of the ignoreCache option.

getIgnoreCache

public boolean getIgnoreCache()
Accessor for the ignoreCache option setting.

Returns:
the ignoreCache option setting
See Also:
setIgnoreCache(boolean)

isSubclasses

public boolean isSubclasses()
Accessor for whether this query includes subclasses

Returns:
Returns whether the query includes subclasses.

setSubclasses

public void setSubclasses(boolean subclasses)
Mutator for whether this query includes subclasses

Parameters:
subclasses - Where subclasses of the candidate class are to be included.

isUnmodifiable

public boolean isUnmodifiable()
Accessor for unmodifiable.

Returns:
Returns the unmodifiable.

assertIsModifiable

protected void assertIsModifiable()
Method to throw an exception if the query is currently not modifiable.

Throws:
NucleusUserException - Thrown when it is unmodifiable

setUnmodifiable

public void setUnmodifiable()
Mutator for unmodifiable.


addSubquery

public void addSubquery(Query sub,
                        java.lang.String variableDecl,
                        java.lang.String candidateExpr,
                        java.util.Map paramMap)
Method to add a subquery to this query.

Parameters:
sub - The subquery
variableDecl - Declaration of variables
candidateExpr - Candidate expression
paramMap - Map of parameters for this subquery

getSubqueryForVariable

public Query.SubqueryDefinition getSubqueryForVariable(java.lang.String variableName)
Accessor for the subquery for the supplied variable.

Parameters:
variableName - Name of the variable
Returns:
Subquery for the variable (if a subquery exists for this variable)

hasSubqueryForVariable

public boolean hasSubqueryForVariable(java.lang.String variableName)
Accessor for whether there is a subquery for the specified variable name.

Parameters:
variableName - Name of the variable
Returns:
Whether there is a subquery defined

prepareDatastore

protected void prepareDatastore()
Convenience method that will flush any outstanding updates to the datastore. This is intended to be used before execution so that the datastore has all relevant data present for what the query needs.


isCompiled

protected boolean isCompiled()
Method to return if the query is compiled.

Returns:
Whether it is compiled

compile

public void compile()
Verify the elements of the query and provide a hint to the query to prepare and optimize an execution plan.


compileInternal

protected abstract void compileInternal(boolean forExecute,
                                        java.util.Map parameterValues)
Method to compile the query. To be implemented by the query implementation.

Parameters:
forExecute - Whether to compile the query ready for execution (using any param values)
parameterValues - Param values keyed by name (when compiling for execution)

getParsedImports

public Imports getParsedImports()
Accessor for the parsed imports. If no imports are set then adds candidate class and user imports.

Returns:
Parsed imports

resolveClassDeclaration

public java.lang.Class resolveClassDeclaration(java.lang.String classDecl)
Utility to resolve the declaration to a particular class. Takes the passed in name, together with the defined import declarations and returns the class represented by the declaration.

Parameters:
classDecl - The declaration
Returns:
The class it resolves to (if any)
Throws:
NucleusUserException - Thrown if the class cannot be resolved.

execute

public java.lang.Object execute()
Execute the query and return the filtered List.

Returns:
the filtered List.
See Also:
executeWithArray(Object[] parameters)

execute

public java.lang.Object execute(java.lang.Object p1)
Execute the query and return the filtered List.

Parameters:
p1 - the value of the first parameter declared.
Returns:
the filtered List.
See Also:
executeWithArray(Object[] parameters)

execute

public java.lang.Object execute(java.lang.Object p1,
                                java.lang.Object p2)
Execute the query and return the filtered List.

Parameters:
p1 - the value of the first parameter declared.
p2 - the value of the second parameter declared.
Returns:
the filtered List.
See Also:
executeWithArray(Object[] parameters)

execute

public java.lang.Object execute(java.lang.Object p1,
                                java.lang.Object p2,
                                java.lang.Object p3)
Execute the query and return the filtered List.

Parameters:
p1 - the value of the first parameter declared.
p2 - the value of the second parameter declared.
p3 - the value of the third parameter declared.
Returns:
the filtered List.
See Also:
executeWithArray(Object[] parameters)

executeWithArray

public java.lang.Object executeWithArray(java.lang.Object[] parameterValues)
Execute the query and return the filtered List.

Parameters:
parameterValues - the Object array with all of the parameters.
Returns:
the filtered List.

executeWithMap

public java.lang.Object executeWithMap(java.util.Map parameters)
Execute the query and return the filtered result(s).

Parameters:
parameters - the Map containing all of the parameters.
Returns:
the filtered results (List, or Object)
Throws:
NoQueryResultsException - Thrown if no results were returned from the query.
See Also:
executeWithArray(Object[] parameters)

getInputParameters

public java.util.Map getInputParameters()
Accessor for the input parameters for this query.

Returns:
The input parameters map, with param values keyed by param name

executeQuery

protected java.lang.Object executeQuery(java.util.Map parameters)
Method to execute the actual query. Calls performExecute() allowing individual implementations to do what they require for execution (in-memory, in-datastore, etc). Applies result checking.

Parameters:
parameters - Map of parameter values keyed by parameter name
Returns:
Result
Throws:
NoQueryResultsException - Thrown if no results were returned from the query.
QueryNotUniqueException - Thrown if multiple results, yet expected one

performExecute

protected abstract java.lang.Object performExecute(java.util.Map parameters)
Method to actually execute the query. To be implemented by extending classes for the particular query language.

Parameters:
parameters - Map containing the parameters.
Returns:
Query result - QueryResult if SELECT, or Long if BULK_UPDATE, BULK_DELETE

applyRangeChecks

protected boolean applyRangeChecks()
Method to return if the query results should have the range checked and unnecessary rows discarded. This is for where the query language has specified a range but the datastore doesnt allow removal of unnecessary results in the query itself (so has to be done in post-processing). This implementation returns false and so should be overridden by query languages to match their capabilities.

Returns:
Whether to apply range checks in post-processing of results.

deletePersistentAll

public long deletePersistentAll()
Method to delete all objects found by this query, catering for cascade changes and updates to in-memory objects.

Returns:
The number of deleted objects.

deletePersistentAll

public long deletePersistentAll(java.lang.Object[] parameterValues)
Method to delete all objects found by this query, catering for cascade changes and updates to in-memory objects.

Parameters:
parameterValues - the Object array with values of the parameters.
Returns:
the filtered Collection.

deletePersistentAll

public long deletePersistentAll(java.util.Map parameters)
Method to delete all objects found by this query, catering for cascade changes and updates to in-memory objects.

Parameters:
parameters - Map of parameters for the query
Returns:
the number of deleted objects

performDeletePersistentAll

protected abstract long performDeletePersistentAll(java.util.Map parameters)
Method to actually execute the deletion of objects. To be implemented by extending classes.

Parameters:
parameters - Map containing the parameters.
Returns:
The filtered QueryResult.

close

public void close(java.lang.Object queryResult)
Close a query result and release any resources associated with it.

Parameters:
queryResult - the result of execute(...) on this Query instance.

closeAll

public void closeAll()
Close all query results associated with this Query instance, and release all resources associated with them.


shouldReturnSingleRow

protected boolean shouldReturnSingleRow()
Convenience method to return whether the query should return a single row.

Returns:
Whether it represents a unique row

resultHasOnlyAggregates

public boolean resultHasOnlyAggregates(java.lang.String result)
Convenience method to simple-parse the "result" clause returning if it includes solely aggregates. This is necessary since we need this information before creating the QueryStatement, after which we compile the result.

Parameters:
result - The result required
Returns:
Whether it has only aggregates

getParameterMapForValues

protected java.util.Map getParameterMapForValues(java.lang.Object[] parameterValues)
Convenience method to convert the input parameters into a parameter map keyed by the parameter name. If the parameters for this query are explicit then they are keyed by the names defined as input via "declareParameters()". If the parameters are implicit then they will have dummy names prefixed by "DATANUCLEUS_PARAM_".

Parameters:
parameterValues - Parameter values
Returns:
The parameter map.


Copyright © 2009. All Rights Reserved.