java.lang.Object
org.eclipse.persistence.internal.jpa.QueryImpl
- Direct Known Subclasses:
EJBQueryImpl
,StoredProcedureQueryImpl
Concrete JPA query class. The JPA query wraps a DatabaseQuery which is
executed.
-
Field Summary
Modifier and TypeFieldDescriptionprotected DatabaseQuery
Wrapped native query.protected EntityManagerImpl
protected int
protected boolean
Stores if the wrapped query is shared, and requires cloning before being changed.protected LockModeType
protected int
protected String
static final int
-
Constructor Summary
ModifierConstructorDescriptionprotected
QueryImpl
(EntityManagerImpl entityManager) Base constructor for EJBQueryImpl.QueryImpl
(DatabaseQuery query, EntityManagerImpl entityManager) Create an EJBQueryImpl with a DatabaseQuery. -
Method Summary
Modifier and TypeMethodDescriptionprotected static void
applyArguments
(StoredProcedureCall call, DatabaseQuery query) Define the query arguments based on the procedure call.protected static DatabaseQuery
applyHints
(Map<String, Object> hints, DatabaseQuery query, ClassLoader classLoader, AbstractSession session) Set implementation-specific hints.protected void
If the query was from the jpql parse cache it must be cloned before being modified.void
close()
This method should be called to close any left over open connection to the database (if there is one).protected Object
convertTemporalType
(Object value, TemporalType type) Convert the given object to the class represented by the given temporal type.protected Object
Execute a ReadQuery by assigning the stored parameter values and running it in the databaseint
Execute an update or delete statement.protected Session
Return the wrappedDatabaseQuery
ensuring that if itisShared
it is cloned before returning to prevent corruption of the query cache.INTERNAL: Return the cached database query for this EJBQueryImpl.protected RuntimeException
Given a DatabaseException, this method will determine if we should throw a different more specific exception like a lock timeout exception.Return the entityManager this query is tied to.int
getHints()
Return the internal map of parameters.Get the current lock mode for the query.int
int
Parameter
<?> getParameter
(int position) <T> Parameter
<T> getParameter
(int position, Class<T> type) Parameter
<?> getParameter
(String name) <T> Parameter
<T> getParameter
(String name, Class<T> type) static String
getParameterId
(Parameter param) Return the identifier of this parameter.getParameterValue
(int position) Return the value bound to the positional parameter.<T> T
getParameterValue
(Parameter<T> param) getParameterValue
(String name) Return the value bound to the named parameter.Execute the query and return the query results as a List.Execute a SELECT query that returns a single untyped result.boolean
Return a boolean indicating whether a value has been bound to the parameter.protected boolean
Spec.protected boolean
isValidActualParameter
(Object value, Class<?> parameterType) protected void
Internal method to add the parameters values to the query prior to execution.protected void
Configure the firstResult, maxRows and lock mode in the EclipseLink ReadQuery.protected void
INTERNAL: Change the internal query to data modify query.protected void
Internal method to change the wrapped query to a DataModifyQuery if necessary.protected void
Internal method to change the wrapped query to a DataReadQuery if necessary.void
setDatabaseQuery
(DatabaseQuery query) Replace the cached query with the given query.setFirstResult
(int startPosition) Set the position of the first result to retrieve.protected void
setFirstResultInternal
(int startPosition) Set the position of the first result to retrieve.setFlushMode
(FlushModeType flushMode) Set the flush mode type to be used for the query execution.protected void
setHintInternal
(String hintName, Object value) Set an implementation-specific hint.setLockMode
(LockModeType lockMode) Set the lock mode type to be used for the query execution.setMaxResults
(int maxResult) Set the maximum number of results to retrieve.void
setMaxResultsInternal
(int maxResult) Set the maximum number of results to retrieve.protected void
setParameterInternal
(int position, Object value) Bind an argument to a positional parameter.protected void
setParameterInternal
(String name, Object value, boolean isIndex) Bind an argument to a named or indexed parameter.protected void
protected void
throwNonUniqueResultException
(String message) protected void
throwNoResultException
(String message) toString()
<T> T
Unwrap the query into the JPA implementation classes/interfaces or the underlying native EclipseLink query.
-
Field Details
-
UNDEFINED
public static final int UNDEFINED- See Also:
-
databaseQuery
Wrapped native query. The query may beisShared
-
entityManager
-
queryName
-
parameterValues
-
parameters
-
firstResultIndex
protected int firstResultIndex -
maxResults
protected int maxResults -
lockMode
-
-
Constructor Details
-
QueryImpl
Base constructor for EJBQueryImpl. Initializes basic variables. -
QueryImpl
Create an EJBQueryImpl with a DatabaseQuery.
-
-
Method Details
-
close
public void close()This method should be called to close any left over open connection to the database (if there is one). -
setAsDataModifyQuery
protected void setAsDataModifyQuery()INTERNAL: Change the internal query to data modify query. -
setAsSQLModifyQuery
protected void setAsSQLModifyQuery()Internal method to change the wrapped query to a DataModifyQuery if necessary. When created, the query is created as a DataReadQuery as it is unknown if it is a SELECT or UPDATE. Note that this prevents the original named query from every being prepared. -
setAsSQLReadQuery
protected void setAsSQLReadQuery()Internal method to change the wrapped query to a DataReadQuery if necessary. This should never occur, but could possibly if the same query was executed as executeUpdate() then as getResultList(). Note that the initial conversion to modify would loose any read settings that had been set. -
executeReadQuery
Execute a ReadQuery by assigning the stored parameter values and running it in the database- Returns:
- the results of the query execution
-
executeUpdate
public int executeUpdate()Execute an update or delete statement.- Returns:
- the number of entities updated or deleted
-
getDatabaseQuery
Return the wrappedDatabaseQuery
ensuring that if itisShared
it is cloned before returning to prevent corruption of the query cache.- See Also:
-
getDatabaseQueryInternal
INTERNAL: Return the cached database query for this EJBQueryImpl. If the query is a named query and it has not yet been looked up, the query will be looked up and stored as the cached query. -
getDetailedException
Given a DatabaseException, this method will determine if we should throw a different more specific exception like a lock timeout exception. -
getEntityManager
Return the entityManager this query is tied to. -
getInternalParameters
Return the internal map of parameters. -
getLockMode
Get the current lock mode for the query.- Returns:
- lock mode
- Throws:
IllegalStateException
- if not a Java Persistence query language SELECT query
-
getResultList
Execute the query and return the query results as a List.- Returns:
- a list of the results
-
getSingleResult
Execute a SELECT query that returns a single untyped result.- Returns:
- the result
- Throws:
NoResultException
- if there is no resultNonUniqueResultException
- if more than one resultIllegalStateException
- if called for a Java Persistence query language UPDATE or DELETE statementQueryTimeoutException
- if the query execution exceeds the query timeout value set and only the statement is rolled backTransactionRequiredException
- if a lock mode other than NONE has been been set and there is no transaction or the persistence context has not been joined to the transactionPessimisticLockException
- if pessimistic locking fails and the transaction is rolled backLockTimeoutException
- if pessimistic locking fails and only the statement is rolled backPersistenceException
- if the query execution exceeds the query timeout value set and the transaction is rolled back
-
processParameters
Internal method to add the parameters values to the query prior to execution. Returns a list of parameter values in the order the parameters are defined for the databaseQuery. -
setDatabaseQuery
Replace the cached query with the given query. -
setFirstResult
Set the position of the first result to retrieve.- Parameters:
startPosition
- position of the first result, numbered from 0- Returns:
- the same query instance
-
getFirstResult
public int getFirstResult()- Since:
- Java Persistence API 2.0
- See Also:
-
setFlushMode
Set the flush mode type to be used for the query execution. -
setFirstResultInternal
protected void setFirstResultInternal(int startPosition) Set the position of the first result to retrieve.- Parameters:
startPosition
- position of the first result, numbered from 0.
-
applyArguments
Define the query arguments based on the procedure call. -
applyHints
protected static DatabaseQuery applyHints(Map<String, Object> hints, DatabaseQuery query, ClassLoader classLoader, AbstractSession session) Set implementation-specific hints.- Parameters:
hints
- a list of hints to be applied to the queryquery
- the query to apply the hints to
-
getParameterId
Return the identifier of this parameter. This will be the name if it is set, else it will be the position -
isBound
Return a boolean indicating whether a value has been bound to the parameter.- Parameters:
param
- parameter object- Returns:
- boolean indicating whether parameter has been bound
-
isFlushModeAUTO
protected boolean isFlushModeAUTO()Spec. 3.5.2: "FlushMode.AUTO is set on the Query object, or if the flush mode setting for the persistence context is AUTO (the default) and a flush mode setting has not been specified for the Query object, the persistence provider is responsible for ensuring that all updates to the state of all entities in the persistence context which could potentially affect the result of the query are visible to the processing of the query." -
setHintInternal
Set an implementation-specific hint. If the hint name is not recognized, it is silently ignored.- Throws:
IllegalArgumentException
- if the second argument is not valid for the implementation.
-
setLockMode
Set the lock mode type to be used for the query execution.- Throws:
IllegalStateException
- if not a Java Persistence query language SELECT query
-
convertTemporalType
Convert the given object to the class represented by the given temporal type.- Returns:
- an object representing the given TemporalType.
-
setMaxResults
Set the maximum number of results to retrieve.- Returns:
- the same query instance
-
getMaxResults
public int getMaxResults()- Since:
- Java Persistence API 2.0
- See Also:
-
getMaxResultsInternal
public int getMaxResultsInternal()- Since:
- Java Persistence API 2.0
- See Also:
-
setMaxResultsInternal
public void setMaxResultsInternal(int maxResult) Set the maximum number of results to retrieve. -
propagateResultProperties
protected void propagateResultProperties()Configure the firstResult, maxRows and lock mode in the EclipseLink ReadQuery. -
setParameterInternal
Bind an argument to a positional parameter. -
setParameterInternal
Bind an argument to a named or indexed parameter.- Parameters:
name
- the parameter namevalue
- to bindisIndex
- defines if index or named
-
isValidActualParameter
-
getActiveSession
-
performPreQueryFlush
protected void performPreQueryFlush() -
setRollbackOnly
protected void setRollbackOnly() -
throwNoResultException
-
throwNonUniqueResultException
-
getFlushMode
- Since:
- Java Persistence 2.0
- See Also:
-
getHints
- Since:
- Java Persistence 2.0
- See Also:
-
getParameter
- Since:
- Java Persistence 2.0
- See Also:
-
getParameter
- Since:
- Java Persistence 2.0
- See Also:
-
getParameter
- Since:
- Java Persistence 2.0
- See Also:
-
getParameter
- Since:
- Java Persistence 2.0
- See Also:
-
getParameterValue
- Since:
- Java Persistence 2.0
- See Also:
-
getParameterValue
Return the value bound to the named parameter.- Returns:
- parameter value
- Throws:
IllegalStateException
- if the parameter has not been been bound
-
getParameterValue
Return the value bound to the positional parameter.- Returns:
- parameter value
- Throws:
IllegalStateException
- if the parameter has not been been bound
-
getParameters
- Since:
- Java Persistence 2.0
- See Also:
-
getSupportedHints
- Since:
- Java Persistence 2.0
-
unwrap
Unwrap the query into the JPA implementation classes/interfaces or the underlying native EclipseLink query.- Since:
- Java Persistence 2.0
- See Also:
-
toString
-