org.apache.openjpa.persistence
Class QueryImpl<X>

java.lang.Object
  extended by org.apache.openjpa.persistence.AbstractQuery<X>
      extended by org.apache.openjpa.persistence.QueryImpl<X>
All Implemented Interfaces:
Serializable, Query, TypedQuery<X>, OpenJPAQuery<X>, OpenJPAQuerySPI<X>

public class QueryImpl<X>
extends AbstractQuery<X>
implements Serializable

Implementation of Query interface.

Author:
Marc Prud'hommeaux, Abe White
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.apache.openjpa.persistence.AbstractQuery
_boundParams, _convertPositionalParams, _declaredParams, _em, _qmd, _relaxBindParameterTypeChecking
 
Fields inherited from interface org.apache.openjpa.persistence.OpenJPAQuery
FLUSH_FALSE, FLUSH_TRUE, FLUSH_WITH_CONNECTION, HINT_RESULT_COUNT, OP_DELETE, OP_SELECT, OP_UPDATE
 
Constructor Summary
QueryImpl(EntityManagerImpl em, Query query)
          Deprecated.  
QueryImpl(EntityManagerImpl em, RuntimeExceptionTranslator ret, Query query)
          Deprecated.  
QueryImpl(EntityManagerImpl em, RuntimeExceptionTranslator ret, Query query, QueryMetaData qmd)
          Constructor; supply factory exception translator and delegate.
 
Method Summary
 OpenJPAQuery<X> addAggregateListener(AggregateListener listener)
          Register an aggregate listener for the query.
 OpenJPAQuery<X> addFilterListener(FilterListener listener)
          Register a filter listener for the query.
(package private)  void assertJPQLOrCriteriaQuery()
          Asserts that this query is a JPQL or Criteria Query.
protected  void assertOpen()
           
 OpenJPAQuery<X> closeAll()
          Close all open query results.
 OpenJPAQuery<X> compile()
          Compile the query.
 boolean equals(Object other)
           
 int executeUpdate()
           
 Collection<?> getCandidateCollection()
          Return the candidate collection, or null if an extent was specified instead of a collection.
 String[] getDataStoreActions(Map params)
          Returns a description of the commands that will be sent to the datastore in order to execute this query.
 Query getDelegate()
          Delegate.
 OpenJPAEntityManager getEntityManager()
          The owning entity manager.
 FetchPlan getFetchPlan()
          Fetch plan for controlling the loading of results.
 int getFirstResult()
          Return the 0-based start index for the returned results.
 FlushModeType getFlushMode()
          Return the current flush mode.
 Map<String,Object> getHints()
          Get all the active hints and their values.
 boolean getIgnoreChanges()
          Whether to ignore changes in the current transaction.
 String getLanguage()
          Query language.
 LockModeType getLockMode()
           
 int getMaxResults()
          Return the maximum number of results to retrieve.
 QueryOperationType getOperation()
          Query operation type.
 OrderedMap<Object,Class<?>> getParamTypes()
           
 String getQueryString()
          Query string.
 Class getResultClass()
          Query result element type.
 List getResultList()
           
 X getSingleResult()
          Execute a query that returns a single result.
 Set<String> getSupportedHints()
          Gets hints supported by this query.
 int hashCode()
           
 boolean hasSubclasses()
          Whether subclasses are included in the query results.
(package private)  void ignorePreparedQuery()
          Ignores this query from PreparedQueryCache by recreating the original query if it has been cached.
(package private)  boolean invalidatePreparedQuery()
          Remove this query from PreparedQueryCache.
protected  void lock()
           
 OpenJPAQuery<X> removeAggregateListener(AggregateListener listener)
          Remove an aggregate listener from the query.
 OpenJPAQuery<X> removeFilterListener(FilterListener listener)
          Remove a filter listener from the query.
 OpenJPAQuery<X> setCandidateCollection(Collection coll)
          Set a collection of candidates.
 OpenJPAQuery<X> setFirstResult(int startPosition)
           
 OpenJPAQuery<X> setFlushMode(FlushModeType flushMode)
           
 OpenJPAQuery<X> setHint(String key, Object value)
           
(package private)  QueryImpl setId(String id)
           
 OpenJPAQuery<X> setIgnoreChanges(boolean ignore)
          Whether to ignore changes in the current transaction.
 TypedQuery<X> setLockMode(LockModeType lockMode)
          Sets lock mode on the given query.
 OpenJPAQuery<X> setMaxResults(int max)
           
 OpenJPAQuery<X> setResultClass(Class cls)
          Query result element type.
 OpenJPAQuery<X> setSubclasses(boolean subs)
          Whether subclasses are included in the query results.
 String toString()
           
protected  void unlock()
           
<T> T
unwrap(Class<T> cls)
          Unwraps this receiver to an instance of the given class, if possible.
 
