Class JPQLQuery
java.lang.Object
org.datanucleus.store.query.Query
org.datanucleus.store.query.AbstractJavaQuery
org.datanucleus.store.query.AbstractJPQLQuery
org.datanucleus.store.rdbms.query.JPQLQuery
- All Implemented Interfaces:
Serializable
,org.datanucleus.ExecutionContextListener
public class JPQLQuery
extends org.datanucleus.store.query.AbstractJPQLQuery
RDBMS representation of a JPQL query for use by DataNucleus.
The query can be specified via method calls, or via a single-string form.
This implementation uses the generic query compilation in "org.datanucleus.query".
There are the following main ways of running a query here
- Totally in the datastore (no candidate collection specified, and no in-memory eval).
- Totally in-memory (candidate collection specified, and in-memory eval)
- Retrieve candidates from datastore (no candidate collection), and evaluate in-memory
- See Also:
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class org.datanucleus.store.query.Query
org.datanucleus.store.query.Query.QueryType, org.datanucleus.store.query.Query.SubqueryDefinition
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected RDBMSQueryCompilation
The compilation of the query for this datastore.static final String
Extension to not apply a discriminator restriction on the candidate of the query.static final String
Extension to add NOWAIT when using FOR UPDATE (when supported).static final String
Extension to include soft-deleted objects in any results.static final String
Extension to define the JOIN TYPE to use when navigating single-valued relations.static final String
Extension to define the JOIN TYPE to use when navigating single-valued relations, when part of the filter.static final String
Extension for whether to convert "== ?" with null parameter to "IS NULL".private static final long
(package private) boolean
Fields inherited from class org.datanucleus.store.query.AbstractJavaQuery
candidateCollection, singleString
Fields inherited from class org.datanucleus.store.query.Query
candidateClass, candidateClassName, clr, compilation, ec, explicitParameters, explicitVariables, EXTENSION_CHECK_UNUSED_PARAMETERS, EXTENSION_CLOSE_RESULTS_AT_EC_CLOSE, EXTENSION_COMPILATION_CACHED, EXTENSION_COMPILE_OPTIMISE_VAR_THIS, EXTENSION_EVALUATE_IN_MEMORY, EXTENSION_EXCLUDE_SUBCLASSES, EXTENSION_FLUSH_BEFORE_EXECUTION, EXTENSION_JDOQL_ALLOW_ALL, EXTENSION_JDOQL_STRICT, EXTENSION_JPQL_ALLOW_RANGE, EXTENSION_JPQL_STRICT, EXTENSION_LOAD_RESULTS_AT_COMMIT, EXTENSION_QUERY_TYPE, EXTENSION_RESULT_CACHE_TYPE, EXTENSION_RESULT_CACHE_VALIDATE_OBJECTS, EXTENSION_RESULT_SIZE_METHOD, EXTENSION_RESULTS_CACHED, EXTENSION_SQL_ALLOW_ALL, EXTENSION_SQL_SYNTAX_CHECKS, EXTENSION_UPDATE_ALL_CANDIDATE_FIELDS, EXTENSION_USE_FETCH_PLAN, extensions, filter, from, fromInclNo, fromInclParam, grouping, having, ignoreCache, implicitParameters, imports, inputParameters, insertFields, insertSelectQuery, ordering, parameterNames, parsedImports, queryResults, range, result, resultClass, resultClassName, resultDistinct, storeMgr, subclasses, subqueries, tasks, toExclNo, toExclParam, type, unique, unmodifiable, update
-
Constructor Summary
ConstructorsConstructorDescriptionJPQLQuery
(org.datanucleus.store.StoreManager storeMgr, org.datanucleus.ExecutionContext ec) Constructs a new query instance that uses the given object manager.JPQLQuery
(org.datanucleus.store.StoreManager storeMgr, org.datanucleus.ExecutionContext ec, String query) Constructor for a JPQL query where the query is specified using the "Single-String" format.JPQLQuery
(org.datanucleus.store.StoreManager storeMgr, org.datanucleus.ExecutionContext ec, JPQLQuery q) Constructs a new query instance having the same criteria as the given query. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addExtension
(String key, Object value) Add a vendor-specific extension this query.protected void
Method that will throw anUnsupportedOperationException
if the query implementation doesn't support cancelling queries.protected boolean
cancelTaskObject
(Object obj) protected void
compileInternal
(Map parameterValues) Method to compile the JPQL query.protected void
compileQueryDelete
(Map parameterValues, org.datanucleus.metadata.AbstractClassMetaData candidateCmd) Method to compile the query for RDBMS for a bulk delete.private void
compileQueryFull
(Map parameters, org.datanucleus.metadata.AbstractClassMetaData candidateCmd) Method to set the (native) query statement for the compiled query as a whole.protected void
compileQueryInsert
(Map parameterValues, org.datanucleus.metadata.AbstractClassMetaData candidateCmd) Method to compile the query for RDBMS for a bulk INSERT.private void
compileQueryToRetrieveCandidates
(Map parameters, org.datanucleus.metadata.AbstractClassMetaData candidateCmd) Method to set the statement (and parameter/results definitions) to retrieve all candidates.protected void
compileQueryUpdate
(Map parameterValues, org.datanucleus.metadata.AbstractClassMetaData candidateCmd) Method to compile the query for RDBMS for a bulk update.protected void
Utility to remove any previous compilation of this Query.protected String
Method to get key for query cachegetSQL()
Convenience accessor for the SQL to invoke in the datastore for this query.Method to return the names of the extensions supported by this query.protected boolean
Method to return if the query is compiled.protected Object
performExecute
(Map parameters) boolean
void
setExtensions
(Map extensions) Set multiple extensions, or use null to clear extensions.void
setImplicitParameter
(int position, Object value) void
setImplicitParameter
(String name, Object value) private void
setMapperJoinTypes
(QueryToSQLMapper sqlMapper) protected boolean
Convenience method for whether this query supports timeouts.Methods inherited from class org.datanucleus.store.query.AbstractJPQLQuery
compileGeneric, compileSubqueries, getLanguage, getSingleStringQuery, resolveClassDeclaration, setResult
Methods inherited from class org.datanucleus.store.query.AbstractJavaQuery
dereferenceFilter, evaluateInMemory, performDeletePersistentAll, setCandidates, setCandidates, toString
Methods inherited from class org.datanucleus.store.query.Query
addSubquery, applyImplicitParameterValueToCompilation, applyImplicitParameterValueToSubqueries, assertIsModifiable, assertIsOpen, cancel, cancel, checkForMissingParameters, checkParameterTypesAgainstCompilation, checkUnusedParameters, close, closeAll, compile, declareExplicitParameters, declareExplicitVariables, declareImports, deepFindSymbolForParameterInCompilation, deletePersistentAll, deletePersistentAll, deletePersistentAll, deregisterTask, equals, execute, executeQuery, executeWithArray, executeWithMap, executionContextClosing, getBooleanExtensionProperty, getCandidateClass, getCandidateClassMetaData, getCandidateClassName, getCompilation, getDatastoreReadTimeoutMillis, getDatastoreWriteTimeoutMillis, getExecutionContext, getExplicitParametersDeclaration, getExplicitVariablesDeclaration, getExtension, getExtensions, getFetchPlan, getFilter, getFrom, getGrouping, getHaving, getIgnoreCache, getImplicitParameters, getImportsDeclaration, getInputParameters, getInsertFields, getInsertSelectQuery, getOrdering, getParameterMapForValues, getParsedImports, getQueryManager, getRange, getRangeFromIncl, getRangeFromInclParam, getRangeToExcl, getRangeToExclParam, getResult, getResultClass, getResultClassName, getResultDistinct, getSerializeRead, getStoreManager, getStringExtensionProperty, getSubqueryForVariable, getType, getUpdate, hashCode, hasSubqueryForVariable, isSubclasses, isUnique, isUnmodifiable, prepareDatastore, registerTask, setCacheResults, setCandidateClass, setCandidateClassName, setCompilation, setDatastoreReadTimeoutMillis, setDatastoreWriteTimeoutMillis, setFetchPlan, setFilter, setFrom, setGrouping, setHaving, setIgnoreCache, setInsertFields, setInsertSelectQuery, setOrdering, setRange, setRange, setResultClass, setResultClassName, setResultDistinct, setResultMetaData, setSerializeRead, setSubclasses, setType, setUnique, setUnmodifiable, setUpdate, shouldReturnSingleRow, useCaching, useFetchPlan, useResultsCaching
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
EXTENSION_USE_IS_NULL_WHEN_EQUALS_NULL_PARAM
Extension for whether to convert "== ?" with null parameter to "IS NULL". Defaults to false to comply with JPA spec 4.11. -
EXTENSION_FOR_UPDATE_NOWAIT
Extension to add NOWAIT when using FOR UPDATE (when supported). -
EXTENSION_CANDIDATE_DONT_RESTRICT_DISCRIMINATOR
Extension to not apply a discriminator restriction on the candidate of the query. -
EXTENSION_INCLUDE_SOFT_DELETES
Extension to include soft-deleted objects in any results. -
EXTENSION_NAVIGATION_JOIN_TYPE_FILTER
Extension to define the JOIN TYPE to use when navigating single-valued relations, when part of the filter. -
EXTENSION_NAVIGATION_JOIN_TYPE
Extension to define the JOIN TYPE to use when navigating single-valued relations. -
datastoreCompilation
The compilation of the query for this datastore. Not applicable if totally in-memory. -
statementReturnsEmpty
boolean statementReturnsEmpty
-
-
Constructor Details
-
JPQLQuery
public JPQLQuery(org.datanucleus.store.StoreManager storeMgr, org.datanucleus.ExecutionContext ec) Constructs a new query instance that uses the given object manager.- Parameters:
storeMgr
- StoreManager for this queryec
- execution context
-
JPQLQuery
public JPQLQuery(org.datanucleus.store.StoreManager storeMgr, org.datanucleus.ExecutionContext ec, JPQLQuery q) Constructs a new query instance having the same criteria as the given query.- Parameters:
storeMgr
- StoreManager for this queryec
- execution contextq
- The query from which to copy criteria.
-
JPQLQuery
public JPQLQuery(org.datanucleus.store.StoreManager storeMgr, org.datanucleus.ExecutionContext ec, String query) Constructor for a JPQL query where the query is specified using the "Single-String" format.- Parameters:
storeMgr
- StoreManager for this queryec
- The ExecutionContextquery
- The single-string query form
-
-
Method Details
-
setImplicitParameter
- Overrides:
setImplicitParameter
in classorg.datanucleus.store.query.Query
-
setImplicitParameter
- Overrides:
setImplicitParameter
in classorg.datanucleus.store.query.Query
-
discardCompiled
protected void discardCompiled()Utility to remove any previous compilation of this Query.- Overrides:
discardCompiled
in classorg.datanucleus.store.query.AbstractJavaQuery
-
isCompiled
protected boolean isCompiled()Method to return if the query is compiled.- Overrides:
isCompiled
in classorg.datanucleus.store.query.Query
- Returns:
- Whether it is compiled
-
getQueryCacheKey
Method to get key for query cache- Overrides:
getQueryCacheKey
in classorg.datanucleus.store.query.AbstractJPQLQuery
- Returns:
- The cache key
-
compileInternal
Method to compile the JPQL query. Uses the superclass to compile the generic query populating the "compilation", and then generates the datastore-specific "datastoreCompilation".- Overrides:
compileInternal
in classorg.datanucleus.store.query.AbstractJPQLQuery
- Parameters:
parameterValues
- Map of param values keyed by param name (if available at compile time)
-
getSQL
Convenience accessor for the SQL to invoke in the datastore for this query.- Returns:
- The SQL.
-
performExecute
- Specified by:
performExecute
in classorg.datanucleus.store.query.Query
-
assertSupportsCancel
protected void assertSupportsCancel()Method that will throw anUnsupportedOperationException
if the query implementation doesn't support cancelling queries.- Overrides:
assertSupportsCancel
in classorg.datanucleus.store.query.Query
-
cancelTaskObject
- Overrides:
cancelTaskObject
in classorg.datanucleus.store.query.Query
-
supportsTimeout
protected boolean supportsTimeout()Convenience method for whether this query supports timeouts.- Overrides:
supportsTimeout
in classorg.datanucleus.store.query.Query
- Returns:
- Whether timeouts are supported.
-
compileQueryFull
private void compileQueryFull(Map parameters, org.datanucleus.metadata.AbstractClassMetaData candidateCmd) Method to set the (native) query statement for the compiled query as a whole. The "table groups" in the resultant SQLStatement will be named as per the candidate alias, and thereafter "{alias}.{fieldName}".- Parameters:
parameters
- Input parameters (if known)candidateCmd
- Metadata for the candidate class
-
compileQueryToRetrieveCandidates
private void compileQueryToRetrieveCandidates(Map parameters, org.datanucleus.metadata.AbstractClassMetaData candidateCmd) Method to set the statement (and parameter/results definitions) to retrieve all candidates. This is used when we want to evaluate in-memory and so just retrieve all possible candidates first.- Parameters:
parameters
- Input parameters (if known)candidateCmd
- Metadata for the candidate class
-
compileQueryInsert
protected void compileQueryInsert(Map parameterValues, org.datanucleus.metadata.AbstractClassMetaData candidateCmd) Method to compile the query for RDBMS for a bulk INSERT.- Parameters:
parameterValues
- The parameter values (if any)candidateCmd
- Meta-data for the candidate class
-
compileQueryUpdate
protected void compileQueryUpdate(Map parameterValues, org.datanucleus.metadata.AbstractClassMetaData candidateCmd) Method to compile the query for RDBMS for a bulk update.- Parameters:
parameterValues
- The parameter values (if any)candidateCmd
- Meta-data for the candidate class
-
compileQueryDelete
protected void compileQueryDelete(Map parameterValues, org.datanucleus.metadata.AbstractClassMetaData candidateCmd) Method to compile the query for RDBMS for a bulk delete.- Parameters:
parameterValues
- The parameter values (if any)candidateCmd
- Meta-data for the candidate class
-
setMapperJoinTypes
-
processesRangeInDatastoreQuery
public boolean processesRangeInDatastoreQuery()- Overrides:
processesRangeInDatastoreQuery
in classorg.datanucleus.store.query.Query
-
getSupportedExtensions
Method to return the names of the extensions supported by this query. To be overridden by subclasses where they support additional extensions.- Overrides:
getSupportedExtensions
in classorg.datanucleus.store.query.AbstractJPQLQuery
- Returns:
- The supported extension names
-
addExtension
Add a vendor-specific extension this query. Intercepts any setting of in-memory evaluation, so we can throw away any datastore compilation.- Overrides:
addExtension
in classorg.datanucleus.store.query.Query
- Parameters:
key
- the extension keyvalue
- the extension value
-
setExtensions
Set multiple extensions, or use null to clear extensions. Intercepts any setting of in-memory evaluation, so we can throw away any datastore compilation.- Overrides:
setExtensions
in classorg.datanucleus.store.query.Query
- Parameters:
extensions
- Query extensions
-
getDatastoreCompilation
-
getNativeQuery
- Overrides:
getNativeQuery
in classorg.datanucleus.store.query.Query
-