org.datanucleus.store.query
Class AbstractSQLQuery

java.lang.Object
  extended by org.datanucleus.store.query.Query
      extended by org.datanucleus.store.query.AbstractSQLQuery
All Implemented Interfaces:
java.io.Serializable

public abstract class AbstractSQLQuery
extends Query

Base definition of a query using SQL. Is based around the JDO definition of an SQL query where you typically set the SQL query filter and have parameters settable but not much else.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class org.datanucleus.store.query.Query
Query.SubqueryDefinition
 
Field Summary
protected  java.lang.String compiledSQL
          The actual SQL issued at execution time.
protected  java.lang.String inputSQL
          The statement that the user specified to the Query.
protected  QueryResultMetaData resultMetaData
          MetaData defining the results of the query.
 
Fields inherited from class org.datanucleus.store.query.Query
BULK_DELETE, BULK_UPDATE, candidateClass, candidateClassName, compilation, explicitParameters, explicitVariables, extensions, filter, from, fromInclNo, grouping, having, ignoreCache, IMPLICIT_POSITIONAL_PARAM_PREFIX, implicitParameters, imports, LOCALISER, om, ordering, parameterNames, parsedImports, queryResults, range, result, resultClass, resultClassName, resultDistinct, SELECT, subclasses, subqueries, toExclNo, type, unique, unmodifiable, update
 
Constructor Summary
AbstractSQLQuery(ObjectManager om, AbstractSQLQuery query)
          Constructs a new query instance from the existing query.
AbstractSQLQuery(ObjectManager om, java.lang.String sqlText)
          Constructs a new query instance having the same criteria as the given query.
 
Method Summary
 void declareExplicitParameters(java.lang.String parameters)
          Declare the explicit parameters to be used in the query.
 void declareExplicitVariables(java.lang.String variables)
          Declare the unbound variables to be used in 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.
protected  void discardCompiled()
          Utility to discard any compiled query.
 java.lang.Object executeWithArray(java.lang.Object[] parameters)
          Execute the query and return the filtered List.
 java.lang.Object executeWithMap(java.util.Map executeParameters)
          Execute the query using the input Map of parameters.
 java.lang.String getInputSQL()
          Accessor for the user-input SQL query.
protected  long performDeletePersistentAll(java.util.Map parameters)
          Execute the query to delete persistent objects.
protected  java.util.Map prepareForExecution(java.util.Map executeParameters)
          Method to process the input parameters preparing the statement and parameters for execution.
 void setCandidates(java.util.Collection pcs)
          Set the candidate Collection to query.
 void setCandidates(Extent pcs)
          Set the candidate Extent to query.
 void setFilter(java.lang.String filter)
          Set the filter for the query.
 void setGrouping(java.lang.String grouping)
          Set the grouping specification for the result Collection.
 void setOrdering(java.lang.String ordering)
          Set the ordering specification for the result Collection.
 void setRange(int fromIncl, int toExcl)
          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 setResultMetaData(QueryResultMetaData qrmd)
          Method to set the MetaData defining the result.
 void setSubclasses(boolean subclasses)
          Method to set whether to use subclasses.
 
Methods inherited from class org.datanucleus.store.query.Query
addExtension, addSubquery, applyRangeChecks, assertIsModifiable, close, closeAll, compile, compileInternal, deletePersistentAll, deletePersistentAll, deletePersistentAll, equals, execute, execute, execute, execute, executeQuery, getCandidateClass, getCandidateClassName, getExplicitParameters, getExplicitVariables, getExtension, getExtensions, getFetchPlan, getFilter, getFrom, getGrouping, getHaving, getIgnoreCache, getImplicitParameters, getImports, getInputParameters, getObjectManager, getOrdering, getParameterMapForValues, getParsedImports, getRange, getRangeFromIncl, getRangeToExcl, getResult, getResultClass, getResultClassName, getResultDistinct, getStoreManager, getSubqueryForVariable, getType, getUpdate, hashCode, hasSubqueryForVariable, isCompiled, isSubclasses, isUnique, isUnmodifiable, performExecute, prepareDatastore, resolveClassDeclaration, resultHasOnlyAggregates, setCandidateClassName, setClass, setExtensions, setFetchPlan, setFrom, setHaving, setIgnoreCache, setImplicitParameter, setImplicitParameter, setRange, setRange, setResultClassName, setResultDistinct, setType, setUnique, setUnmodifiable, setUpdate, shouldReturnSingleRow
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

inputSQL

protected final transient java.lang.String inputSQL
The statement that the user specified to the Query.


compiledSQL

protected transient java.lang.String compiledSQL
The actual SQL issued at execution time.


resultMetaData

protected QueryResultMetaData resultMetaData
MetaData defining the results of the query.

Constructor Detail

AbstractSQLQuery

public AbstractSQLQuery(ObjectManager om,
                        AbstractSQLQuery query)
Constructs a new query instance from the existing query.

Parameters:
om - Object Manager
query - Existing query

AbstractSQLQuery

public AbstractSQLQuery(ObjectManager om,
                        java.lang.String sqlText)
Constructs a new query instance having the same criteria as the given query.

Parameters:
om - The ObjectManager
sqlText - The SQL query string
Method Detail

discardCompiled

protected void discardCompiled()
Utility to discard any compiled query.

Overrides:
discardCompiled in class Query
See Also:
Query.discardCompiled()

getInputSQL

public java.lang.String getInputSQL()
Accessor for the user-input SQL query.

Returns:
User-input SQL

setCandidates

public void setCandidates(Extent pcs)
Set the candidate Extent to query. This implementation always throws a JPOXUserException since this concept doesn't apply to SQL queries.