Methods inherited from class org.apache.openjpa.persistence.AbstractQuery
assertBound, assertValueAssignable, bindValue, calculateMaxKey, clearBinding, convertTemporalType, convertTemporalType, declareParameter, getBoundParameterKeys, getDeclaredParameterKeys, getDeclaredParameterKeys, getDeclaredParameters, getNamedParameters, getParameter, getParameter, getParameter, getParameter, getParameters, getParameterValue, getParameterValue, getParameterValue, getParameterValues, getPositionalParameters, getRelaxBindParameterTypeChecking, hasPositionalParameters, isBound, isNative, setParameter, setParameter, setParameter, setParameter, setParameter, setParameter, setParameter, setParameter, setParameter, setParameters, setParameters, setRelaxBindParameterTypeChecking
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

QueryImpl

public QueryImpl(EntityManagerImpl em,
                 RuntimeExceptionTranslator ret,
                 Query query,
                 QueryMetaData qmd)
Constructor; supply factory exception translator and delegate.

Parameters:
em - The EntityManager which created this query
ret - Exception translator for this query
query - The underlying "kernel" query.

QueryImpl

public QueryImpl(EntityManagerImpl em,
                 RuntimeExceptionTranslator ret,
                 Query query)
Deprecated. 

Constructor; supply factory and delegate.


QueryImpl

public QueryImpl(EntityManagerImpl em,
                 Query query)
Deprecated. 

Constructor; supply factory and delegate.

Method Detail

getDelegate

public Query getDelegate()
Delegate.


getEntityManager

public OpenJPAEntityManager getEntityManager()
Description copied from interface: OpenJPAQuery
The owning entity manager.

Specified by:
getEntityManager in interface OpenJPAQuery<X>

getLanguage

public String getLanguage()
Description copied from interface: OpenJPAQuery
Query language.

Specified by:
getLanguage in interface OpenJPAQuery<X>

getOperation

public QueryOperationType getOperation()
Description copied from interface: OpenJPAQuery
Query operation type.

Specified by:
getOperation in interface OpenJPAQuery<X>

getFetchPlan

public FetchPlan getFetchPlan()
Description copied from interface: OpenJPAQuery
Fetch plan for controlling the loading of results.

Specified by:
getFetchPlan in interface OpenJPAQuery<X>

getQueryString

public String getQueryString()
Description copied from interface: OpenJPAQuery
Query string.

Specified by:
getQueryString in interface OpenJPAQuery<X>

getIgnoreChanges

public boolean getIgnoreChanges()
Description copied from interface: OpenJPAQuery
Whether to ignore changes in the current transaction.

Specified by:
getIgnoreChanges in interface OpenJPAQuery<X>

setIgnoreChanges

public OpenJPAQuery<X> setIgnoreChanges(boolean ignore)
Description copied from interface: OpenJPAQuery
Whether to ignore changes in the current transaction.

Specified by:
setIgnoreChanges in interface OpenJPAQuery<X>

addFilterListener

public OpenJPAQuery<X> addFilterListener(FilterListener listener)
Description copied from interface: OpenJPAQuerySPI
Register a filter listener for the query.

Specified by:
addFilterListener in interface OpenJPAQuery<X>
Specified by:
addFilterListener in interface OpenJPAQuerySPI<X>

removeFilterListener

public OpenJPAQuery<X> removeFilterListener(FilterListener listener)
Description copied from interface: OpenJPAQuerySPI
Remove a filter listener from the query.

Specified by:
removeFilterListener in interface OpenJPAQuery<X>
Specified by:
removeFilterListener in interface OpenJPAQuerySPI<X>

addAggregateListener

public OpenJPAQuery<X> addAggregateListener(AggregateListener listener)
Description copied from interface: OpenJPAQuerySPI
Register an aggregate listener for the query.

Specified by:
addAggregateListener in interface OpenJPAQuery<X>
Specified by:
addAggregateListener in interface OpenJPAQuerySPI<X>

removeAggregateListener

public OpenJPAQuery<X> removeAggregateListener(AggregateListener listener)
Description copied from interface: OpenJPAQuerySPI
Remove an aggregate listener from the query.

Specified by:
removeAggregateListener in interface OpenJPAQuery<X>
Specified by:
removeAggregateListener in interface OpenJPAQuerySPI<X>

getCandidateCollection

public Collection<?> getCandidateCollection()
Description copied from interface: OpenJPAQuery
Return the candidate collection, or null if an extent was specified instead of a collection.

Specified by:
getCandidateCollection in interface OpenJPAQuery<X>

setCandidateCollection

public OpenJPAQuery<X> setCandidateCollection(Collection coll)
Description copied from interface: OpenJPAQuery
Set a collection of candidates.

Specified by:
setCandidateCollection in interface OpenJPAQuery<X>

getResultClass

public Class getResultClass()
Description copied from interface: OpenJPAQuery
Query result element type.

Specified by:
getResultClass in interface OpenJPAQuery<X>

setResultClass

public OpenJPAQuery<X> setResultClass(Class cls)
Description copied from interface: OpenJPAQuery
Query result element type.

Specified by:
setResultClass in interface OpenJPAQuery<X>

hasSubclasses

public boolean hasSubclasses()
Description copied from interface: OpenJPAQuery
Whether subclasses are included in the query results.

Specified by:
hasSubclasses in interface OpenJPAQuery<X>

setSubclasses

