Class JPQLQuery

  • All Implemented Interfaces:
    java.io.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:
    Serialized Form
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private class  JPQLQuery.BulkTable  
      • 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
      protected RDBMSQueryCompilation datastoreCompilation
      The compilation of the query for this datastore.
      static java.lang.String EXTENSION_CANDIDATE_DONT_RESTRICT_DISCRIMINATOR
      Extension to not apply a discriminator restriction on the candidate of the query.
      static java.lang.String EXTENSION_FOR_UPDATE_NOWAIT
      Extension to add NOWAIT when using FOR UPDATE (when supported).
      static java.lang.String EXTENSION_INCLUDE_SOFT_DELETES
      Extension to include soft-deleted objects in any results.
      static java.lang.String EXTENSION_NAVIGATION_JOIN_TYPE
      Extension to define the JOIN TYPE to use when navigating single-valued relations.
      static java.lang.String EXTENSION_NAVIGATION_JOIN_TYPE_FILTER
      Extension to define the JOIN TYPE to use when navigating single-valued relations, when part of the filter.
      static java.lang.String EXTENSION_USE_IS_NULL_WHEN_EQUALS_NULL_PARAM
      Extension for whether to convert "== ?" with null parameter to "IS NULL".
      private static long serialVersionUID  
      (package private) boolean statementReturnsEmpty  
      • 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
      JPQLQuery​(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, java.lang.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

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addExtension​(java.lang.String key, java.lang.Object value)
      Add a vendor-specific extension this query.
      protected void assertSupportsCancel()
      Method that will throw an UnsupportedOperationException if the query implementation doesn't support cancelling queries.
      protected boolean cancelTaskObject​(java.lang.Object obj)  
      protected void compileInternal​(java.util.Map parameterValues)
      Method to compile the JPQL query.
      protected void compileQueryDelete​(java.util.Map parameterValues, org.datanucleus.metadata.AbstractClassMetaData candidateCmd)
      Method to compile the query for RDBMS for a bulk delete.
      private void compileQueryFull​(java.util.Map parameters, org.datanucleus.metadata.AbstractClassMetaData candidateCmd)
      Method to set the (native) query statement for the compiled query as a whole.
      protected void compileQueryInsert​(java.util.Map parameterValues, org.datanucleus.metadata.AbstractClassMetaData candidateCmd)
      Method to compile the query for RDBMS for a bulk INSERT.
      private void compileQueryToRetrieveCandidates​(java.util.Map parameters, org.datanucleus.metadata.AbstractClassMetaData candidateCmd)
      Method to set the statement (and parameter/results definitions) to retrieve all candidates.
      protected void compileQueryUpdate​(java.util.Map parameterValues, org.datanucleus.metadata.AbstractClassMetaData candidateCmd)
      Method to compile the query for RDBMS for a bulk update.
      protected void discardCompiled()
      Utility to remove any previous compilation of this Query.
      RDBMSQueryCompilation getDatastoreCompilation()  
      java.lang.Object getNativeQuery()  
      protected java.lang.String getQueryCacheKey()
      Method to get key for query cache
      java.lang.String getSQL()
      Convenience accessor for the SQL to invoke in the datastore for this query.
      java.util.Set<java.lang.String> getSupportedExtensions()
      Method to return the names of the extensions supported by this query.
      protected boolean isCompiled()
      Method to return if the query is compiled.
      protected java.lang.Object performExecute​(java.util.Map parameters)  
      boolean processesRangeInDatastoreQuery()  
      void setExtensions​(java.util.Map extensions)
      Set multiple extensions, or use null to clear extensions.
      void setImplicitParameter​(int position, java.lang.Object value)  
      void setImplicitParameter​(java.lang.String name, java.lang.Object value)  
      private void setMapperJoinTypes​(QueryToSQLMapper sqlMapper)  
      protected boolean supportsTimeout()
      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
      • Methods inherited from class java.lang.Object

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

      • EXTENSION_USE_IS_NULL_WHEN_EQUALS_NULL_PARAM

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

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

        public static final java.lang.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 java.lang.String EXTENSION_INCLUDE_SOFT_DELETES
        Extension to include soft-deleted objects in any results.
      • EXTENSION_NAVIGATION_JOIN_TYPE_FILTER

        public static final java.lang.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 java.lang.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 Detail

      • 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 query
        ec - 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 query
        ec - execution context
        q - The query from which to copy criteria.
      • JPQLQuery

        public JPQLQuery​(org.datanucleus.store.StoreManager storeMgr,
                         org.datanucleus.ExecutionContext ec,
                         java.lang.String query)
        Constructor for a JPQL query where the query is specified using the "Single-String" format.
        Parameters:
        storeMgr - StoreManager for this query
        ec - The ExecutionContext
        query - The single-string query form
    • Method Detail

      • setImplicitParameter

        public void setImplicitParameter​(int position,
                                         java.lang.Object value)
        Overrides:
        setImplicitParameter in class org.datanucleus.store.query.Query
      • setImplicitParameter

        public void setImplicitParameter​(java.lang.String name,
                                         java.lang.Object value)
        Overrides:
        setImplicitParameter in class org.datanucleus.store.query.Query
      • 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
      • getQueryCacheKey

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

        protected void compileInternal​(java.util.Map parameterValues)
        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 class org.datanucleus.store.query.AbstractJPQLQuery
        Parameters:
        parameterValues - Map of param values keyed by param name (if available at compile time)
      • getSQL

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

        protected java.lang.Object performExecute​(java.util.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​(java.lang.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​(java.util.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​(java.util.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​(java.util.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​(java.util.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​(java.util.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 java.util.Set<java.lang.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.AbstractJPQLQuery
        Returns:
        The supported extension names
      • addExtension

        public void addExtension​(java.lang.String key,
                                 java.lang.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​(java.util.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
      • getNativeQuery

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