Top Description Fields Constructors Methods
org.eclipse.persistence.internal.jpa

public Class QueryImpl

extends Object
Class Inheritance
Known Direct Subclasses
org.eclipse.persistence.internal.jpa.StoredProcedureQueryImpl, org.eclipse.persistence.internal.jpa.EJBQueryImpl
Imports
java.util.ArrayList, .HashMap, .HashSet, .List, .Map, .Set, jakarta.persistence.FlushModeType, .LockModeType, .LockTimeoutException, .NoResultException, .NonUniqueResultException, .Parameter, .PersistenceException, .PessimisticLockException, .Query, .QueryTimeoutException, .TemporalType, .TransactionRequiredException, org.eclipse.persistence.exceptions.DatabaseException, .QueryException, org.eclipse.persistence.internal.helper.BasicTypeHelperImpl, .ClassConstants, .ConversionManager, .DatabaseField, .Helper, org.eclipse.persistence.internal.jpa.querydef.ParameterExpressionImpl, org.eclipse.persistence.internal.localization.ExceptionLocalization, org.eclipse.persistence.internal.sessions.AbstractSession, .UnitOfWorkImpl, org.eclipse.persistence.jpa.JpaEntityManager, org.eclipse.persistence.platform.database.oracle.plsql.PLSQLStoredProcedureCall, .PLSQLargument, org.eclipse.persistence.queries.Call, .DataModifyQuery, .DataReadQuery, .DatabaseQuery, .DatabaseQuery.ParameterType, .ModifyQuery, .ObjectLevelReadQuery, .ReadAllQuery, .ReadQuery, .StoredProcedureCall, org.eclipse.persistence.sessions.DatabaseRecord, .Session

Concrete JPA query class. The JPA query wraps a DatabaseQuery which is executed.

Field Summary

Modifier and TypeField and Description
protected DatabaseQuery
databaseQuery

Wrapped native query.

protected EntityManagerImpl
protected int
protected boolean
isShared

Stores if the wrapped query is shared, and requires cloning before being changed.

protected LockModeType
protected int
protected Map<String, Parameter<?>>
protected Map<String, Object>
protected String
public static final int

Constructor Summary

AccessConstructor and Description
protected
QueryImpl(EntityManagerImpl entityManager)

Base constructor for EJBQueryImpl.

public
QueryImpl(DatabaseQuery query, EntityManagerImpl entityManager)

Create an EJBQueryImpl with a DatabaseQuery.

Method Summary

Modifier and TypeMethod and Description
protected static void
applyArguments(StoredProcedureCall call, DatabaseQuery query)

Define the query arguments based on the procedure call.

protected static DatabaseQuery
applyHints(Map<String, Object>
a list of hints to be applied to the query
hints
,
DatabaseQuery
the query to apply the hints to
query
,
ClassLoader classLoader, AbstractSession session)

Set implementation-specific hints.

protected void
cloneSharedQuery()

If the query was from the jpql parse cache it must be cloned before being modified.

public void
close()

This method should be called to close any left over open connection to the database (if there is one).

protected Object

Returns:

an object representing the given TemporalType.
convertTemporalType
(Object value, TemporalType type)

Convert the given object to the class represented by the given temporal type.

protected Object

Returns:

the results of the query execution
executeReadQuery
()

Execute a ReadQuery by assigning the stored parameter values and running it in the database

public int

Returns:

the number of entities updated or deleted
executeUpdate
()

Execute an update or delete statement.

protected Session
public DatabaseQuery
getDatabaseQuery()

Return the wrapped DatabaseQuery ensuring that if it isShared it is cloned before returning to prevent corruption of the query cache.

public DatabaseQuery
getDatabaseQueryInternal()

INTERNAL: Return the cached database query for this EJBQueryImpl.

protected RuntimeException
getDetailedException(DatabaseException e)

Given a DatabaseException, this method will determine if we should throw a different more specific exception like a lock timeout exception.

public JpaEntityManager
getEntityManager()

Return the entityManager this query is tied to.

public int
public FlushModeType
public Map<String, Object>
protected Map<String, Parameter<?>>
getInternalParameters()

