org.datanucleus.store.rdbms.query
Class SQLQuery

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

public final class SQLQuery
extends org.datanucleus.store.query.AbstractSQLQuery

A Query using SQL, and keeping to the JDO2 definition of a SQL query. The majority of this has to be specified in the query filter itself. There are no variables/imports. Ordering/grouping is explicit in the query.

Results

Results from this type of query will be :-

Parameters

Parameters to this type of query can be :-

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class org.datanucleus.store.query.Query
org.datanucleus.store.query.Query.SubqueryDefinition
 
Field Summary
protected  boolean isCompiled
          State variable for the compilation state
protected static org.datanucleus.util.Localiser LOCALISER_RDBMS
          Localiser of messages.
protected  org.datanucleus.store.mapped.StatementMappingIndex[] stmtMappings
          Mappings for the result of the query.
 
Fields inherited from class org.datanucleus.store.query.AbstractSQLQuery
compiledSQL, inputSQL, resultMetaData
 
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, implicitParameters, imports, LOCALISER, om, ordering, parameterNames, parsedImports, queryResults, range, result, resultClass, resultClassName, resultDistinct, SELECT, subclasses, subqueries, tasks, toExclNo, type, unique, unmodifiable, update
 
Constructor Summary
SQLQuery(org.datanucleus.ObjectManager om)
          Constructs a new query instance having the same criteria as the given query.
SQLQuery(org.datanucleus.ObjectManager om, SQLQuery query)
          Constructor for a new query using the existing query.
SQLQuery(org.datanucleus.ObjectManager om, java.lang.String queryString)
          Constructs a new query instance for the provided single-string SQL query.
 
Method Summary
protected  void assertSupportsCancel()
          Method that will throw an UnsupportedOperationException if the query implementation doesn't support cancelling queries.
static boolean columnNamesAreTheSame(org.datanucleus.store.mapped.DatastoreAdapter dba, java.lang.String name1, java.lang.String name2)
          Convenience method to compare two column names.
 void compileInternal(boolean forExecute, java.util.Map parameterValues)
          Verify the elements of the query and provide a hint to the query to prepare and optimize an execution plan.
protected  void discardCompiled()
          Utility to remove any previous compilation of this Query.
 boolean equals(java.lang.Object obj)
          Equality operator.
protected  java.lang.String generateQueryStatement()
          Method to perform any necessary pre-processing on the users query statement before we execute it.
protected  org.datanucleus.store.query.ResultObjectFactory getResultObjectFactoryForCandidateClass(java.sql.ResultSet rs)
          Method to generate a ResultObjectFactory for converting rows of the provided ResultSet into instances of the candidate class.
protected  org.datanucleus.store.query.ResultObjectFactory getResultObjectFactoryForNoCandidateClass(java.sql.ResultSet rs, java.lang.Class resultClass)
          Utility to take a ResultSet and return a ResultObjectFactory for extracting the results, assuming that no candidate class is supplied.
protected  boolean isCompiled()
          Method to return if the query is compiled.
protected  java.lang.Object performExecute(java.util.Map parameters)
          Execute the query and return the result.
protected  java.lang.Object performExecuteInternal(java.lang.Object... args)
          Method executing the query in the destination environment.
 
Methods inherited from class org.datanucleus.store.query.AbstractSQLQuery
declareExplicitParameters, declareExplicitVariables, declareImports, executeWithArray, executeWithMap, getInputSQL, performDeletePersistentAll, prepareForExecution, setCandidates, setCandidates, setFilter, setGrouping, setOrdering, setRange, setResult, setResultClass, setResultMetaData, setSubclasses
 
Methods inherited from class org.datanucleus.store.query.Query
addExtension, addSubquery, applyImplicitParameterValueToCompilation, applyRangeChecks, assertIsModifiable, cancel, cancel, checkParameterTypesAgainstCompilation, close, closeAll, compile, deletePersistentAll, deletePersistentAll, deletePersistentAll, execute, executeQuery, getBooleanExtensionProperty, getCandidateClass, getCandidateClassName, getCompilation, getExplicitParameters, getExplicitVariables, getExtension, getExtensions, getFetchPlan, getFilter, getFrom, getGrouping, getHaving, getIgnoreCache, getImplicitParameters, getImports, getInputParameters, getObjectManager, getOrdering, getParameterMapForValues, getParsedImports, getPerformExecuteTask, getRange, getRangeFromIncl, getRangeToExcl, getResult, getResultClass, getResultClassName, getResultDistinct, getSerializeRead, getStoreManager, getSubqueryForVariable, getSupportedExtensions, getTimeoutMillis, getType, getUpdate, hashCode, hasSubqueryForVariable, isSubclasses, isUnique, isUnmodifiable, performExecuteTask, prepareDatastore, resolveClassDeclaration, setCandidateClassName, setClass, setExtensions, setFetchPlan, setFrom, setHaving, setIgnoreCache, setImplicitParameter, setImplicitParameter, setRange, setRange, setResultClassName, setResultDistinct, setSerializeRead, setTimeoutMillis, setType, setUnique, setUnmodifiable, setUpdate, shouldReturnSingleRow, useFetchPlan
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOCALISER_RDBMS

