org.objectweb.speedo.query.lib
Class SpeedoQuery

java.lang.Object
  extended byorg.objectweb.speedo.query.lib.QueryDefinitionImpl
      extended byorg.objectweb.speedo.query.lib.SpeedoQuery
All Implemented Interfaces:
javax.jdo.Query, QueryDefinition, java.io.Serializable

public class SpeedoQuery
extends QueryDefinitionImpl
implements javax.jdo.Query

SpeedoQuery is the basic implementation of the javax.jdo.Query interface. This class is just a wrapper to a SpeedoCompiledQuery object which is a reused object.

Author:
S. Chassande-Barrioz
See Also:
Serialized Form

Field Summary
 java.util.Map extensions
           
 
Fields inherited from class org.objectweb.speedo.query.lib.QueryDefinitionImpl
candidateClass, candidateInstances, extentClass, filter, grouping, ignoreCache, importStatements, indexFirst, indexLast, order, parameters, result, resultClass, unique, variables, withPrefetch
 
Fields inherited from interface javax.jdo.Query
JDOQL, SQL
 
Constructor Summary
SpeedoQuery()
           
 
Method Summary
 void addExtension(java.lang.String key, java.lang.Object value)
           
 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.
 void declareImports(java.lang.String imports)
          Set the import statements to be used to identify the fully qualified name of variables or parameters.
 void declareParameters(java.lang.String parameters)
          Declare the list of parameters query execution.
 void declareVariables(java.lang.String variables)
          Declare the unbound variables to be used in the query.
 void defineWith(QueryDefinition qd)
           
 long deletePersistentAll()
           
 long deletePersistentAll(java.util.Map arg0)
           
 long deletePersistentAll(java.lang.Object[] arg0)
           
 java.lang.Object execute()
          Execute the query and return the filtered Set.
 java.lang.Object execute(java.lang.Object p1)
          Execute the query and return the filtered Set.
 java.lang.Object execute(java.lang.Object p1, java.lang.Object p2)
          Execute the query and return the filtered Set.
 java.lang.Object execute(java.lang.Object p1, java.lang.Object p2, java.lang.Object p3)
          Execute the query and return the filtered Set.
 java.lang.Object executeWithArray(java.lang.Object[] anarray)
          Execute the query and return the filtered Set.
 java.lang.Object executeWithMap(java.util.Map amap)
          Execute the query and return the filtered Set.
 javax.jdo.FetchPlan getFetchPlan()
           
 boolean getIgnoreCache()
          Get the ignoreCache option setting.
 javax.jdo.PersistenceManager getPersistenceManager()
          Get the PersistenceManager associated with this Query.
 CompiledQuery getQueryCompiler()
           
 QueryManager getQueryManager()
           
 boolean isUnmodifiable()
           
 void setCandidates(java.util.Collection pcs)
          Set the candidate Set to query.
 void setCandidates(javax.jdo.Extent pcs)
          Set the candidate Extent to query.
 void setClass(java.lang.Class cls)
          Set the class of the candidate instances of the query.
 void setExtensions(java.util.Map exts)
           
 void setFetchPlan(javax.jdo.FetchPlan fp)
           
 void setFilter(java.lang.String f)
          Set the filter for the query.
 void setGrouping(java.lang.String arg0)
           
 void setIgnoreCache(boolean ignoreCache)
          Set the ignoreCache option.
 void setIncludeSubClasses(boolean val)
           
 void setLogger(org.objectweb.util.monolog.api.Logger logger)
           
 void setOrdering(java.lang.String ordering)
          Set the ordering specification for the result Set.
 void setProxyManager(ProxyManager _pm)
           
 void setQueryCompiler(CompiledQuery _qc)
           
 void setQueryManager(QueryManager _qm)
           
 void setRange(long first, long last)
           
 void setResult(java.lang.String result)
           
 void setResultClass(java.lang.Class resultClass)
           
 void setUnique(boolean unique)
           
 void setUnmodifiable()
           
 
Methods inherited from class org.objectweb.speedo.query.lib.QueryDefinitionImpl
equals, getCandidateClass, getCollection, getExtent, getFilter, getGrouping, getImportStatements, getIncludeSubClasses, getIndexFirst, getIndexLast, getOrder, getParameters, getResult, getResultClass, getUnique, getVariables, hashCode, isCollection, isIgnoreCache, qdToString, toString, withPrefetch, withPrefetch
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

extensions

public java.util.Map extensions
Constructor Detail

SpeedoQuery

public SpeedoQuery()
Method Detail

setLogger

public void setLogger(org.objectweb.util.monolog.api.Logger logger)

getQueryManager

public QueryManager getQueryManager()

setQueryManager

