|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.jpox.store.query.Query
public abstract class Query
Abstract implementation for all queries in JPOX. Implementations of JDOQL, SQL, JPQL, etc should extend this.
| 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 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 JPOX 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. |
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 boolean |
isCompiled
State variable for the compilation state |
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. |
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 a JPOXUserException 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[] parameters)
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. |
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. |
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.lang.String |
getImports()
Accessor for the imports specification. |
ObjectManager |
getObjectManager()
Accessor for the PersistenceManager associated with this Query. |
java.lang.String |
getOrdering()
Accessor for the ordering string for the query. |
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. |
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. |
boolean |
isCompiled()
Accessor for whether 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. |
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 |
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 abstract 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 |
|---|
protected static final Localiser LOCALISER
protected final transient ObjectManager om
public static final short SELECT
public static final short BULK_UPDATE
public static final short BULK_DELETE
protected short type
protected java.lang.Class candidateClass
protected java.lang.String candidateClassName
protected boolean subclasses
protected boolean unique
protected transient java.lang.String from
protected transient java.lang.String update
protected java.lang.String result
protected java.lang.Class resultClass
protected java.lang.String resultClassName
protected java.lang.String filter
protected java.lang.String imports
protected java.lang.String explicitVariables
protected java.lang.String explicitParameters
protected java.lang.String ordering
protected java.lang.String grouping
protected java.lang.String having
protected java.lang.String range
protected long fromInclNo
protected long toExclNo
protected boolean unmodifiable
protected boolean ignoreCache
protected java.util.Map extensions
protected java.util.Map subqueries
protected transient boolean isCompiled
protected transient java.util.HashMap implicitParameters
protected transient Imports parsedImports
protected transient java.lang.String[] parameterNames
protected transient java.util.HashSet queryResults
| Constructor Detail |
|---|
public Query(ObjectManager om)
om - The ObjectManager for this query.| Method Detail |
|---|
protected void discardCompiled()
public boolean equals(java.lang.Object obj)
equals in class java.lang.Objectobj - Object to compare against
public int hashCode()
hashCode in class java.lang.Objectpublic short getType()
public void setType(short type)
type - The query typepublic StoreManager getStoreManager()
public ObjectManager getObjectManager()
Query.getPersistenceManager()
public void addExtension(java.lang.String key,
java.lang.Object value)
key - the extension keyvalue - the extension valuepublic void setExtensions(java.util.Map extensions)
extensions - addExtension(java.lang.String, java.lang.Object)public java.lang.Object getExtension(java.lang.String key)
key - The key
public FetchPlan getFetchPlan()
public void setFetchPlan(FetchPlan fp)
fp - The FetchPlanpublic void setUpdate(java.lang.String update)
update - the update clausepublic java.lang.String getUpdate()
public java.lang.Class getCandidateClass()
Query.setClass(java.lang.Class)public void setClass(java.lang.Class candidateClass)
candidateClass - the Class of the candidate instances.Query.setClass(java.lang.Class)public void setCandidateClassName(java.lang.String candidateClassName)
candidateClassName - Name of the candidate classpublic java.lang.String getCandidateClassName()
public void setFrom(java.lang.String from)
from - the candidatespublic java.lang.String getFrom()
public abstract void setCandidates(Extent pcs)
pcs - the Candidate Extent.Query.setCandidates(javax.jdo.Extent)public abstract void setCandidates(java.util.Collection pcs)
pcs - the Candidate collection.Query.setCandidates(java.util.Collection)public void setFilter(java.lang.String filter)
filter - the query filter.Query.setFilter(java.lang.String)public java.lang.String getFilter()
public void declareImports(java.lang.String imports)
imports - import statements separated by semicolons.Query.declareImports(java.lang.String)public java.lang.String getImports()
public void declareExplicitParameters(java.lang.String parameters)
parameters - the list of parameters separated by commaspublic java.lang.String getExplicitParameters()
public void setImplicitParameter(java.lang.String name,
java.lang.Object value)
name - Name of the parametervalue - Value of the parameter
JPOXQueryInvalidParametersException - if the parameter is invalid
public void setImplicitParameter(int position,
java.lang.Object value)
position - Position of the parametervalue - Value of the parameter
JPOXQueryInvalidParametersException - if the parameter is invalidpublic void declareExplicitVariables(java.lang.String variables)
variables - the variables separated by semicolons.public java.lang.String getExplicitVariables()
public void setOrdering(java.lang.String ordering)
ordering - the ordering specification.Query.setOrdering(java.lang.String)public java.lang.String getOrdering()
public void setGrouping(java.lang.String grouping)
grouping - the grouping specification.Query.setGrouping(java.lang.String)public java.lang.String getGrouping()
public void setHaving(java.lang.String having)
having - the having specification.public java.lang.String getHaving()
public void setUnique(boolean unique)
unique - whether the result is uniqueQuery.setUnique(boolean)public boolean isUnique()
public void setRange(long fromIncl,
long toExcl)
fromIncl - From element no (inclusive) to returntoExcl - To element no (exclusive) to returnQuery.setRange(long, long)public void setRange(java.lang.String range)
range - Range stringQuery.setRange(java.lang.String)public java.lang.String getRange()
public long getRangeFromIncl()
public long getRangeToExcl()
public void setResult(java.lang.String result)
result - The result parameter consists of the optional keyword
distinct followed by a commaseparated list of named result expressions or
a result class specification.Query.setResult(java.lang.String)public java.lang.String getResult()
public void setResultClass(java.lang.Class result_cls)
result_cls - The result classQuery.setResultClass(java.lang.Class)public java.lang.Class getResultClass()
public void setResultClassName(java.lang.String resultClassName)
resultClassName - Name of the result classpublic java.lang.String getResultClassName()
public void setResultMetaData(QueryResultMetaData qrmd)
qrmd - QueryResultMetaDatapublic void setIgnoreCache(boolean ignoreCache)
ignoreCache - the setting of the ignoreCache option.Query.setIgnoreCache(boolean),
PersistenceManager.setIgnoreCache(boolean)public boolean getIgnoreCache()
setIgnoreCache(boolean),
Query.getIgnoreCache(),
PersistenceManager.getIgnoreCache()public boolean isSubclasses()
public void setSubclasses(boolean subclasses)
subclasses - Where subclasses of the candidate class are to be included.public boolean isUnmodifiable()
protected void assertIsModifiable()
JPOXUserException - Thrown when it is unmodifiablepublic void setUnmodifiable()
public void addSubquery(Query sub,
java.lang.String variableDecl,
java.lang.String candidateExpr,
java.util.Map paramMap)
sub - The subqueryvariableDecl - Declaration of variablescandidateExpr - Candidate expressionparamMap - Map of parameters for this subquerypublic Query.SubqueryDefinition getSubqueryForVariable(java.lang.String variableName)
variableName - Name of the variable
public boolean hasSubqueryForVariable(java.lang.String variableName)
variableName - Name of the variable
protected void prepareDatastore()
public boolean isCompiled()
public void compile()
protected abstract void compileInternal(boolean forExecute,
java.util.Map parameterValues)
forExecute - Whether to compile the query ready for execution (using any param values)parameterValues - Param values keyed by name (when compiling for execution)public Imports getParsedImports()
public java.lang.Class resolveClassDeclaration(java.lang.String classDecl)
classDecl - The declaration
JPOXUserException - Thrown if the class cannot be resolved.public java.lang.Object execute()
Query.execute(),
executeWithArray(Object[] parameters)public java.lang.Object execute(java.lang.Object p1)
p1 - the value of the first parameter declared.
Query.execute(Object),
executeWithArray(Object[] parameters)
public java.lang.Object execute(java.lang.Object p1,
java.lang.Object p2)
p1 - the value of the first parameter declared.p2 - the value of the second parameter declared.
Query.execute(Object,Object),
executeWithArray(Object[] parameters)
public java.lang.Object execute(java.lang.Object p1,
java.lang.Object p2,
java.lang.Object p3)
p1 - the value of the first parameter declared.p2 - the value of the second parameter declared.p3 - the value of the third parameter declared.
Query.execute(Object,Object,Object),
executeWithArray(Object[] parameters)public java.lang.Object executeWithArray(java.lang.Object[] parameterValues)
parameterValues - the Object array with all of the parameters.
Query.executeWithArray(Object[])public java.lang.Object executeWithMap(java.util.Map parameters)
parameters - the Map containing all of the parameters.
NoQueryResultsException - Thrown if no results were returned from the query.Query.executeWithMap(Map),
executeWithArray(Object[] parameters)protected abstract boolean shouldReturnSingleRow()
protected boolean applyRangeChecks()
protected abstract java.lang.Object performExecute(java.util.Map parameters)
parameters - Map containing the parameters.
public long deletePersistentAll()
Query.deletePersistentAll()public long deletePersistentAll(java.lang.Object[] parameters)
parameters - the Object array with all of the parameters.
Query.deletePersistentAll(Object[])public long deletePersistentAll(java.util.Map parameters)
parameters - Map of parameters for the query
Query.deletePersistentAll(Map)protected abstract long performDeletePersistentAll(java.util.Map parameters)
parameters - Map containing the parameters.
public void close(java.lang.Object queryResult)
queryResult - the result of execute(...) on this Query instance.Query.close(java.lang.Object)public void closeAll()
Query.closeAll()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||