Return the internal map of parameters.

public LockModeType

Returns:

lock mode
getLockMode
()

Get the current lock mode for the query.

public int
public int
public <T> Parameter<T>
getParameter(String name, Class<T> type)

public <T> Parameter<T>
getParameter(int position, Class<T> type)

public Parameter<?>
public Parameter<?>
getParameter(int position)

public static String
getParameterId(Parameter<T> param)

Return the identifier of this parameter.

public Set<Parameter<?>>
public <T> T
public Object

Returns:

parameter value
getParameterValue
(String name)

Return the value bound to the named parameter.

public Object

Returns:

parameter value
getParameterValue
(int position)

Return the value bound to the positional parameter.

public List<E>

Returns:

a list of the results
getResultList
()

Execute the query and return the query results as a List.

public Object

Returns:

the result
getSingleResult
()

Execute a SELECT query that returns a single untyped result.

public Set<String>
public boolean

Returns:

boolean indicating whether parameter has been bound
isBound
(Parameter<?>
parameter object
param
)

Return a boolean indicating whether a value has been bound to the parameter.

protected boolean
protected boolean
isValidActualParameter(Object value, Class<?> parameterType)

protected void
protected List<Object>
processParameters()

Internal method to add the parameters values to the query prior to execution.

protected void
propagateResultProperties()

Configure the firstResult, maxRows and lock mode in the EclipseLink ReadQuery.

protected void
setAsDataModifyQuery()

INTERNAL: Change the internal query to data modify query.

protected void
setAsSQLModifyQuery()

Internal method to change the wrapped query to a DataModifyQuery if necessary.

protected void
setAsSQLReadQuery()

Internal method to change the wrapped query to a DataReadQuery if necessary.

public void
setDatabaseQuery(DatabaseQuery query)

Replace the cached query with the given query.

public QueryImpl

Returns:

the same query instance
setFirstResult
(int
position of the first result, numbered from 0
startPosition
)

Set the position of the first result to retrieve.

protected void
setFirstResultInternal(int
position of the first result, numbered from 0.
startPosition
)

Set the position of the first result to retrieve.

public QueryImpl
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.

public QueryImpl
setLockMode(LockModeType lockMode)

Set the lock mode type to be used for the query execution.

public QueryImpl

Returns:

the same query instance
setMaxResults
(int maxResult)

Set the maximum number of results to retrieve.

public 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
the parameter name
name
,
Object
to bind
value
,
boolean
defines if index or named
isIndex
)

Bind an argument to a named or indexed parameter.

protected void
protected void
protected void
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public <T> T
unwrap(Class<T> cls)

Unwrap the query into the JPA implementation classes/interfaces or the underlying native EclipseLink query.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

databaseQueryback to summary
protected DatabaseQuery databaseQuery

Wrapped native query. The query may be isShared

entityManagerback to summary
protected EntityManagerImpl entityManager
firstResultIndexback to summary
protected int firstResultIndex
isSharedback to summary
protected boolean isShared

Stores if the wrapped query is shared, and requires cloning before being changed.

lockModeback to summary
protected LockModeType lockMode
maxResultsback to summary
protected int maxResults
parametersback to summary
protected Map<String, Parameter<?>> parameters
parameterValuesback to summary
protected Map<String, Object> parameterValues
queryNameback to summary
protected String queryName
UNDEFINEDback to summary
public static final int UNDEFINED

Constructor Detail

QueryImplback to summary
protected QueryImpl(EntityManagerImpl entityManager)

Base constructor for EJBQueryImpl. Initializes basic variables.

QueryImplback to summary
public QueryImpl(DatabaseQuery query, EntityManagerImpl entityManager)

Create an EJBQueryImpl with a DatabaseQuery.

Method Detail

applyArgumentsback to summary
protected static void applyArguments(StoredProcedureCall call, DatabaseQuery query)

Define the query arguments based on the procedure call.

applyHintsback to summary
protected static DatabaseQuery applyHints(Map<String, Object> hints, DatabaseQuery query, ClassLoader classLoader, AbstractSession session)