public void setQueryManager(QueryManager _qm)

getQueryCompiler

public CompiledQuery getQueryCompiler()

setQueryCompiler

public void setQueryCompiler(CompiledQuery _qc)

setProxyManager

public void setProxyManager(ProxyManager _pm)

defineWith

public void defineWith(QueryDefinition qd)
Overrides:
defineWith in class QueryDefinitionImpl

setClass

public void setClass(java.lang.Class cls)
Set the class of the candidate instances of the query.

The class specifies the class of the candidates of the query. Elements of the candidate collection that are of the specified class are filtered before being put into the result Set.

Specified by:
setClass in interface javax.jdo.Query
Parameters:
cls - the Class of the candidate instances.

setCandidates

public void setCandidates(javax.jdo.Extent pcs)
Set the candidate Extent to query.

Specified by:
setCandidates in interface javax.jdo.Query
Parameters:
pcs - the Candidate Extent.

setCandidates

public void setCandidates(java.util.Collection pcs)
Set the candidate Set to query.

Specified by:
setCandidates in interface javax.jdo.Query
Parameters:
pcs - the Candidate collection.

setFilter

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

The filter specification is a String containing a boolean expression that is to be evaluated for each of the instances in the candidate collection. If the filter is not specified, then it defaults to "true", which has the effect of filtering the input Set only for class type.

An element of the candidate collection is returned in the result if:

The user may denote uniqueness in the filter expression by explicitly declaring an expression (for example, e1 != e2).

Rules for constructing valid expressions follow the Java language, except for these differences:

Identifiers in the expression are considered to be in the name space of the specified class, with the addition of declared imports, parameters and variables. As in the Java language, this is a reserved word which means the element of the collection being evaluated.

Navigation through single-valued fields is specified by the Java language syntax of field_name.field_name....field_name.

A JDO implementation is allowed to reorder the filter expression for optimization purposes.

Specified by:
setFilter in interface javax.jdo.Query
Parameters:
f - the query filter.

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 and unbound variables might come from a different class from the candidate class, and the names need to be declared in an import statement to eliminate ambiguity. Import statements are specified as a String with semicolon-separated statements.

The String parameter to this method follows the syntax of the import statement of the Java language.

Specified by:
declareImports in interface javax.jdo.Query
Parameters:
imports - import statements separated by semicolons.

declareParameters

public void declareParameters(java.lang.String parameters)
Declare the list of parameters query execution. The parameter declaration is a String containing one or more query parameter declarations separated with commas. Each parameter named in the parameter declaration must be bound to a value when the query is executed.

The String parameter to this method follows the syntax for formal parameters in the Java language.

Specified by:
declareParameters in interface javax.jdo.Query
Parameters:
parameters - the list of parameters separated by commas.

declareVariables

public void declareVariables(java.lang.String variables)
Declare the unbound variables to be used in the query. Variables might be used in the filter, and these variables must be declared with their type. The unbound variable declaration is a String containing one or more unbound variable declarations separated with semicolons. It follows the syntax for local variables in the Java language.

Specified by:
declareVariables in interface javax.jdo.Query
Parameters:
variables - the variables separated by semicolons.

setOrdering

public void setOrdering(java.lang.String ordering)
Set the ordering specification for the result Set. The ordering specification is a String containing one or more ordering declarations separated by commas.

Each ordering declaration is the name of the field on which to order the results followed by one of the following words: "ascending" or "descending".

The field must be declared in the candidate class or must be a navigation expression starting with a field in the candidate class.

Valid field types are primitive types except boolean; wrapper types except Boolean; BigDecimal; BigInteger; String; and Date.

Specified by:
setOrdering in interface javax.jdo.Query
Parameters:
ordering - the ordering specification.

setIgnoreCache

public void setIgnoreCache(boolean ignoreCache)
Set the ignoreCache option. The default value for this option was set by the PersistenceManagerFactory or the PersistenceManager used to create this Query. The ignoreCache option setting specifies whether the query should execute entirely in the back end, instead of in the cache. If this flag is set to true, an implementation might be able to optimize the query execution by ignoring changed values in the cache. For optimistic transactions, this can dramatically improve query response times.

Specified by:
setIgnoreCache in interface javax.jdo.Query
Parameters:
ignoreCache - the setting of the ignoreCache option.

getIgnoreCache

public boolean getIgnoreCache()
Get the ignoreCache option setting.

Specified by:
getIgnoreCache in interface javax.jdo.Query
Returns:
the ignoreCache option setting.
See Also:
setIgnoreCache(boolean)

setIncludeSubClasses

public void setIncludeSubClasses(boolean val)

compile

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

Specified by:
compile in interface javax.jdo.Query

