Class JDOQLQuery

java.lang.Object
org.datanucleus.store.query.Query
org.datanucleus.store.query.AbstractJavaQuery
org.datanucleus.store.query.AbstractJDOQLQuery
org.datanucleus.store.rdbms.query.JDOQLQuery
All Implemented Interfaces:
Serializable, org.datanucleus.ExecutionContextListener

public class JDOQLQuery extends org.datanucleus.store.query.AbstractJDOQLQuery
RDBMS representation of a JDOQL 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 Classes
    Modifier and Type
    Class
    Description
    private class 
     

    Nested classes/interfaces inherited from class org.datanucleus.store.query.Query

    org.datanucleus.store.query.Query.QueryType, org.datanucleus.store.query.Query.SubqueryDefinition
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    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 disable the setting of DISTINCT when joining with JDOQL.
    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

    Constructors
    Constructor
    Description
    JDOQLQuery(org.datanucleus.store.StoreManager storeMgr, org.datanucleus.ExecutionContext ec)
    Constructs a new query instance that uses the given object manager.
    JDOQLQuery(org.datanucleus.store.StoreManager storeMgr, org.datanucleus.ExecutionContext ec, String query)
    Constructor for a JDOQL query where the query is specified using the "Single-String" format.
    JDOQLQuery(org.datanucleus.store.StoreManager storeMgr, org.datanucleus.ExecutionContext ec, JDOQLQuery q)
    Constructs a new query instance having the same criteria as the given query.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addExtension(String key, Object value)
    Add a vendor-specific extension this query.
    protected void
    Method that will throw an UnsupportedOperationException if the query implementation doesn't support cancelling queries.
    protected boolean
     
    protected void
    compileInternal(Map parameterValues)
    Method to compile the JDOQL 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.
    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 boolean
    Convenience method to return whether the query should be evaluated in-memory.
     
     
    protected String
    Method to get key for query cache
    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.
    private void
     
    protected boolean
    Convenience method for whether this query supports timeouts.

    Methods inherited from class org.datanucleus.store.query.AbstractJDOQLQuery

    compileGeneric, compileSubqueries, getLanguage, getSingleStringQuery, setGrouping, setResult

    Methods inherited from class org.datanucleus.store.query.AbstractJavaQuery

    dereferenceFilter, 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, resolveClassDeclaration, setCacheResults, setCandidateClass, setCandidateClassName, setCompilation, setDatastoreReadTimeoutMillis, setDatastoreWriteTimeoutMillis, setFetchPlan, setFilter, setFrom, setHaving, setIgnoreCache, setImplicitParameter, setImplicitParameter, setInsertFields, setInsertSelectQuery, setOrdering, setRange, setRange, setResultClass, setResultClassName, setResultDistinct, setResultMetaData, setSerializeRead, setSubclasses, setType, setUnique, setUnmodifiable, setUpdate, shouldReturnSingleRow, useCaching, useFetchPlan, useResultsCaching

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      See Also:
    • EXTENSION_USE_IS_NULL_WHEN_EQUALS_NULL_PARAM

      public static final String EXTENSION_USE_IS_NULL_WHEN_EQUALS_NULL_PARAM
      Extension for whether to convert "== ?" with null parameter to "IS NULL". Defaults to true to match Java semantics.
    • EXTENSION_FOR_UPDATE_NOWAIT

      public static final String EXTENSION_FOR_UPDATE_NOWAIT
      Extension to add NOWAIT when using FOR UPDATE (when supported).
    • EXTENSION_CANDIDATE_DONT_RESTRICT_DISCRIMINATOR

      public static final String EXTENSION_CANDIDATE_DONT_RESTRICT_DISCRIMINATOR
      Extension to not apply a discriminator restriction on the candidate of the query.
    • EXTENSION_INCLUDE_SOFT_DELETES

      public static final String EXTENSION_INCLUDE_SOFT_DELETES
      Extension to include soft-deleted objects in any results.
    • EXTENSION_NON_DISTINCT_IMPLICIT_JOIN

      public static final String EXTENSION_NON_DISTINCT_IMPLICIT_JOIN
      Extension for whether to disable the setting of DISTINCT when joining with JDOQL.
    • EXTENSION_NAVIGATION_JOIN_TYPE_FILTER

      public static final String 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

      public static final String EXTENSION_NAVIGATION_JOIN_TYPE
      Extension to define the JOIN TYPE to use when navigating single-valued relations.
    • datastoreCompilation

      protected transient RDBMSQueryCompilation datastoreCompilation
      The compilation of the query for this datastore. Not applicable if totally in-memory.
    • statementReturnsEmpty

      boolean statementReturnsEmpty
  • Constructor Details

    • JDOQLQuery

      public JDOQLQuery(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 query
      ec - execution context
    • JDOQLQuery

      public JDOQLQuery(org.datanucleus.store.StoreManager storeMgr, org.datanucleus.ExecutionContext ec, JDOQLQuery q)
      Constructs a new query instance having the same criteria as the given query.
      Parameters:
      storeMgr - StoreManager for this query
      ec - execution context
      q - The query from which to copy criteria.
    • JDOQLQuery

      public JDOQLQuery(org.datanucleus.store.StoreManager storeMgr, org.datanucleus.ExecutionContext ec, String query)
      Constructor for a JDOQL query where the query is specified using the "Single-String" format.
      Parameters:
      storeMgr - StoreManager for this query
      ec - execution context
      query - The single-string query form
  • Method Details

    • discardCompiled

      protected void discardCompiled()
      Utility to remove any previous compilation of this Query.
      Overrides:
      discardCompiled in class org.datanucleus.store.query.AbstractJavaQuery
    • 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
    • evaluateInMemory

      protected boolean evaluateInMemory()
      Convenience method to return whether the query should be evaluated in-memory.
      Overrides:
      evaluateInMemory in class org.datanucleus.store.query.AbstractJavaQuery
      Returns:
      Use in-memory evaluation?
    • getQueryCacheKey

      protected String getQueryCacheKey()
      Method to get key for query cache
      Overrides:
      getQueryCacheKey in class org.datanucleus.store.query.AbstractJDOQLQuery
      Returns:
      The cache key
    • compileInternal

      protected void compileInternal(Map parameterValues)
      Method to compile the JDOQL query. Uses the superclass to compile the generic query populating the "compilation", and then generates the datastore-specific "datastoreCompilation".
      Overrides:
      compileInternal in class org.datanucleus.store.query.AbstractJDOQLQuery
      Parameters:
      parameterValues - Map of param values keyed by param name (if available at compile time)
    • getSQL

      public String getSQL()
      Convenience accessor for the SQL to invoke in the datastore for this query.
      Returns:
      The SQL.
    • performExecute

      protected Object performExecute(Map parameters)
      Specified by:
      performExecute in class org.datanucleus.store.query.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
    • cancelTaskObject

      protected boolean cancelTaskObject(Object obj)
      Overrides:
      cancelTaskObject in class org.datanucleus.store.query.Query
    • supportsTimeout

      protected boolean supportsTimeout()
      Convenience method for whether this query supports timeouts.
      Overrides:
      supportsTimeout in class org.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.
      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
    • 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

      private void setMapperJoinTypes(QueryToSQLMapper sqlMapper)
    • processesRangeInDatastoreQuery

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

      public Set<String> 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 class org.datanucleus.store.query.AbstractJDOQLQuery
      Returns:
      The supported extension names
    • addExtension

      public void addExtension(String key, Object value)
      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 class org.datanucleus.store.query.Query
      Parameters:
      key - the extension key
      value - the extension value
    • setExtensions

      public void setExtensions(Map extensions)
      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 class org.datanucleus.store.query.Query
      Parameters:
      extensions - Query extensions
    • getDatastoreCompilation

      public RDBMSQueryCompilation getDatastoreCompilation()
    • getNativeQuery

      public Object getNativeQuery()
      Overrides:
      getNativeQuery in class org.datanucleus.store.query.Query