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:
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, clr, compilation, ec, explicitParameters, explicitVariables, EXTENSION_CHECK_UNUSED_PARAMETERS, EXTENSION_COMPILATION_CACHED, EXTENSION_EVALUATE_IN_MEMORY, EXTENSION_FLUSH_BEFORE_EXECUTION, EXTENSION_LOAD_RESULTS_AT_COMMIT, EXTENSION_MULTITHREAD, EXTENSION_RESULT_CACHE_TYPE, EXTENSION_RESULT_SIZE_METHOD, EXTENSION_RESULTS_CACHED, EXTENSION_USE_FETCH_PLAN, extensions, filter, from, fromInclNo, fromInclParam, grouping, having, ignoreCache, implicitParameters, imports, inputParameters, LOCALISER, ordering, OTHER, parameterNames, parsedImports, queryResults, range, result, resultClass, resultClassName, resultDistinct, SELECT, storeMgr, subclasses, subqueries, tasks, toExclNo, toExclParam, type, unique, unmodifiable, update
 
Constructor Summary
SQLQuery(org.datanucleus.store.StoreManager storeMgr, org.datanucleus.store.ExecutionContext ec)
          Constructs a new query instance having the same criteria as the given query.
SQLQuery(org.datanucleus.store.StoreManager storeMgr, org.datanucleus.store.ExecutionContext ec, SQLQuery query)
          Constructor for a new query using the existing query.
SQLQuery(org.datanucleus.store.StoreManager storeMgr, org.datanucleus.store.ExecutionContext ec, 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, String name1, String name2)
          Convenience method to compare two column names.
 void compileInternal(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(Object obj)
          Equality operator.
protected  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(ResultSet rs)
          Method to generate a ResultObjectFactory for converting rows of the provided ResultSet into instances of the candidate class.
protected  boolean isCompiled()
          Method to return if the query is compiled.
protected  Object performExecute(Map parameters)
          Execute the query and return the result.
 boolean processesRangeInDatastoreQuery()
           
 
Methods inherited from class org.datanucleus.store.query.AbstractSQLQuery
declareExplicitParameters, declareExplicitVariables, declareImports, executeWithArray, executeWithMap, getInputSQL, getLanguage, performDeletePersistentAll, prepareForExecution, setCandidates, setCandidates, setFilter, setGrouping, setOrdering, setRange, setResult, setResultClass, setResultMetaData, setSubclasses, shouldReturnSingleRow
 
Methods inherited from class org.datanucleus.store.query.Query
addExtension, addSubquery, applyImplicitParameterValueToCompilation, applyImplicitParameterValueToSubqueries, assertIsModifiable, cancel, cancel, cancelTaskObject, checkForMissingParameters, checkParameterTypesAgainstCompilation, checkUnusedParameters, close, closeAll, compile, deepFindSymbolForParameterInCompilation, deletePersistentAll, deletePersistentAll, deletePersistentAll, deregisterTask, execute, executeQuery, getBooleanExtensionProperty, getCandidateClass, getCandidateClassName, getCompilation, getDatastoreReadTimeoutMillis, getDatastoreWriteTimeoutMillis, getExecutionContext, getExplicitParameters, getExplicitVariables, getExtension, getExtensions, getFetchPlan, getFilter, getFrom, getGrouping, getHaving, getIgnoreCache, getImplicitParameters, getImports, getInputParameters, getOrdering, getParameterMapForValues, getParsedImports, getQueryManager, getRange, getRangeFromIncl, getRangeFromInclParam, getRangeToExcl, getRangeToExclParam, getResult, getResultClass, getResultClassName, getResultDistinct, getSerializeRead, getStoreManager, getStringExtensionProperty, getSubqueryForVariable, getSupportedExtensions, getType, getUpdate, hashCode, hasSubqueryForVariable, isSubclasses, isUnique, isUnmodifiable, prepareDatastore, registerTask, resolveClassDeclaration, setCacheResults, setCandidateClass, setCandidateClassName, 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

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.store.StoreManager storeMgr,
                org.datanucleus.store.ExecutionContext ec,
                SQLQuery query)
Constructor for a new query using the existing query.

Parameters:
storeMgr - StoreManager for this query
ec - execution context
query - The existing query

SQLQuery

public SQLQuery(org.datanucleus.store.StoreManager storeMgr,
                org.datanucleus.store.ExecutionContext ec)
Constructs a new query instance having the same criteria as the given query.

Parameters:
storeMgr - StoreManager for this query
ec - execution context

SQLQuery

public SQLQuery(org.datanucleus.store.StoreManager storeMgr,
                org.datanucleus.store.ExecutionContext ec,
                String queryString)
Constructs a new query instance for the provided single-string SQL query.

Parameters:
storeMgr - StoreManager for this query
ec - execution context
queryString - The SQL query string
Method Detail

equals

public boolean equals(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

processesRangeInDatastoreQuery

public boolean processesRangeInDatastoreQuery()
Overrides:
processesRangeInDatastoreQuery in class org.datanucleus.store.query.Query

compileInternal

public void compileInternal(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 Object performExecute(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) (not null)
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

getResultObjectFactoryForCandidateClass

protected org.datanucleus.store.query.ResultObjectFactory getResultObjectFactoryForCandidateClass(ResultSet rs)
                                                                                           throws 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:
SQLException - Thrown if an error occurs processing the ResultSet

columnNamesAreTheSame

public static boolean columnNamesAreTheSame(org.datanucleus.store.mapped.DatastoreAdapter dba,
                                            String name1,
                                            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 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 © 2012. All Rights Reserved.