Specified by:
setCandidates in class Query
Parameters:
pcs - the Candidate Extent.
Throws:
NucleusUserException - Always thrown since method not applicable

setCandidates

public void setCandidates(java.util.Collection pcs)
Set the candidate Collection to query. This implementation always throws a JPOXUserException since this concept doesn't apply to SQL queries.

Specified by:
setCandidates in class Query
Parameters:
pcs - the Candidate collection.
Throws:
NucleusUserException - Always thrown since method not applicable

setResult

public void setResult(java.lang.String result)
Set the result for the results. The application might want to get results from a query that are not instances of the candidate class. The results might be fields of persistent instances, instances of classes other than the candidate class, or aggregates of fields. This implementation always throws a JPOXUserException since this concept doesn't apply to SQL queries.

Overrides:
setResult in class Query
Parameters:
result - The result parameter consists of the optional keyword distinct followed by a commaseparated list of named result expressions or a result class specification.
Throws:
NucleusUserException - Always thrown.
Since:
1.1

setResultMetaData

public void setResultMetaData(QueryResultMetaData qrmd)
Method to set the MetaData defining the result. Setting this will unset the resultClass.

Overrides:
setResultMetaData in class Query
Parameters:
qrmd - Query Result MetaData
Since:
1.2

setResultClass

public void setResultClass(java.lang.Class result_cls)
Set the result class for the results. Setting this will unset the resultMetaData.

Overrides:
setResultClass in class Query
Parameters:
result_cls - The result class

setRange

public void setRange(int fromIncl,
                     int toExcl)
Set the range of the results. Not applicable to SQL/JPOXSQL queries. This implementation always throws a JPOXUserException since this concept doesn't apply to SQL queries.

Parameters:
fromIncl - From element no (inclusive) to return
toExcl - To element no (exclusive) to return
Throws:
NucleusUserException - Always thrown.
Since:
1.1

setSubclasses

public void setSubclasses(boolean subclasses)
Method to set whether to use subclasses. This is not used with JPOXSQL. This implementation always throws a JPOXUserException since this concept doesn't apply to SQL queries.

Overrides:
setSubclasses in class Query
Parameters:
subclasses - Whether to use subclasses
Throws:
NucleusUserException - Always thrown.

setFilter

public void setFilter(java.lang.String filter)
Set the filter for the query. This implementation always throws a JPOXUserException since this concept doesn't apply to SQL queries.

Overrides:
setFilter in class Query
Parameters:
filter - the query filter.
Throws:
NucleusUserException - Always thrown since method not applicable

declareExplicitVariables

public void declareExplicitVariables(java.lang.String variables)
Declare the unbound variables to be used in the query. This implementation always throws a JPOXUserException since this concept doesn't apply to SQL queries.

Overrides:
declareExplicitVariables in class Query
Parameters:
variables - the variables separated by semicolons.
Throws:
NucleusUserException - Always thrown since method not applicable

declareExplicitParameters

public void declareExplicitParameters(java.lang.String parameters)
Declare the explicit parameters to be used in the query. This implementation always throws a JPOXUserException since this concept doesn't apply to SQL queries.

Overrides:
declareExplicitParameters in class Query
Parameters:
parameters - the parameters separated by semicolons.
Throws:
NucleusUserException - Always thrown.

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. This implementation always throws a JPOXUserException since this concept doesn't apply to SQL queries.

Overrides:
declareImports in class Query
Parameters:
imports - import statements separated by semicolons.
Throws:
NucleusUserException - Always thrown.

setGrouping

public void setGrouping(java.lang.String grouping)
Set the grouping specification for the result Collection. This implementation always throws a JPOXUserException since this concept doesn't apply to SQL queries.

Overrides:
setGrouping in class Query
Parameters:
grouping - the grouping specification.
Throws:
NucleusUserException - Always thrown.

setOrdering

public void setOrdering(java.lang.String ordering)
Set the ordering specification for the result Collection. This implementation always throws a JPOXUserException since this concept doesn't apply to SQL queries.

Overrides:
setOrdering in class Query
Parameters:
ordering - the ordering specification.
Throws:
NucleusUserException - Always thrown.

performDeletePersistentAll

protected long performDeletePersistentAll(java.util.Map parameters)
Execute the query to delete persistent objects.

Specified by:
performDeletePersistentAll in class Query
Parameters:
parameters - the Map containing all of the parameters.
Returns:
the filtered QueryResult of the deleted objects.

executeWithArray

public java.lang.Object executeWithArray(java.lang.Object[] parameters)
Execute the query and return the filtered List. Override the method in Query since we want the parameter names to be Integer based here.

Overrides:
executeWithArray in class Query
Parameters:
parameters - the Object array with all of the parameters.
Returns:
The query results

executeWithMap

public java.lang.Object executeWithMap(java.util.Map executeParameters)
Execute the query using the input Map of parameters.

Overrides:
executeWithMap in class Query
Parameters:
executeParameters - the Map of the parameters passed in to execute().
Returns:
The query results
See Also:
Query.executeWithArray(Object[] parameters)

prepareForExecution

protected java.util.Map prepareForExecution(java.util.Map executeParameters)
Method to process the input parameters preparing the statement and parameters for execution. The parameters returned are ready for execution. Compiles the query, and updates the "compiledSQL" and "parameterNames". Supports positional parameters, numbered parameters (?1, ?2), and named parameters (:p1, :p3). If using named parameters then the keys of the Map must align to the names in the SQL. If using numbered/positional parameters then the keys of the Map must be Integer and align with the parameter numbers/positions.

Parameters:
executeParameters - The input parameters map
Returns:
Map of parameters for execution


Copyright © 2009. All Rights Reserved.