Query
public interface StoredProcedureQuery extends Query
Stored procedure query execution may be controlled in accordance with the following:
setParameter
methods are used to set the values of
all required IN
and INOUT
parameters.
It is not required to set the values of stored procedure parameters
for which default values have been defined by the stored procedure.getResultList
and getSingleResult
are
called on a StoredProcedureQuery
object, the provider
will call execute
on an unexecuted stored procedure
query before processing getResultList
or
getSingleResult
.executeUpdate
is called on a
StoredProcedureQuery
object, the provider will call
execute
on an unexecuted stored procedure query
followed by getUpdateCount
. The results of
executeUpdate
will be those of getUpdateCount
.execute
method supports both the simple case where
scalar results are passed back only via INOUT
and
OUT
parameters as well as the most general case
(multiple result sets and/or update counts, possibly also in
combination with output parameter values).execute
method returns true if the first result is a
result set, and false if it is an update count or there are no results
other than through INOUT
and OUT
parameters,
if any.execute
method returns true, the pending result set
can be obtained by calling getResultList
or
getSingleResult
.hasMoreResults
method can then be used to test
for further results.execute
or hasMoreResults
returns false,
the getUpdateCount
method can be called to obtain the
pending result if it is an update count. The getUpdateCount
method will return either the update count (zero or greater) or -1
if there is no update count (i.e., either the next result is a result set
or there is no next update count).INOUT
or OUT
parameters are extracted.getResultList
and
getUpdateCount
have been exhausted, results returned through
INOUT
and OUT
parameters can be retrieved.getOutputParameterValue
methods are used to retrieve
the values passed back from the procedure through INOUT
and OUT
parameters.REF_CURSOR
parameters for result sets the
update counts should be exhausted before calling getResultList
to retrieve the result set. Alternatively, the REF_CURSOR
result set can be retrieved through getOutputParameterValue
.
Result set mappings will be applied to results corresponding to
REF_CURSOR
parameters in the order the REF_CURSOR
parameters were registered with the query.INOUT
and OUT
parameters, execute
can be followed immediately by calls to
getOutputParameterValue
.Modifier and Type | Method | Description |
---|---|---|
boolean |
execute() |
Return 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 |
executeUpdate() |
Return the update count of -1 if there is no pending result or
if the first result is not an update count.
|
java.lang.Object |
getOutputParameterValue(int position) |
Retrieve a value passed back from the procedure
through an INOUT or OUT parameter.
|
java.lang.Object |
getOutputParameterValue(java.lang.String parameterName) |
Retrieve a value passed back from the procedure
through an INOUT or OUT parameter.
|
java.util.List |
getResultList() |
Retrieve the list of results from the next result set.
|
java.lang.Object |
getSingleResult() |
Retrieve a single result from the next result set.
|
int |
getUpdateCount() |
Return the update count or -1 if there is no pending result
or if the next result is not an update count.
|
boolean |
hasMoreResults() |
Return 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.
|
StoredProcedureQuery |
registerStoredProcedureParameter(int position,
java.lang.Class type,
ParameterMode mode) |
Register a positional parameter.
|
StoredProcedureQuery |
registerStoredProcedureParameter(java.lang.String parameterName,
java.lang.Class type,
ParameterMode mode) |
Register a named parameter.
|
StoredProcedureQuery |
setFlushMode(FlushModeType flushMode) |
Set the flush mode type to be used for the query execution.
|
StoredProcedureQuery |
setHint(java.lang.String hintName,
java.lang.Object value) |
Set a query property or hint.
|
StoredProcedureQuery |
setParameter(int position,
java.lang.Object value) |
Bind an argument value to a positional parameter.
|
StoredProcedureQuery |
setParameter(int position,
java.util.Calendar value,
TemporalType temporalType) |
Bind an instance of
java.util.Calendar to a positional
parameter. |
StoredProcedureQuery |
setParameter(int position,
java.util.Date value,
TemporalType temporalType) |
Bind an instance of
java.util.Date to a positional parameter. |
StoredProcedureQuery |
setParameter(java.lang.String name,
java.lang.Object value) |
Bind an argument value to a named parameter.
|
StoredProcedureQuery |
setParameter(java.lang.String name,
java.util.Calendar value,
TemporalType temporalType) |
Bind an instance of
java.util.Calendar to a named parameter. |
StoredProcedureQuery |
setParameter(java.lang.String name,
java.util.Date value,
TemporalType temporalType) |
Bind an instance of
java.util.Date to a named parameter. |
StoredProcedureQuery |
setParameter(Parameter<java.util.Calendar> param,
java.util.Calendar value,
TemporalType temporalType) |
Bind an instance of
java.util.Calendar to a Parameter object. |
StoredProcedureQuery |
setParameter(Parameter<java.util.Date> param,
java.util.Date value,
TemporalType temporalType) |
Bind an instance of
java.util.Date to a Parameter object. |
<T> StoredProcedureQuery |
setParameter(Parameter<T> param,
T value) |
Bind the value of a
Parameter object. |
getFirstResult, getFlushMode, getHints, getLockMode, getMaxResults, getParameter, getParameter, getParameter, getParameter, getParameters, getParameterValue, getParameterValue, getParameterValue, getResultStream, isBound, setFirstResult, setLockMode, setMaxResults, unwrap
StoredProcedureQuery setHint(java.lang.String hintName, java.lang.Object value)
<T> StoredProcedureQuery setParameter(Parameter<T> param, T value)
Parameter
object.setParameter
in interface Query
param
- parameter objectvalue
- parameter valuejava.lang.IllegalArgumentException
- if the parameter does not
correspond to a parameter of the queryStoredProcedureQuery setParameter(Parameter<java.util.Calendar> param, java.util.Calendar value, TemporalType temporalType)
java.util.Calendar
to a Parameter
object.setParameter
in interface Query
param
- parameter objectvalue
- parameter valuetemporalType
- temporal typejava.lang.IllegalArgumentException
- if the parameter does not
correspond to a parameter of the queryStoredProcedureQuery setParameter(Parameter<java.util.Date> param, java.util.Date value, TemporalType temporalType)
java.util.Date
to a Parameter
object.setParameter
in interface Query
param
- parameter objectvalue
- parameter valuetemporalType
- temporal typejava.lang.IllegalArgumentException
- if the parameter does not
correspond to a parameter of the queryStoredProcedureQuery setParameter(java.lang.String name, java.lang.Object value)
setParameter
in interface Query
name
- parameter namevalue
- parameter valuejava.lang.IllegalArgumentException
- if the parameter name does
not correspond to a parameter of the query or if the
argument is of incorrect typeStoredProcedureQuery setParameter(java.lang.String name, java.util.Calendar value, TemporalType temporalType)
java.util.Calendar
to a named parameter.setParameter
in interface Query
name
- parameter namevalue
- parameter valuetemporalType
- temporal typejava.lang.IllegalArgumentException
- if the parameter name does
not correspond to a parameter of the query or if the
value argument is of incorrect typeStoredProcedureQuery setParameter(java.lang.String name, java.util.Date value, TemporalType temporalType)
java.util.Date
to a named parameter.setParameter
in interface Query
name
- parameter namevalue
- parameter valuetemporalType
- temporal typejava.lang.IllegalArgumentException
- if the parameter name does
not correspond to a parameter of the query or if the
value argument is of incorrect typeStoredProcedureQuery setParameter(int position, java.lang.Object value)
setParameter
in interface Query
position
- positionvalue
- parameter valuejava.lang.IllegalArgumentException
- if position does not
correspond to a positional parameter of the query
or if the argument is of incorrect typeStoredProcedureQuery setParameter(int position, java.util.Calendar value, TemporalType temporalType)
java.util.Calendar
to a positional
parameter.setParameter
in interface Query
position
- positionvalue
- parameter valuetemporalType
- temporal typejava.lang.IllegalArgumentException
- if position does not
correspond to a positional parameter of the query or
if the value argument is of incorrect typeStoredProcedureQuery setParameter(int position, java.util.Date value, TemporalType temporalType)
java.util.Date
to a positional parameter.setParameter
in interface Query
position
- positionvalue
- parameter valuetemporalType
- temporal typejava.lang.IllegalArgumentException
- if position does not
correspond to a positional parameter of the query or
if the value argument is of incorrect typeStoredProcedureQuery setFlushMode(FlushModeType flushMode)
setFlushMode
in interface Query
flushMode
- flush modeStoredProcedureQuery registerStoredProcedureParameter(int position, java.lang.Class type, ParameterMode mode)
position
- parameter positiontype
- type of the parametermode
- parameter modeStoredProcedureQuery registerStoredProcedureParameter(java.lang.String parameterName, java.lang.Class type, ParameterMode mode)
parameterName
- name of the parameter as registered or
specified in metadatatype
- type of the parametermode
- parameter modejava.lang.Object getOutputParameterValue(int position)
position
- parameter positionjava.lang.IllegalArgumentException
- if the position does
not correspond to a parameter of the query or is
not an INOUT or OUT parameterjava.lang.Object getOutputParameterValue(java.lang.String parameterName)
parameterName
- name of the parameter as registered or
specified in metadatajava.lang.IllegalArgumentException
- if the parameter name does
not correspond to a parameter of the query or is
not an INOUT or OUT parameterboolean execute()
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 backint executeUpdate()
execute
on the query if needed.executeUpdate
in interface Query
TransactionRequiredException
- if there is
no transaction or the persistence context has not
been joined to the transactionQueryTimeoutException
- if the statement 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 backjava.util.List getResultList()
execute
on the query
if needed.
A REF_CURSOR
result set, if any, will be retrieved
in the order the REF_CURSOR
parameter was
registered with the query.getResultList
in interface Query
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 backjava.lang.Object getSingleResult()
execute
on the query
if needed.
A REF_CURSOR
result set, if any, will be retrieved
in the order the REF_CURSOR
parameter was
registered with the query.getSingleResult
in interface Query
NoResultException
- if there is no result in the next
result setNonUniqueResultException
- if more than one resultQueryTimeoutException
- 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 backboolean hasMoreResults()
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 backint getUpdateCount()
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 backCopyright © 2018. All rights reserved.