Class JDOQuery<T>

java.lang.Object
org.datanucleus.api.jdo.JDOQuery<T>
Type Parameters:
T - Candidate class for this query
All Implemented Interfaces:
Serializable, AutoCloseable, javax.jdo.Query<T>

public class JDOQuery<T> extends Object implements javax.jdo.Query<T>
Wrapper for JDO Query class. Stores the PM the query is executed against, the internal query, and the query language. The language is stored since it is referenced by the JDO API and so we don't have to embody knowledge of which internal query type is for which language (could be moved to the internal query).
See Also:
  • Field Details

    • PROPERTY_CLOSEABLE_QUERY

      public static final String PROPERTY_CLOSEABLE_QUERY
      See Also:
    • serialVersionUID

      private static final long serialVersionUID
      See Also:
    • JDOQL_QUERY_LANGUAGE

      public static final String JDOQL_QUERY_LANGUAGE
      See Also:
    • JPQL_QUERY_LANGUAGE

      public static final String JPQL_QUERY_LANGUAGE
      See Also:
    • SQL_QUERY_LANGUAGE

      public static final String SQL_QUERY_LANGUAGE
      See Also:
    • pm

      transient javax.jdo.PersistenceManager pm
      PersistenceManager for the query.
    • query

      org.datanucleus.store.query.Query<T> query
      Underlying query that will be executed.
    • closed

      private boolean closed
    • language

      String language
      Query language.
    • fetchPlan

      JDOFetchPlan fetchPlan
      JDO Fetch Plan.
    • parameterValueByName

      Map parameterValueByName
      Map of parameters keyed by their name.
    • parameterValues

      Object[] parameterValues
      Positional parameter values.
  • Constructor Details

    • JDOQuery

      public JDOQuery(javax.jdo.PersistenceManager pm, org.datanucleus.store.query.Query<T> query, String language)
      Constructor for a query used by JDO.
      Parameters:
      pm - PersistenceManager
      query - Underlying query
      language - Query language
  • Method Details

    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface javax.jdo.Query<T>
    • isClosed

      public boolean isClosed()
      Accessor for whether this Query is closed.
      Returns:
      Whether this Query is closed.
    • close

      public void close(Object queryResult)
      Close the query result.
      Specified by:
      close in interface javax.jdo.Query<T>
      Parameters:
      queryResult - Query result
    • closeAll

      public void closeAll()
      Close all query results for this query.
      Specified by:
      closeAll in interface javax.jdo.Query<T>
    • compile

      public void compile()
      Compile the query.
      Specified by:
      compile in interface javax.jdo.Query<T>
    • declareImports

      public void declareImports(String imports)
      Declare any imports for the query.
      Specified by:
      declareImports in interface javax.jdo.Query<T>
      Parameters:
      imports - The imports
    • declareParameters

      public void declareParameters(String parameters)
      Declare any parameters for the query.
      Specified by:
      declareParameters in interface javax.jdo.Query<T>
      Parameters:
      parameters - The parameters
    • declareVariables

      public void declareVariables(String variables)
      Declare any variables for the query.
      Specified by:
      declareVariables in interface javax.jdo.Query<T>
      Parameters:
      variables - The variables
    • imports

      public javax.jdo.Query<T> imports(String imports)
      Specified by:
      imports in interface javax.jdo.Query<T>
    • parameters

      public javax.jdo.Query<T> parameters(String parameters)
      Specified by:
      parameters in interface javax.jdo.Query<T>
    • variables

      public javax.jdo.Query<T> variables(String variables)
      Specified by:
      variables in interface javax.jdo.Query<T>
    • setParameters

      public javax.jdo.Query<T> setParameters(Object... paramValues)
      Specified by:
      setParameters in interface javax.jdo.Query<T>
    • setNamedParameters

      public javax.jdo.Query<T> setNamedParameters(Map<String,?> paramMap)
      Specified by:
      setNamedParameters in interface javax.jdo.Query<T>
    • execute

      public Object execute()
      Execute the query.
      Specified by:
      execute in interface javax.jdo.Query<T>
      Returns:
      The results
    • execute

      public Object execute(Object p1)
      Execute the query.
      Specified by:
      execute in interface javax.jdo.Query<T>
      Parameters:
      p1 - First param value
      Returns:
      The results
    • execute

      public Object execute(Object p1, Object p2)
      Execute the query.
      Specified by:
      execute in interface javax.jdo.Query<T>
      Parameters:
      p1 - First param value
      p2 - Second param value
      Returns:
      The results
    • execute

      public Object execute(Object p1, Object p2, Object p3)
      Execute the query.
      Specified by:
      execute in interface javax.jdo.Query<T>
      Parameters:
      p1 - First param value
      p2 - Second param value
      p3 - Third param value
      Returns:
      The results
    • executeWithArray

      public Object executeWithArray(Object... parameterValues)
      Execute the query.
      Specified by:
      executeWithArray in interface javax.jdo.Query<T>
      Parameters:
      parameterValues - Param values
      Returns:
      The results
    • executeWithMap

      public Object executeWithMap(Map parameters)
      Execute the query.
      Specified by:
      executeWithMap in interface javax.jdo.Query<T>
      Parameters:
      parameters - Param values
      Returns:
      The results
    • executeList

      public List<T> executeList()
      Specified by:
      executeList in interface javax.jdo.Query<T>
    • executeUnique

      public T executeUnique()
      Specified by:
      executeUnique in interface javax.jdo.Query<T>
    • executeResultList

      public <R> List<R> executeResultList(Class<R> resultCls)
      Specified by:
      executeResultList in interface javax.jdo.Query<T>
    • executeResultUnique

      public <R> R executeResultUnique(Class<R> resultCls)
      Specified by:
      executeResultUnique in interface javax.jdo.Query<T>
    • executeResultList

      public List<Object> executeResultList()
      Specified by:
      executeResultList in interface javax.jdo.Query<T>
    • executeResultUnique

      public Object executeResultUnique()
      Specified by:
      executeResultUnique in interface javax.jdo.Query<T>
    • executeInternal

      protected Object executeInternal()
    • deletePersistentAll

      public long deletePersistentAll()
      Execute the query deleting all instances found.
      Specified by:
      deletePersistentAll in interface javax.jdo.Query<T>
      Returns:
      Number of deleted instances
    • deletePersistentAll

      public long deletePersistentAll(Object... parameters)
      Execute the query deleting all instances found.
      Specified by:
      deletePersistentAll in interface javax.jdo.Query<T>
      Parameters:
      parameters - Parameters to use when executing
      Returns:
      Number of deleted instances
    • deletePersistentAll

      public long deletePersistentAll(Map parameters)
      Execute the query deleting all instances found.
      Specified by:
      deletePersistentAll in interface javax.jdo.Query<T>
      Parameters:
      parameters - Parameters to use when executing
      Returns:
      Number of deleted instances
    • deletePersistentInternal

      protected long deletePersistentInternal()
    • cancelAll

      public void cancelAll()
      Method to cancel any executing queries.
      Specified by:
      cancelAll in interface javax.jdo.Query<T>
      Throws:
      javax.jdo.JDOUnsupportedOptionException - if the datastore doesn't support cancellation of queries
    • cancel

      public void cancel(Thread thr)
      Method to cancel the executing query for the supplied thread.
      Specified by:
      cancel in interface javax.jdo.Query<T>
      Throws:
      javax.jdo.JDOUnsupportedOptionException - if the datastore doesn't support cancellation of queries
    • setCandidates

      public void setCandidates(javax.jdo.Extent<T> extent)
      Set the candidates for the query.
      Specified by:
      setCandidates in interface javax.jdo.Query<T>
      Parameters:
      extent - Extent defining the candidates
    • setCandidates

      public void setCandidates(Collection<T> pcs)
      Set the candidates for the query.
      Specified by:
      setCandidates in interface javax.jdo.Query<T>
      Parameters:
      pcs - PC candidates
    • setClass

      public void setClass(Class<T> candidateClass)
      Set the candidate class for the query.
      Specified by:
      setClass in interface javax.jdo.Query<T>
      Parameters:
      candidateClass - Candidate class
    • addExtension

      public void addExtension(String key, Object value)
      Method to add an extension to the query.
      Specified by:
      addExtension in interface javax.jdo.Query<T>
      Parameters:
      key - Key for the extension
      value - Value for the extension
    • setExtensions

      public void setExtensions(Map extensions)
      Set the extensions for the query.
      Specified by:
      setExtensions in interface javax.jdo.Query<T>
      Parameters:
      extensions - The extensions
    • extension

      public javax.jdo.Query<T> extension(String key, Object value)
      Specified by:
      extension in interface javax.jdo.Query<T>
    • extensions

      public javax.jdo.Query<T> extensions(Map values)
      Specified by:
      extensions in interface javax.jdo.Query<T>
    • getFetchPlan

      public javax.jdo.FetchPlan getFetchPlan()
      Accessor for the fetch plan to use.
      Specified by:
      getFetchPlan in interface javax.jdo.Query<T>
      Returns:
      The fetch plan
    • filter

      public javax.jdo.Query<T> filter(String filter)
      Specified by:
      filter in interface javax.jdo.Query<T>
    • setFilter

      public void setFilter(String filter)
      Set the filter for the query.
      Specified by:
      setFilter in interface javax.jdo.Query<T>
      Parameters:
      filter - The query filter
    • groupBy

      public javax.jdo.Query<T> groupBy(String grouping)
      Specified by:
      groupBy in interface javax.jdo.Query<T>
    • setGrouping

      public void setGrouping(String grouping)
      Set the grouping for the query.
      Specified by:
      setGrouping in interface javax.jdo.Query<T>
      Parameters:
      grouping - The grouping
    • getIgnoreCache

      public boolean getIgnoreCache()
      Accessor for the ignore cache setting
      Specified by:
      getIgnoreCache in interface javax.jdo.Query<T>
      Returns:
      Ignore cache
    • setIgnoreCache

      public void setIgnoreCache(boolean ignoreCache)
      Set the ignore cache setting for the query.
      Specified by:
      setIgnoreCache in interface javax.jdo.Query<T>
      Parameters:
      ignoreCache - The ignore cache setting
    • ignoreCache

      public javax.jdo.Query<T> ignoreCache(boolean flag)
      Specified by:
      ignoreCache in interface javax.jdo.Query<T>
    • orderBy

      public javax.jdo.Query<T> orderBy(String ordering)
      Specified by:
      orderBy in interface javax.jdo.Query<T>
    • setOrdering

      public void setOrdering(String ordering)
      Set the ordering for the query.
      Specified by:
      setOrdering in interface javax.jdo.Query<T>
      Parameters:
      ordering - The ordering
    • getPersistenceManager

      public javax.jdo.PersistenceManager getPersistenceManager()
      Accessor for the PersistenceManager.
      Specified by:
      getPersistenceManager in interface javax.jdo.Query<T>
      Returns:
      PM
    • range

      public javax.jdo.Query<T> range(long fromIncl, long toExcl)
      Specified by:
      range in interface javax.jdo.Query<T>
    • range

      public javax.jdo.Query<T> range(String range)
      Specified by:
      range in interface javax.jdo.Query<T>
    • setRange

      public void setRange(String range)
      Set the range for the query.
      Specified by:
      setRange in interface javax.jdo.Query<T>
      Parameters:
      range - The range specification
    • setRange

      public void setRange(long fromIncl, long toExcl)
      Set the range for the query.
      Specified by:
      setRange in interface javax.jdo.Query<T>
      Parameters:
      fromIncl - From range inclusive
      toExcl - To range exclusive
    • result

      public javax.jdo.Query<T> result(String result)
      Specified by:
      result in interface javax.jdo.Query<T>
    • setResult

      public void setResult(String result)
      Set the result for the query.
      Specified by:
      setResult in interface javax.jdo.Query<T>
      Parameters:
      result - Result clause
    • setResultClass

      public void setResultClass(Class result_cls)
      Set the result class for the query.
      Specified by:
      setResultClass in interface javax.jdo.Query<T>
      Parameters:
      result_cls - Result class
    • setDatastoreReadTimeoutMillis

      public void setDatastoreReadTimeoutMillis(Integer timeout)
      Set the datastore read timeout.
      Specified by:
      setDatastoreReadTimeoutMillis in interface javax.jdo.Query<T>
      Parameters:
      timeout - Timeout interval (millisecs)
    • getDatastoreReadTimeoutMillis

      public Integer getDatastoreReadTimeoutMillis()
      Accessor for the datastore read timeout.
      Specified by:
      getDatastoreReadTimeoutMillis in interface javax.jdo.Query<T>
      Returns:
      Timeout (if defined)
    • setDatastoreWriteTimeoutMillis

      public void setDatastoreWriteTimeoutMillis(Integer timeout)
      Set the datastore write timeout.
      Specified by:
      setDatastoreWriteTimeoutMillis in interface javax.jdo.Query<T>
      Parameters:
      timeout - Timeout interval (millisecs)
    • getDatastoreWriteTimeoutMillis

      public Integer getDatastoreWriteTimeoutMillis()
      Accessor for the datastore write timeout.
      Specified by:
      getDatastoreWriteTimeoutMillis in interface javax.jdo.Query<T>
      Returns:
      Timeout (if defined)
    • datastoreReadTimeoutMillis

      public javax.jdo.Query<T> datastoreReadTimeoutMillis(Integer interval)
      Specified by:
      datastoreReadTimeoutMillis in interface javax.jdo.Query<T>
    • datastoreWriteTimeoutMillis

      public javax.jdo.Query<T> datastoreWriteTimeoutMillis(Integer interval)
      Specified by:
      datastoreWriteTimeoutMillis in interface javax.jdo.Query<T>
    • setUnique

      public void setUnique(boolean unique)
      Set whether to expect a unique result.
      Specified by:
      setUnique in interface javax.jdo.Query<T>
      Parameters:
      unique - Whether results are unique
    • isUnmodifiable

      public boolean isUnmodifiable()
      Accessor for whether the query is modifiable.
      Specified by:
      isUnmodifiable in interface javax.jdo.Query<T>
      Returns:
      Whether it is modifiable
    • setUnmodifiable

      public void setUnmodifiable()
      Set the query to be unmodifiable.
      Specified by:
      setUnmodifiable in interface javax.jdo.Query<T>
    • unmodifiable

      public javax.jdo.Query<T> unmodifiable()
      Specified by:
      unmodifiable in interface javax.jdo.Query<T>
    • addSubquery

      public void addSubquery(javax.jdo.Query sub, String variableDecl, String candidateExpr)
      Add a subquery to this query.
      Specified by:
      addSubquery in interface javax.jdo.Query<T>
      Parameters:
      sub - the subquery to add to this Query
      variableDecl - the name of the variable in the outer query to bind the results of the subquery
      candidateExpr - the candidate collection of the subquery as an expression using terms of the outer query
    • addSubquery

      public void addSubquery(javax.jdo.Query sub, String variableDecl, String candidateExpr, String parameter)
      Add a subquery to this query. The String version of the method binds the named expression to the parameter implictly or explicitly declared in the subquery.
      Specified by:
      addSubquery in interface javax.jdo.Query<T>
      Parameters:
      sub - the subquery to add to this Query
      variableDecl - the name of the variable to be used in this Query
      candidateExpr - the candidate collection to apply to the subquery
      parameter - the expression from the outer query to bind the parameter in the subquery
    • addSubquery

      public void addSubquery(javax.jdo.Query sub, String variableDecl, String candidateExpr, String... parameters)
      Add a subquery to this query. The String version of the method binds the named expression to the parameter implictly or explicitly declared in the subquery.
      Specified by:
      addSubquery in interface javax.jdo.Query<T>
      Parameters:
      sub - the subquery to add to this Query
      variableDecl - the name of the variable to be used in this Query
      candidateExpr - the candidate collection to apply to the subquery
      parameters - the expressions from the outer query to bind the parameter in the subquery
    • addSubquery

      public void addSubquery(javax.jdo.Query sub, String variableDecl, String candidateExpr, Map parameters)
      Add a subquery to this query. The String version of the method binds the named expression to the parameter implictly or explicitly declared in the subquery.
      Specified by:
      addSubquery in interface javax.jdo.Query<T>
      Parameters:
      sub - the subquery to add to this Query
      variableDecl - the name of the variable to be used in this Query
      candidateExpr - the candidate collection to apply to the subquery
      parameters - the expressions from the outer query to bind the parameter in the subquery
    • subquery

      public javax.jdo.Query<T> subquery(javax.jdo.Query sub, String variableDecl, String candidateExpr)
      Specified by:
      subquery in interface javax.jdo.Query<T>
    • subquery

      public javax.jdo.Query<T> subquery(javax.jdo.Query sub, String variableDecl, String candidateExpr, String parameter)
      Specified by:
      subquery in interface javax.jdo.Query<T>
    • subquery

      public javax.jdo.Query<T> subquery(javax.jdo.Query sub, String variableDecl, String candidateExpr, String... parameters)
      Specified by:
      subquery in interface javax.jdo.Query<T>
    • subquery

      public javax.jdo.Query<T> subquery(javax.jdo.Query sub, String variableDecl, String candidateExpr, Map parameters)
      Specified by:
      subquery in interface javax.jdo.Query<T>
    • getSerializeRead

      public Boolean getSerializeRead()
      Accessor for whether to serialise any read objects in this query.
      Specified by:
      getSerializeRead in interface javax.jdo.Query<T>
      Returns:
      The setting for whether to serialise any read objects
    • setSerializeRead

      public void setSerializeRead(Boolean serialize)
      Mutator for whether to serialise any read objects.
      Specified by:
      setSerializeRead in interface javax.jdo.Query<T>
      Parameters:
      serialize - Whether to serialise any read objects in this query.
    • serializeRead

      public javax.jdo.Query<T> serializeRead(Boolean serialize)
      Specified by:
      serializeRead in interface javax.jdo.Query<T>
    • getInternalQuery

      public org.datanucleus.store.query.Query<T> getInternalQuery()
      Accessor for the internal query.
      Returns:
      Internal query
    • getLanguage

      public String getLanguage()
      Accessor for the query language.
      Returns:
      Query language
    • saveAsNamedQuery

      public javax.jdo.Query<T> saveAsNamedQuery(String name)
      Save this query as a named query with the specified name.
      Specified by:
      saveAsNamedQuery in interface javax.jdo.Query<T>
      Parameters:
      name - The name to refer to it under
      Returns:
      This query
    • toString

      public String toString()
      Convenience method to return the query in string form.
      Overrides:
      toString in class Object
      Returns:
      Stringifier method
    • getNativeQuery

      public Object getNativeQuery()
      Accessor for the native query invoked by this query (if known at this time and supported by the store plugin).
      Returns:
      The native query (e.g for RDBMS this is the SQL).
    • assertIsOpen

      protected void assertIsOpen()
      Method to assert if this Query is open.
      Throws:
      javax.jdo.JDOFatalUserException - if the Query is closed.