Set implementation-specific hints.

Parameters
hints:Map<String, Object>

a list of hints to be applied to the query

query:DatabaseQuery

the query to apply the hints to

cloneSharedQueryback to summary
protected void cloneSharedQuery()

If the query was from the jpql parse cache it must be cloned before being modified.

closeback to summary
public void close()

This method should be called to close any left over open connection to the database (if there is one).

convertTemporalTypeback to summary
protected Object convertTemporalType(Object value, TemporalType type)

Convert the given object to the class represented by the given temporal type.

Returns:Object

an object representing the given TemporalType.

executeReadQueryback to summary
protected Object executeReadQuery()

Execute a ReadQuery by assigning the stored parameter values and running it in the database

Returns:Object

the results of the query execution

executeUpdateback to summary
public int executeUpdate()

Execute an update or delete statement.

Returns:int

the number of entities updated or deleted

getActiveSessionback to summary
protected Session getActiveSession()
getDatabaseQueryback to summary
public DatabaseQuery getDatabaseQuery()

Return the wrapped DatabaseQuery ensuring that if it isShared it is cloned before returning to prevent corruption of the query cache.

See Also
getDatabaseQueryInternal()
getDatabaseQueryInternalback to summary
public DatabaseQuery 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.

getDetailedExceptionback to summary
protected RuntimeException getDetailedException(DatabaseException e)

Given a DatabaseException, this method will determine if we should throw a different more specific exception like a lock timeout exception.

getEntityManagerback to summary
public JpaEntityManager getEntityManager()

Return the entityManager this query is tied to.

getFirstResultback to summary
public int getFirstResult()
Since
Java Persistence API 2.0
See Also
jakarta.persistence.Query#getFirstResult()
getFlushModeback to summary
public FlushModeType getFlushMode()
Since
Java Persistence 2.0
See Also
Query#getFlushMode()
getHintsback to summary
public Map<String, Object> getHints()
Since
Java Persistence 2.0
See Also
Query#getHints()
getInternalParametersback to summary
protected Map<String, Parameter<?>> getInternalParameters()

Return the internal map of parameters.

getLockModeback to summary
public LockModeType getLockMode()

Get the current lock mode for the query.

Returns:LockModeType

lock mode

Exceptions
IllegalStateException:
if not a Java Persistence query language SELECT query
getMaxResultsback to summary
public int getMaxResults()
Since
Java Persistence API 2.0
See Also
jakarta.persistence.Query#getMaxResults()
getMaxResultsInternalback to summary
public int getMaxResultsInternal()
Since
Java Persistence API 2.0
See Also
jakarta.persistence.Query#getMaxResults()
getParameterback to summary
public <T> Parameter<T> getParameter(String name, Class<T> type)
Since
Java Persistence 2.0
See Also
Query#getParameter(String, Class)
getParameterback to summary
public <T> Parameter<T> getParameter(int position, Class<T> type)
Since
Java Persistence 2.0
See Also
Query#getParameter(int, Class)
getParameterback to summary
public Parameter<?> getParameter(String name)
Since
Java Persistence 2.0
See Also
Query#getParameter(String, Class)
getParameterback to summary
public Parameter<?> getParameter(int position)
Since
Java Persistence 2.0
See Also
Query#getParameter(int, Class)
getParameterIdback to summary
public static String getParameterId(Parameter<T> param)

Return the identifier of this parameter. This will be the name if it is set, else it will be the position

getParametersback to summary
public Set<Parameter<?>> getParameters()
Since
Java Persistence 2.0
See Also
Query#getParameters()
getParameterValueback to summary
public <T> T getParameterValue(Parameter<T> param)
Since
Java Persistence 2.0
See Also
Query#getParameterValue(Parameter)
getParameterValueback to summary
public Object getParameterValue(String name)

Return the value bound to the named parameter.

Returns:Object

parameter value

Exceptions
IllegalStateException:
if the parameter has not been been bound
getParameterValueback to summary
public Object getParameterValue(int position)

Return the value bound to the positional parameter.

Returns:Object

parameter value