protected static final org.datanucleus.util.Localiser LOCALISER_RDBMS
Localiser of messages.


isCompiled

protected transient boolean isCompiled
State variable for the compilation state


stmtMappings

protected transient org.datanucleus.store.mapped.StatementMappingIndex[] stmtMappings
Mappings for the result of the query.

Constructor Detail

SQLQuery

public SQLQuery(org.datanucleus.ObjectManager om,
                SQLQuery query)
Constructor for a new query using the existing query.

Parameters:
om - ObjectManager
query - The existing query

SQLQuery

public SQLQuery(org.datanucleus.ObjectManager om)
Constructs a new query instance having the same criteria as the given query.

Parameters:
om - The ObjectManager

SQLQuery

public SQLQuery(org.datanucleus.ObjectManager om,
                java.lang.String queryString)
Constructs a new query instance for the provided single-string SQL query.

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

equals

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

Overrides:
equals in class org.datanucleus.store.query.Query
Parameters:
obj - The object to compare against
Returns:
Whether they are equal

discardCompiled

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

Overrides:
discardCompiled in class org.datanucleus.store.query.AbstractSQLQuery

isCompiled

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

Overrides:
isCompiled in class org.datanucleus.store.query.Query
Returns:
Whether it is compiled

compileInternal

public void compileInternal(boolean forExecute,
                            java.util.Map parameterValues)
Verify the elements of the query and provide a hint to the query to prepare and optimize an execution plan.

Specified by:
compileInternal in class org.datanucleus.store.query.Query

performExecute

protected java.lang.Object performExecute(java.util.Map parameters)
Execute the query and return the result. For a SELECT query this will be the QueryResult. For an UPDATE/DELETE it will be the row count for the update statement.

Specified by:
performExecute in class org.datanucleus.store.query.Query
Parameters:
parameters - the Map containing all of the parameters (positional parameters)
Returns:
the result of the query

assertSupportsCancel

protected void assertSupportsCancel()
Method that will throw an UnsupportedOperationException if the query implementation doesn't support cancelling queries.

Overrides:
assertSupportsCancel in class org.datanucleus.store.query.Query

performExecuteInternal

protected java.lang.Object performExecuteInternal(java.lang.Object... args)
Method executing the query in the destination environment. This performs the actual PreparedStatement.execute() and nothing else. Any SQLException from the execution is wrapped as a NucleusException.

Overrides:
performExecuteInternal in class org.datanucleus.store.query.Query
Parameters:
args - Arguments to the execution (SQLController, ManagedConnection, PreparedStatement)
Returns:
The result

getResultObjectFactoryForCandidateClass

protected org.datanucleus.store.query.ResultObjectFactory getResultObjectFactoryForCandidateClass(java.sql.ResultSet rs)
                                                                                           throws java.sql.SQLException
Method to generate a ResultObjectFactory for converting rows of the provided ResultSet into instances of the candidate class. Populates stmtMappings.

Parameters:
rs - The ResultSet
Returns:
The ResultObjectFactory
Throws:
java.sql.SQLException - Thrown if an error occurs processing the ResultSet

getResultObjectFactoryForNoCandidateClass

protected org.datanucleus.store.query.ResultObjectFactory getResultObjectFactoryForNoCandidateClass(java.sql.ResultSet rs,
                                                                                                    java.lang.Class resultClass)
                                                                                             throws java.sql.SQLException
Utility to take a ResultSet and return a ResultObjectFactory for extracting the results, assuming that no candidate class is supplied. The QueryResult will return either a result class type, or Object/Object[] depending on whether a ResultClass has been defined.

Parameters:
rs - The ResultSet
Returns:
The query ResultObjectFactory
Throws:
java.sql.SQLException - Thrown when an error occurs creating the QueryResult

columnNamesAreTheSame

public static boolean columnNamesAreTheSame(org.datanucleus.store.mapped.DatastoreAdapter dba,
                                            java.lang.String name1,
                                            java.lang.String name2)
Convenience method to compare two column names. Allows for case sensitivity issues, and for database added quoting.

Parameters:
dba - Datastore adapter
name1 - The first name (from the datastore)
name2 - The second name (from the user SQL statement)
Returns:
Whether they are the same

generateQueryStatement

protected java.lang.String generateQueryStatement()
Method to perform any necessary pre-processing on the users query statement before we execute it. SQL queries are not modified in any way, as per JDO2 spec [14.7].

Returns:
The compiled SQL statement


Copyright © 2009. All Rights Reserved.