execute

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

Specified by:
execute in interface javax.jdo.Query
Returns:
the filtered Set.
See Also:
executeWithArray(java.lang.Object[] parameters)

execute

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

Specified by:
execute in interface javax.jdo.Query
Parameters:
p1 - the value of the first parameter declared.
Returns:
the filtered Set.
See Also:
executeWithArray(java.lang.Object[] parameters)

execute

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

Specified by:
execute in interface javax.jdo.Query
Parameters:
p1 - the value of the first parameter declared.
p2 - the value of the second parameter declared.
Returns:
the filtered Set.
See Also:
executeWithArray(java.lang.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 Set.

Specified by:
execute in interface javax.jdo.Query
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 Set.
See Also:
executeWithArray(java.lang.Object[] parameters)

executeWithMap

public java.lang.Object executeWithMap(java.util.Map amap)
Execute the query and return the filtered Set. The query is executed with the parameters set by the Map values. Each Map entry consists of a key which is the name of the parameter in the declareParameters method, and a value which is the value used in the execute method. The keys in the Map and the declared parameters must exactly match or a JDOUserException is thrown.

Specified by:
executeWithMap in interface javax.jdo.Query
Parameters:
amap - the Map containing all of the parameters.
Returns:
the filtered Set.
See Also:
executeWithArray(java.lang.Object[] parameters)

executeWithArray

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

The execution of the query obtains the values of the parameters and matches them against the declared parameters in order. The names of the declared parameters are ignored. The type of the declared parameters must match the type of the passed parameters, except that the passed parameters might need to be unwrapped to get their primitive values.

The filter, import, declared parameters, declared variables, and ordering statements are verified for consistency.

Each element in the candidate Set is examined to see that it is assignment compatible to the Class of the query. It is then evaluated by the boolean expression of the filter. The element passes the filter if there exist unique values for all variables for which the filter expression evaluates to true.

Specified by:
executeWithArray in interface javax.jdo.Query
Parameters:
anarray - the Object array with all of the parameters.
Returns:
the filtered Set.

getPersistenceManager

public javax.jdo.PersistenceManager getPersistenceManager()
Get the PersistenceManager associated with this Query.

If this Query was restored from a serialized form, it has no PersistenceManager, and this method returns null.

Specified by:
getPersistenceManager in interface javax.jdo.Query
Returns:
the PersistenceManager associated with this Query.

close

public void close(java.lang.Object queryResult)
Close a query result and release any resources associated with it. The parameter is the return from execute(...) and might have iterators open on it. Iterators associated with the query result are invalidated: they return false to hasNext() and throw NoSuchElementException to next(). This method makes nothing, all is done by the SpeedoCompiledQuery object. This object is never closed, and could be reused in the future.

Specified by:
close in interface javax.jdo.Query
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. The query results might have iterators open on them. Iterators associated with the query results are invalidated: they return false to hasNext() and throw NoSuchElementException to next().

Specified by:
closeAll in interface javax.jdo.Query

getFetchPlan

public javax.jdo.FetchPlan getFetchPlan()
Specified by:
getFetchPlan in interface javax.jdo.Query

setFetchPlan

public void setFetchPlan(javax.jdo.FetchPlan fp)

deletePersistentAll

public long deletePersistentAll()
Specified by:
deletePersistentAll in interface javax.jdo.Query

deletePersistentAll

public long deletePersistentAll(java.util.Map arg0)
Specified by:
deletePersistentAll in interface javax.jdo.Query

deletePersistentAll

public long deletePersistentAll(java.lang.Object[] arg0)
Specified by:
deletePersistentAll in interface javax.jdo.Query

setGrouping

public void setGrouping(java.lang.String arg0)
Specified by:
setGrouping in interface javax.jdo.Query

setRange

public void setRange(long first,
                     long last)
Specified by:
setRange in interface javax.jdo.Query

setUnique

public void setUnique(boolean unique)
Specified by:
setUnique in interface javax.jdo.Query

setResult

public void setResult(java.lang.String result)
Specified by:
setResult in interface javax.jdo.Query

setResultClass

public void setResultClass(java.lang.Class resultClass)
Specified by:
setResultClass in interface javax.jdo.Query

setExtensions

public void setExtensions(java.util.Map exts)
Specified by:
setExtensions in interface javax.jdo.Query

addExtension

public void addExtension(java.lang.String key,
                         java.lang.Object value)
Specified by:
addExtension in interface javax.jdo.Query

isUnmodifiable

public boolean isUnmodifiable()
Specified by:
isUnmodifiable in interface javax.jdo.Query

setUnmodifiable

public void setUnmodifiable()
Specified by:
setUnmodifiable in interface javax.jdo.Query