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. Based around the JDO definition of an SQL query where you typically set the SQL query filter and have parameters set-able 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, clr, compilation, ec, explicitParameters, explicitVariables, extensions, filter, from, fromInclNo, fromInclParam, grouping, having, ignoreCache, implicitParameters, imports, LOCALISER, ordering, OTHER, parameterNames, parsedImports, queryResults, range, result, resultClass, resultClassName, resultDistinct, SELECT, subclasses, subqueries, tasks, toExclNo, toExclParam, type, unique, unmodifiable, update
 
Constructor Summary
AbstractSQLQuery(ExecutionContext ec, AbstractSQLQuery query)
          Constructs a new query instance from the existing query.
AbstractSQLQuery(ExecutionContext ec, 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.
 java.lang.String getLanguage()
          Accessor for the query language.
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.
protected  boolean shouldReturnSingleRow()
          Convenience method to return whether the query should return a single row.
 
Methods inherited from class org.datanucleus.store.query.Query
addExtension, addSubquery, applyImplicitParameterValueToCompilation, applyRangeChecks, assertIsModifiable, assertSupportsCancel, cancel, cancel, checkParameterTypesAgainstCompilation, checkUnusedParameters, close, closeAll, compile, compileInternal, deletePersistentAll, deletePersistentAll, deletePersistentAll, equals, execute, executeInSeparateThread, executeQuery, getBooleanExtensionProperty, getCandidateClass, getCandidateClassName, getCompilation, getDatastoreReadTimeoutMillis, getDatastoreWriteTimeoutMillis, getExplicitParameters, getExplicitVariables, getExtension, getExtensions, getFetchPlan, getFilter, getFrom, getGrouping, getHaving, getIgnoreCache, getImplicitParameters, getImports, getInputParameters, getObjectManager, getOrdering, getParameterMapForValues, getParsedImports, getQueryManager, getRange, getRangeFromIncl, getRangeFromInclParam, getRangeToExcl, getRangeToExclParam, getResult, getResultClass, getResultClassName, getResultDistinct, getSerializeRead, getStoreManager, getSubqueryForVariable, getSupportedExtensions, getType, getUpdate, hashCode, hasSubqueryForVariable, isCompiled, isSubclasses, isUnique, isUnmodifiable, performExecute, performExecuteInternal, performExecuteTask, prepareDatastore, resolveClassDeclaration, setCandidateClassName, setClass, setCompilation, setDatastoreReadTimeoutMillis, setDatastoreWriteTimeoutMillis, setExtensions, setFetchPlan, setFrom, setHaving, setIgnoreCache, setImplicitParameter, setImplicitParameter, setRange, setRange, setResultClassName, setResultDistinct, setSerializeRead, setType, setUnique, setUnmodifiable, setUpdate, supportsTimeout, useCaching, useFetchPlan, useResultsCaching
 
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(ExecutionContext ec,
                        AbstractSQLQuery query)
Constructs a new query instance from the existing query.

Parameters:
ec - ExecutionContext
query - Existing query

AbstractSQLQuery

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

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

getLanguage

public java.lang.String getLanguage()
Description copied from class: Query
Accessor for the query language.

Overrides:
getLanguage in class Query
Returns:
Query language

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 NucleusUserException 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 NucleusUserException 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 NucleusUserException 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.

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

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 for SQL. This implementation always throws a NucleusUserException 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.

setSubclasses

public void setSubclasses(boolean subclasses)
Method to set whether to use subclasses. Not applicable for SQL. This implementation always throws a NucleusUserException 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. Not applicable for SQL. This implementation always throws a NucleusUserException 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 NucleusUserException 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 NucleusUserException 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 NucleusUserException 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 NucleusUserException 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 NucleusUserException 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.

Overrides:
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
See Also:
Query.executeQuery(Map parameters)

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.executeQuery(Map 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

shouldReturnSingleRow

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

Overrides:
shouldReturnSingleRow in class Query
Returns:
Whether it represents a unique row


Copyright © 2011. All Rights Reserved.