public OpenJPAQuery<X> setSubclasses(boolean subs)
Description copied from interface: OpenJPAQuery
Whether subclasses are included in the query results.

Specified by:
setSubclasses in interface OpenJPAQuery<X>

getFirstResult

public int getFirstResult()
Description copied from interface: OpenJPAQuery
Return the 0-based start index for the returned results.

Specified by:
getFirstResult in interface Query
Specified by:
getFirstResult in interface OpenJPAQuery<X>

setFirstResult

public OpenJPAQuery<X> setFirstResult(int startPosition)
Specified by:
setFirstResult in interface Query
Specified by:
setFirstResult in interface TypedQuery<X>
Specified by:
setFirstResult in interface OpenJPAQuery<X>

getMaxResults

public int getMaxResults()
Description copied from interface: OpenJPAQuery
Return the maximum number of results to retrieve. or Integer.MAX_VALUE for no limit.

Specified by:
getMaxResults in interface Query
Specified by:
getMaxResults in interface OpenJPAQuery<X>

setMaxResults

public OpenJPAQuery<X> setMaxResults(int max)
Specified by:
setMaxResults in interface Query
Specified by:
setMaxResults in interface TypedQuery<X>
Specified by:
setMaxResults in interface OpenJPAQuery<X>

compile

public OpenJPAQuery<X> compile()
Description copied from interface: OpenJPAQuery
Compile the query.

Specified by:
compile in interface OpenJPAQuery<X>

getResultList

public List getResultList()
Specified by:
getResultList in interface Query
Specified by:
getResultList in interface TypedQuery<X>

getSingleResult

public X getSingleResult()
Execute a query that returns a single result.

Specified by:
getSingleResult in interface Query
Specified by:
getSingleResult in interface TypedQuery<X>

executeUpdate

public int executeUpdate()
Specified by:
executeUpdate in interface Query

getFlushMode

public FlushModeType getFlushMode()
Description copied from interface: OpenJPAQuery
Return the current flush mode.

Specified by:
getFlushMode in interface Query
Specified by:
getFlushMode in interface OpenJPAQuery<X>

setFlushMode

public OpenJPAQuery<X> setFlushMode(FlushModeType flushMode)
Specified by:
setFlushMode in interface Query
Specified by:
setFlushMode in interface TypedQuery<X>
Specified by:
setFlushMode in interface OpenJPAQuery<X>

assertJPQLOrCriteriaQuery

void assertJPQLOrCriteriaQuery()
Asserts that this query is a JPQL or Criteria Query.


closeAll

public OpenJPAQuery<X> closeAll()
Description copied from interface: OpenJPAQuery
Close all open query results.

Specified by:
closeAll in interface OpenJPAQuery<X>

getDataStoreActions

public String[] getDataStoreActions(Map params)
Description copied from interface: OpenJPAQuery
Returns a description of the commands that will be sent to the datastore in order to execute this query. This will typically be in the native query language of the database (e.g., SQL).

Specified by:
getDataStoreActions in interface OpenJPAQuery<X>
Parameters:
params - the named parameter map for the query invocation

getLockMode

public LockModeType getLockMode()
Specified by:
getLockMode in interface Query

setLockMode

public TypedQuery<X> setLockMode(LockModeType lockMode)
Sets lock mode on the given query. If the target query has been prepared and cached, then ignores the cached version.

Specified by:
setLockMode in interface Query
Specified by:
setLockMode in interface TypedQuery<X>
See Also:
ignorePreparedQuery()

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object other)
Overrides:
equals in class Object

getHints

public Map<String,Object> getHints()
Get all the active hints and their values.

Specified by:
getHints in interface Query

setHint

public OpenJPAQuery<X> setHint(String key,
                               Object value)
Specified by:
setHint in interface Query
Specified by:
setHint in interface TypedQuery<X>
Specified by:
setHint in interface OpenJPAQuery<X>

getSupportedHints

public Set<String> getSupportedHints()
Description copied from interface: OpenJPAQuery
Gets hints supported by this query.

Specified by:
getSupportedHints in interface OpenJPAQuery<X>

unwrap

public <T> T unwrap(Class<T> cls)
Unwraps this receiver to an instance of the given class, if possible.

Specified by:
unwrap in interface Query
Throws:
if - the given class is null, generic Object.class or a class that is not wrapped by this receiver.
Since:
2.0.0

invalidatePreparedQuery

boolean invalidatePreparedQuery()
Remove this query from PreparedQueryCache.


ignorePreparedQuery

void ignorePreparedQuery()
Ignores this query from PreparedQueryCache by recreating the original query if it has been cached.


setId

QueryImpl setId(String id)

lock

protected void lock()
Specified by:
lock in class AbstractQuery<X>

unlock

protected void unlock()
Specified by:
unlock in class AbstractQuery<X>

assertOpen

protected void assertOpen()
Specified by:
assertOpen in class AbstractQuery<X>

getParamTypes

public OrderedMap<Object,Class<?>> getParamTypes()
Specified by:
getParamTypes in class AbstractQuery<X>
Returns:
a map of parameter name to type for this query.

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2006-2012 Apache Software Foundation. All Rights Reserved.