Module org.eclipse.persistence.jpa
Class StoredProcedureQueryImpl
java.lang.Object
org.eclipse.persistence.internal.jpa.QueryImpl
org.eclipse.persistence.internal.jpa.StoredProcedureQueryImpl
- All Implemented Interfaces:
Query
,StoredProcedureQuery
Concrete JPA query class. The JPA query wraps a StoredProcesureQuery which
is executed.
-
Field Summary
Modifier and TypeFieldDescriptionprotected DatabaseCall
protected int
protected Statement
protected boolean
protected boolean
protected int
Fields inherited from class org.eclipse.persistence.internal.jpa.QueryImpl
databaseQuery, entityManager, firstResultIndex, isShared, lockMode, maxResults, parameters, parameterValues, queryName, UNDEFINED
-
Constructor Summary
ModifierConstructorDescriptionStoredProcedureQueryImpl
(String name, EntityManagerImpl entityManager) Create an StoredProcedureQueryImpl with a query name.protected
StoredProcedureQueryImpl
(EntityManagerImpl entityManager) Base constructor for StoredProcedureQueryImpl.StoredProcedureQueryImpl
(DatabaseQuery query, EntityManagerImpl entityManager) Create an StoredProcedureQueryImpl with a DatabaseQuery. -
Method Summary
Modifier and TypeMethodDescriptionprotected List
buildResultRecords
(ResultSet resultSet) Build the given result set into a list objects.static DatabaseQuery
buildResultSetMappingNameQuery
(List<String> resultSetMappingNames, StoredProcedureCall call) Build a ResultSetMappingQuery from a sql result set mapping name and a stored procedure call.static DatabaseQuery
buildResultSetMappingNameQuery
(List<String> resultSetMappingNames, StoredProcedureCall call, Map<String, Object> hints, ClassLoader classLoader, AbstractSession session) Build a ResultSetMappingQuery from a sql result set mapping name and a stored procedure call.static DatabaseQuery
buildResultSetMappingQuery
(List<SQLResultSetMapping> resultSetMappings, StoredProcedureCall call) Build a ResultSetMappingQuery from the sql result set mappings given a stored procedure call.static DatabaseQuery
buildResultSetMappingQuery
(List<SQLResultSetMapping> resultSetMappings, StoredProcedureCall call, Map<String, Object> hints, ClassLoader classLoader, AbstractSession session) Build a ResultSetMappingQuery from the sql result set mappings given a stored procedure call.static DatabaseQuery
buildStoredProcedureQuery
(Class<?> resultClass, StoredProcedureCall call, Map<String, Object> hints, ClassLoader classLoader, AbstractSession session) Build a ReadAllQuery from a class and stored procedure call.static DatabaseQuery
buildStoredProcedureQuery
(String sqlResultSetMappingName, StoredProcedureCall call, Map<String, Object> hints, ClassLoader classLoader, AbstractSession session) Build a ResultSetMappingQuery from a sql result set mapping name and a stored procedure call.static DatabaseQuery
buildStoredProcedureQuery
(StoredProcedureCall call, Map<String, Object> hints, ClassLoader classLoader, AbstractSession session) Build a DataReadQuery with the stored procedure call given.void
close()
Call this method to close any open connections to the database.boolean
execute()
Returns true if the first result corresponds to a result set, and false if it is an update count or if there are no results other than through INOUT and OUT parameters, if any.int
Execute an update or delete statement (from a stored procedure query).void
finalize()
Finalize method in case the query is not closed.protected StoredProcedureCall
getCall()
Return the stored procedure call associated with this query.Return the internal map of parameters.getOutputParameterValue
(int position) Used to retrieve the values passed back from the procedure through INOUT and OUT parameters.getOutputParameterValue
(String parameterName) Used to retrieve the values passed back from the procedure through INOUT and OUT parameters.Execute the query and return the query results as a List.protected ResultSetMappingQuery
Return the ResultSetMappingQuery for this stored procedure query.Execute the query and return the single query result.int
Returns the update count or -1 if there is no pending result or if the next result is not an update count.boolean
Returns true if the next result corresponds to a result set, and false if it is an update count or if there are no results other than through INOUT and OUT parameters, if any.protected boolean
Returns true if the execute statement for this query is 1) not null (i.e.registerStoredProcedureParameter
(int position, Class type, ParameterMode mode) Register a positional parameter.registerStoredProcedureParameter
(String parameterName, Class type, ParameterMode mode) Register a named parameter.setFirstResult
(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.Set a query property or 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.setParameter
(int position, Object value) Bind an argument to a positional parameter.setParameter
(int position, Calendar value, TemporalType temporalType) Bind an instance of java.util.Calendar to a positional parameter.setParameter
(int position, Date value, TemporalType temporalType) Bind an instance of java.util.Date to a positional parameter.setParameter
(Parameter<Calendar> param, Calendar value, TemporalType temporalType) Bind an instance of java.util.Calendar to a Parameter object.setParameter
(Parameter<Date> param, Date value, TemporalType temporalType) Bind an instance of java.util.Date to a Parameter object.setParameter
(Parameter<T> param, T value) Bind the value of a Parameter object.setParameter
(String name, Object value) Bind an argument to a named parameter.setParameter
(String name, Calendar value, TemporalType temporalType) Bind an instance of java.util.Calendar to a named parameter.setParameter
(String name, Date value, TemporalType temporalType) Bind an instance of java.util.Date to a named parameter.protected void
setParameterInternal
(String name, Object value, boolean isIndex) Bind an argument to a named or indexed parameter.Methods inherited from class org.eclipse.persistence.internal.jpa.QueryImpl
applyArguments, applyHints, cloneSharedQuery, convertTemporalType, executeReadQuery, getActiveSession, getDatabaseQuery, getDatabaseQueryInternal, getDetailedException, getEntityManager, getFirstResult, getFlushMode, getHints, getLockMode, getMaxResults, getMaxResultsInternal, getParameter, getParameter, getParameter, getParameter, getParameterId, getParameters, getParameterValue, getParameterValue, getParameterValue, getSupportedHints, isBound, isFlushModeAUTO, isValidActualParameter, performPreQueryFlush, processParameters, propagateResultProperties, setAsDataModifyQuery, setAsSQLModifyQuery, setAsSQLReadQuery, setDatabaseQuery, setFirstResultInternal, setHintInternal, setMaxResultsInternal, setParameterInternal, setRollbackOnly, throwNonUniqueResultException, throwNoResultException, toString, unwrap
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface jakarta.persistence.Query
getFirstResult, getFlushMode, getHints, getLockMode, getMaxResults, getParameter, getParameter, getParameter, getParameter, getParameters, getParameterValue, getParameterValue, getParameterValue, getResultStream, isBound, unwrap
-
Field Details
-
hasMoreResults
protected boolean hasMoreResults -
executeCall
-
executeStatement
-
executeResultSetIndex
protected int executeResultSetIndex -
outputCursorIndex
protected int outputCursorIndex -
isOutputCursorResultSet
protected boolean isOutputCursorResultSet
-
-
Constructor Details
-
StoredProcedureQueryImpl
Base constructor for StoredProcedureQueryImpl. Initializes basic variables. -
StoredProcedureQueryImpl
Create an StoredProcedureQueryImpl with a DatabaseQuery. -
StoredProcedureQueryImpl
Create an StoredProcedureQueryImpl with a query name.
-
-
Method Details
-
buildResultRecords
Build the given result set into a list objects. Assumes there is an execute call available and therefore should not be called unless an execute statement was issued by the user. -
buildResultSetMappingNameQuery
public static DatabaseQuery buildResultSetMappingNameQuery(List<String> resultSetMappingNames, StoredProcedureCall call) Build a ResultSetMappingQuery from a sql result set mapping name and a stored procedure call. This is called from a named stored procedure that employs result set mapping name(s) which should be available from the session. -
buildResultSetMappingNameQuery
public static DatabaseQuery buildResultSetMappingNameQuery(List<String> resultSetMappingNames, StoredProcedureCall call, Map<String, Object> hints, ClassLoader classLoader, AbstractSession session) Build a ResultSetMappingQuery from a sql result set mapping name and a stored procedure call. This is called from a named stored procedure that employs result set mapping name(s) which should be available from the session. -
buildResultSetMappingQuery
public static DatabaseQuery buildResultSetMappingQuery(List<SQLResultSetMapping> resultSetMappings, StoredProcedureCall call) Build a ResultSetMappingQuery from the sql result set mappings given a stored procedure call. This is called from a named stored procedure query that employs result class name(s). The resultSetMappings are build from these class name(s) and are not available from the session. -
buildResultSetMappingQuery
public static DatabaseQuery buildResultSetMappingQuery(List<SQLResultSetMapping> resultSetMappings, StoredProcedureCall call, Map<String, Object> hints, ClassLoader classLoader, AbstractSession session) Build a ResultSetMappingQuery from the sql result set mappings given a stored procedure call. This is called from a named stored procedure query that employs result class name(s). The resultSetMappings are build from these class name(s) and are not available from the session. -
buildStoredProcedureQuery
public static DatabaseQuery buildStoredProcedureQuery(Class<?> resultClass, StoredProcedureCall call, Map<String, Object> hints, ClassLoader classLoader, AbstractSession session) Build a ReadAllQuery from a class and stored procedure call. -
buildStoredProcedureQuery
public static DatabaseQuery buildStoredProcedureQuery(StoredProcedureCall call, Map<String, Object> hints, ClassLoader classLoader, AbstractSession session) Build a DataReadQuery with the stored procedure call given. -
buildStoredProcedureQuery
public static DatabaseQuery buildStoredProcedureQuery(String sqlResultSetMappingName, StoredProcedureCall call, Map<String, Object> hints, ClassLoader classLoader, AbstractSession session) Build a ResultSetMappingQuery from a sql result set mapping name and a stored procedure call. -
close
public void close()Call this method to close any open connections to the database. -
execute
public boolean execute()Returns true if the first result corresponds to a result set, and false if it is an update count or if there are no results other than through INOUT and OUT parameters, if any.- Specified by:
execute
in interfaceStoredProcedureQuery
- Returns:
- true if first result corresponds to result set
- Throws:
QueryTimeoutException
- if the query execution exceeds the query timeout value set and only the statement is rolled backPersistenceException
- if the query execution exceeds the query timeout value set and the transaction is rolled back
-
executeUpdate
public int executeUpdate()Execute an update or delete statement (from a stored procedure query).- Specified by:
executeUpdate
in interfaceQuery
- Specified by:
executeUpdate
in interfaceStoredProcedureQuery
- Overrides:
executeUpdate
in classQueryImpl
- Returns:
- the number of entities updated or deleted
-
finalize
public void finalize()Finalize method in case the query is not closed. -
getCall
Return the stored procedure call associated with this query. -
getInternalParameters
Return the internal map of parameters.- Overrides:
getInternalParameters
in classQueryImpl
-
getOutputParameterValue
Used to retrieve the values passed back from the procedure through INOUT and OUT parameters. For portability, all results corresponding to result sets and update counts must be retrieved before the values of output parameters.- Specified by:
getOutputParameterValue
in interfaceStoredProcedureQuery
- Parameters:
position
- parameter position- Returns:
- the result that is passed back through the parameter
- Throws:
IllegalArgumentException
- if the position does not correspond to a parameter of the query or is not an INOUT or OUT parameter
-
getOutputParameterValue
Used to retrieve the values passed back from the procedure through INOUT and OUT parameters. For portability, all results corresponding to result sets and update counts must be retrieved before the values of output parameters.- Specified by:
getOutputParameterValue
in interfaceStoredProcedureQuery
- Parameters:
parameterName
- name of the parameter as registered or specified in metadata- Returns:
- the result that is passed back through the parameter
- Throws:
IllegalArgumentException
- if the parameter name does not correspond to a parameter of the query or is not an INOUT or OUT parameter
-
getResultList
Execute the query and return the query results as a List.- Specified by:
getResultList
in interfaceQuery
- Specified by:
getResultList
in interfaceStoredProcedureQuery
- Overrides:
getResultList
in classQueryImpl
- Returns:
- a list of the results
-
getResultSetMappingQuery
Return the ResultSetMappingQuery for this stored procedure query. NOTE: Methods assumes associated database query is a ResultSetMappingQuery. -
getSingleResult
Execute the query and return the single query result.- Specified by:
getSingleResult
in interfaceQuery
- Specified by:
getSingleResult
in interfaceStoredProcedureQuery
- Overrides:
getSingleResult
in classQueryImpl
- Returns:
- a single result object.
-
getUpdateCount
public int getUpdateCount()Returns the update count or -1 if there is no pending result or if the next result is not an update count.- Specified by:
getUpdateCount
in interfaceStoredProcedureQuery
- Returns:
- update count or -1 if there is no pending result or if the next result is not an update count
- Throws:
QueryTimeoutException
- if the query execution exceeds the query timeout value set and only the statement is rolled backPersistenceException
- if the query execution exceeds the query timeout value set and the transaction is rolled back
-
hasMoreResults
public boolean hasMoreResults()Returns true if the next result corresponds to a result set, and false if it is an update count or if there are no results other than through INOUT and OUT parameters, if any.- Specified by:
hasMoreResults
in interfaceStoredProcedureQuery
- Returns:
- true if next result corresponds to result set
- Throws:
QueryTimeoutException
- if the query execution exceeds the query timeout value set and only the statement is rolled backPersistenceException
- if the query execution exceeds the query timeout value set and the transaction is rolled back
-
isValidCallableStatement
protected boolean isValidCallableStatement()Returns true if the execute statement for this query is 1) not null (i.e. query has been executed and 2) is an instance of callable statement, meaning there are out parameters associated with it. -
registerStoredProcedureParameter
public StoredProcedureQuery registerStoredProcedureParameter(int position, Class type, ParameterMode mode) Register a positional parameter. All positional parameters must be registered.- Specified by:
registerStoredProcedureParameter
in interfaceStoredProcedureQuery
- Parameters:
position
- parameter positiontype
- type of the parametermode
- parameter mode- Returns:
- the same query instance
-
registerStoredProcedureParameter
public StoredProcedureQuery registerStoredProcedureParameter(String parameterName, Class type, ParameterMode mode) Register a named parameter. When using parameter names, all parameters must be registered in the order in which they occur in the parameter list of the stored procedure.- Specified by:
registerStoredProcedureParameter
in interfaceStoredProcedureQuery
- Parameters:
parameterName
- name of the parameter as registered or specified in metadatatype
- type of the parametermode
- parameter mode- Returns:
- the same query instance
-
setFirstResult
Set the position of the first result to retrieve.- Specified by:
setFirstResult
in interfaceQuery
- Overrides:
setFirstResult
in classQueryImpl
- Parameters:
startPosition
- position of the first result, numbered from 0- Returns:
- the same query instance
-
setFlushMode
Set the flush mode type to be used for the query execution. The flush mode type applies to the query regardless of the flush mode type in use for the entity manager.- Specified by:
setFlushMode
in interfaceQuery
- Specified by:
setFlushMode
in interfaceStoredProcedureQuery
- Overrides:
setFlushMode
in classQueryImpl
- Parameters:
flushMode
- flush mode- Returns:
- the same query instance
-
setHint
Set a query property or hint. The hints elements may be used to specify query properties and hints. Properties defined by this specification must be observed by the provider. Vendor-specific hints that are not recognized by a provider must be silently ignored. Portable applications should not rely on the standard timeout hint. Depending on the database in use, this hint may or may not be observed.- Specified by:
setHint
in interfaceQuery
- Specified by:
setHint
in interfaceStoredProcedureQuery
- Parameters:
hintName
- name of the property or hintvalue
- value for the property or hint- Returns:
- the same query instance
- 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.- Specified by:
setLockMode
in interfaceQuery
- Overrides:
setLockMode
in classQueryImpl
- Throws:
IllegalStateException
- if not a Java Persistence query language SELECT query
-
setMaxResults
Set the maximum number of results to retrieve.- Specified by:
setMaxResults
in interfaceQuery
- Overrides:
setMaxResults
in classQueryImpl
- Returns:
- the same query instance
-
setParameter
Bind an instance of java.util.Calendar to a positional parameter.- Specified by:
setParameter
in interfaceQuery
- Specified by:
setParameter
in interfaceStoredProcedureQuery
- Returns:
- the same query instance
- Throws:
IllegalArgumentException
- if position does not correspond to a positional parameter of the query or if the value argument is of incorrect type
-
setParameter
Bind an instance of java.util.Date to a positional parameter.- Specified by:
setParameter
in interfaceQuery
- Specified by:
setParameter
in interfaceStoredProcedureQuery
- Returns:
- the same query instance
- Throws:
IllegalArgumentException
- if position does not correspond to a positional parameter of the query or if the value argument is of incorrect type
-
setParameter
Bind an argument to a positional parameter.- Specified by:
setParameter
in interfaceQuery
- Specified by:
setParameter
in interfaceStoredProcedureQuery
- Returns:
- the same query instance
- Throws:
IllegalArgumentException
- if position does not correspond to a positional parameter of the query or if the argument is of incorrect type
-
setParameter
public StoredProcedureQuery setParameter(Parameter<Calendar> param, Calendar value, TemporalType temporalType) Bind an instance of java.util.Calendar to a Parameter object.- Specified by:
setParameter
in interfaceQuery
- Specified by:
setParameter
in interfaceStoredProcedureQuery
- Returns:
- the same query instance
- Throws:
IllegalArgumentException
- if the parameter does not correspond to a parameter of the query
-
setParameter
public StoredProcedureQuery setParameter(Parameter<Date> param, Date value, TemporalType temporalType) Bind an instance of java.util.Date to a Parameter object.- Specified by:
setParameter
in interfaceQuery
- Specified by:
setParameter
in interfaceStoredProcedureQuery
- Returns:
- the same query instance
- Throws:
IllegalArgumentException
- if the parameter does not correspond to a parameter of the query
-
setParameter
Bind the value of a Parameter object.- Specified by:
setParameter
in interfaceQuery
- Specified by:
setParameter
in interfaceStoredProcedureQuery
- Returns:
- the same query instance
- Throws:
IllegalArgumentException
- if the parameter does not correspond to a parameter of the query
-
setParameter
Bind an instance of java.util.Calendar to a named parameter.- Specified by:
setParameter
in interfaceQuery
- Specified by:
setParameter
in interfaceStoredProcedureQuery
- Returns:
- the same query instance
- Throws:
IllegalArgumentException
- if the parameter name does not correspond to a parameter of the query or if the value argument is of incorrect type
-
setParameter
Bind an instance of java.util.Date to a named parameter.- Specified by:
setParameter
in interfaceQuery
- Specified by:
setParameter
in interfaceStoredProcedureQuery
- Returns:
- the same query instance
- Throws:
IllegalArgumentException
- if the parameter name does not correspond to a parameter of the query or if the value argument is of incorrect type
-
setParameter
Bind an argument to a named parameter.- Specified by:
setParameter
in interfaceQuery
- Specified by:
setParameter
in interfaceStoredProcedureQuery
- Returns:
- the same query instance
- Throws:
IllegalArgumentException
- if the parameter name does not correspond to a parameter of the query or if the argument is of incorrect type
-
setParameterInternal
Bind an argument to a named or indexed parameter.- Overrides:
setParameterInternal
in classQueryImpl
- Parameters:
name
- the parameter namevalue
- to bindisIndex
- defines if index or named
-