Exceptions
IllegalStateException:
if the parameter has not been been bound
getResultListback to summary
public List<E> getResultList()

Execute the query and return the query results as a List.

Returns:List<E>

a list of the results

getSingleResultback to summary
public Object getSingleResult()

Execute a SELECT query that returns a single untyped result.

Returns:Object

the result

Exceptions
NoResultException:
if there is no result
NonUniqueResultException:
if more than one result
IllegalStateException:
if called for a Java Persistence query language UPDATE or DELETE statement
QueryTimeoutException:
if the query execution exceeds the query timeout value set and only the statement is rolled back
TransactionRequiredException:
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 transaction
PessimisticLockException:
if pessimistic locking fails and the transaction is rolled back
LockTimeoutException:
if pessimistic locking fails and only the statement is rolled back
PersistenceException:
if the query execution exceeds the query timeout value set and the transaction is rolled back
getSupportedHintsback to summary
public Set<String> getSupportedHints()
Since
Java Persistence 2.0
isBoundback to summary
public boolean isBound(Parameter<?> param)

Return a boolean indicating whether a value has been bound to the parameter.

Parameters
param:Parameter<?>

parameter object

Returns:boolean

boolean indicating whether parameter has been bound

isFlushModeAUTOback to summary
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."

isValidActualParameterback to summary
protected boolean isValidActualParameter(Object value, Class<?> parameterType)
performPreQueryFlushback to summary
protected void performPreQueryFlush()
processParametersback to summary
protected List<Object> 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.

propagateResultPropertiesback to summary
protected void propagateResultProperties()

Configure the firstResult, maxRows and lock mode in the EclipseLink ReadQuery.

setAsDataModifyQueryback to summary
protected void setAsDataModifyQuery()

INTERNAL: Change the internal query to data modify query.

setAsSQLModifyQueryback to summary
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.

setAsSQLReadQueryback to summary
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.

setDatabaseQueryback to summary
public void setDatabaseQuery(DatabaseQuery query)

Replace the cached query with the given query.

setFirstResultback to summary
public QueryImpl setFirstResult(int startPosition)

Set the position of the first result to retrieve.

Parameters
startPosition:int

position of the first result, numbered from 0

Returns:QueryImpl

the same query instance

setFirstResultInternalback to summary
protected void setFirstResultInternal(int startPosition)

Set the position of the first result to retrieve.

Parameters
startPosition:int

position of the first result, numbered from 0.

setFlushModeback to summary
public QueryImpl setFlushMode(FlushModeType flushMode)

Set the flush mode type to be used for the query execution.

setHintInternalback to summary
protected void setHintInternal(String hintName, Object value)

Set an implementation-specific hint. If the hint name is not recognized, it is silently ignored.

Exceptions
IllegalArgumentException:
if the second argument is not valid for the implementation.
setLockModeback to summary
public QueryImpl setLockMode(LockModeType lockMode)

Set the lock mode type to be used for the query execution.

Exceptions
IllegalStateException:
if not a Java Persistence query language SELECT query
setMaxResultsback to summary
public QueryImpl setMaxResults(int maxResult)

Set the maximum number of results to retrieve.

Returns:QueryImpl

the same query instance

setMaxResultsInternalback to summary
public void setMaxResultsInternal(int maxResult)

Set the maximum number of results to retrieve.

setParameterInternalback to summary
protected void setParameterInternal(int position, Object value)

Bind an argument to a positional parameter.

setParameterInternalback to summary
protected void setParameterInternal(String name, Object value, boolean isIndex)

Bind an argument to a named or indexed parameter.

Parameters
name:String

the parameter name

value:Object

to bind

isIndex:boolean

defines if index or named

setRollbackOnlyback to summary
protected void setRollbackOnly()
throwNonUniqueResultExceptionback to summary
protected void throwNonUniqueResultException(String message)
throwNoResultExceptionback to summary
protected void throwNoResultException(String message)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
unwrapback to summary
public <T> T unwrap(Class<T> cls)

Unwrap the query into the JPA implementation classes/interfaces or the underlying native EclipseLink query.

Since
Java Persistence 2.0
See Also
Query#unwrap(Class)