Interface ProcedureCall
-
- All Superinterfaces:
AutoCloseable
,CommonQueryContract
,NameableQuery
,Query
,StoredProcedureQuery
,SynchronizeableQuery
- All Known Subinterfaces:
ProcedureCallImplementor<R>
- All Known Implementing Classes:
ProcedureCallImpl
public interface ProcedureCall extends CommonQueryContract, SynchronizeableQuery, StoredProcedureQuery, NameableQuery, AutoCloseable
Defines support for executing database stored procedures and functions.Note that here we use the terms "procedure" and "function" as follows:
- procedure is a named database executable we expect to call via :
{call procedureName(...)}
- function is a named database executable we expect to call via :
{? = call functionName(...)}
Unless explicitly specified, the ProcedureCall is assumed to follow the procedure call syntax. To explicitly specify that this should be a function call, use
markAsFunctionCall(int)
. JPA users could either:- use
storedProcedureQuery.unwrap( ProcedureCall.class
.markAsFunctionCall() - set the
FUNCTION_RETURN_TYPE_HINT
hint (avoids casting to Hibernate-specific classes)
When using function-call syntax:
- parameters must be registered by position (not name)
- The first parameter is considered to be the function return (the `?` before the call)
- the first parameter must have mode of OUT, INOUT or REF_CURSOR; IN is invalid
In some cases, based on the Dialect, we will have other validations and assumptions as well. For example, on PGSQL, whenever we see a REF_CURSOR mode parameter, we know that:
-
this will be a function call (so we call
markAsFunctionCall(int)
implicitly) because that is the only way PGSQL supports returning REF_CURSOR results. - there can be only one REF_CURSOR mode parameter
-
-
Field Summary
Fields Modifier and Type Field Description static String
FUNCTION_RETURN_TYPE_HINT
The hint key (for use with JPA's "hint system") indicating the function's return JDBC type code (aka,Types
code)
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description ProcedureCall
addSynchronizedEntityClass(Class entityClass)
Add all query spaces associated with the entity with the given type.ProcedureCall
addSynchronizedEntityName(String entityName)
Add all query spaces associated with the entity with the given names.ProcedureCall
addSynchronizedQuerySpace(String querySpace)
Add a query space.default void
close()
Release the underlying JDBCCallableStatement
ProcedureOutputs
getOutputs()
Retrieves access to outputs of this procedure call.ProcedureParameter
getParameterRegistration(int position)
Retrieve a previously registered parameter memento by the position under which it was registered.ProcedureParameter
getParameterRegistration(String name)
Retrieve a previously registered parameter memento by the name under which it was registered.String
getProcedureName()
Get the name of the stored procedure (or function) to be called.List<ProcedureParameter>
getRegisteredParameters()
Retrieve all registered parameters.boolean
isFunctionCall()
Does thisProcedureCall
represent a call to a databaseFUNCTION
, as opposed to aPROCEDURE
?ProcedureCall
markAsFunctionCall(int sqlType)
Mark this ProcedureCall as representing a call to a database function, rather than a database procedure.ProcedureCall
markAsFunctionCall(Class<?> resultType)
Mark this ProcedureCall as representing a call to a database function, rather than a database procedure.ProcedureCall
markAsFunctionCall(BasicTypeReference<?> typeReference)
Mark this ProcedureCall as representing a call to a database function, rather than a database procedure.<T> ProcedureParameter<T>
registerParameter(int position, Class<T> type, ParameterMode mode)
Basic form for registering a positional parameter.<T> ProcedureParameter<T>
registerParameter(int position, BasicTypeReference<T> type, ParameterMode mode)
Basic form for registering a positional parameter.<T> ProcedureParameter<T>
registerParameter(String parameterName, Class<T> type, ParameterMode mode)
Basic form for registering a named parameter.<T> ProcedureParameter<T>
registerParameter(String parameterName, BasicTypeReference<T> type, ParameterMode mode)
Basic form for registering a named parameter.ProcedureCall
registerStoredProcedureParameter(int position, Class type, ParameterMode mode)
ProcedureCall
registerStoredProcedureParameter(int position, BasicTypeReference<?> type, ParameterMode mode)
LikeregisterStoredProcedureParameter(int, Class, ParameterMode)
but a basic type reference is given instead of a class for the parameter type.ProcedureCall
registerStoredProcedureParameter(String parameterName, Class type, ParameterMode mode)
ProcedureCall
registerStoredProcedureParameter(String parameterName, BasicTypeReference<?> type, ParameterMode mode)
LikeregisterStoredProcedureParameter(String, Class, ParameterMode)
but a basic type reference is given instead of a class for the parameter type.ProcedureCall
setFlushMode(FlushModeType flushMode)
Set theFlushMode
in to use for this query.ProcedureCall
setHint(String hintName, Object value)
Set a hint.ProcedureCall
setParameter(int position, Object value)
Bind the given argument to an ordinal query parameter.ProcedureCall
setParameter(int position, Calendar value, TemporalType temporalType)
ProcedureCall
setParameter(int position, Date value, TemporalType temporalType)
ProcedureCall
setParameter(Parameter<Calendar> param, Calendar value, TemporalType temporalType)
ProcedureCall
setParameter(Parameter<Date> param, Date value, TemporalType temporalType)
<T> ProcedureCall
setParameter(Parameter<T> param, T value)
ProcedureCall
setParameter(String name, Object value)
Bind the given argument to a named query parameter.ProcedureCall
setParameter(String name, Calendar value, TemporalType temporalType)
ProcedureCall
setParameter(String name, Date value, TemporalType temporalType)
NamedCallableQueryMemento
toMemento(String name)
Convert the query into the memento-
Methods inherited from interface org.hibernate.query.CommonQueryContract
getComment, getFlushMode, getHibernateFlushMode, getTimeout, setComment, setHibernateFlushMode, setParameter, setParameter, setParameter, setParameter, setParameter, setParameter, setParameter, setParameter, setParameter, setParameterList, setParameterList, setParameterList, setParameterList, setParameterList, setParameterList, setParameterList, setParameterList, setParameterList, setParameterList, setParameterList, setParameterList, setParameterList, setParameterList, setParameterList, setParameterList, setParameterList, setParameterList, setProperties, setProperties, setTimeout
-
Methods inherited from interface jakarta.persistence.Query
getFirstResult, getFlushMode, getHints, getLockMode, getMaxResults, getParameter, getParameter, getParameter, getParameter, getParameters, getParameterValue, getParameterValue, getParameterValue, getResultStream, isBound, setFirstResult, setLockMode, setMaxResults, unwrap
-
Methods inherited from interface jakarta.persistence.StoredProcedureQuery
execute, executeUpdate, getOutputParameterValue, getOutputParameterValue, getResultList, getSingleResult, getUpdateCount, hasMoreResults
-
Methods inherited from interface org.hibernate.query.SynchronizeableQuery
getSynchronizedQuerySpaces
-
-
-
-
Field Detail
-
FUNCTION_RETURN_TYPE_HINT
static final String FUNCTION_RETURN_TYPE_HINT
The hint key (for use with JPA's "hint system") indicating the function's return JDBC type code (aka,Types
code)- See Also:
- Constant Field Values
-
-
Method Detail
-
getProcedureName
String getProcedureName()
Get the name of the stored procedure (or function) to be called.- Returns:
- The procedure name.
-
isFunctionCall
boolean isFunctionCall()
Does thisProcedureCall
represent a call to a databaseFUNCTION
, as opposed to aPROCEDURE
?- Returns:
true
indicates that this ProcedureCall represents a function call;false
indicates a procedure call.- API Note:
- this will only report whether this
ProcedureCall
was marked as a function via call tomarkAsFunctionCall(int)
. In particular, it will not returntrue
when using JPA query hint.
-
markAsFunctionCall
ProcedureCall markAsFunctionCall(int sqlType)
Mark this ProcedureCall as representing a call to a database function, rather than a database procedure.- Parameters:
sqlType
- TheTypes
code for the function return- Returns:
this
, for method chaining
-
markAsFunctionCall
ProcedureCall markAsFunctionCall(Class<?> resultType)
Mark this ProcedureCall as representing a call to a database function, rather than a database procedure.- Parameters:
resultType
- The result type for the function return- Returns:
this
, for method chaining- Since:
- 6.2
-
markAsFunctionCall
ProcedureCall markAsFunctionCall(BasicTypeReference<?> typeReference)
Mark this ProcedureCall as representing a call to a database function, rather than a database procedure.- Parameters:
typeReference
- The result type for the function return- Returns:
this
, for method chaining- Since:
- 6.2
-
registerParameter
<T> ProcedureParameter<T> registerParameter(int position, Class<T> type, ParameterMode mode)
Basic form for registering a positional parameter.- Type Parameters:
T
- The parameterized Java type of the parameter.- Parameters:
position
- The positiontype
- The Java type of the parametermode
- The parameter mode (in, out, inout)- Returns:
- The parameter registration memento
-
registerParameter
<T> ProcedureParameter<T> registerParameter(int position, BasicTypeReference<T> type, ParameterMode mode)
Basic form for registering a positional parameter.- Type Parameters:
T
- The parameterized Java type of the parameter.- Parameters:
position
- The positiontype
- The type reference of the parameter typemode
- The parameter mode (in, out, inout)- Returns:
- The parameter registration memento
-
registerStoredProcedureParameter
ProcedureCall registerStoredProcedureParameter(int position, BasicTypeReference<?> type, ParameterMode mode)
LikeregisterStoredProcedureParameter(int, Class, ParameterMode)
but a basic type reference is given instead of a class for the parameter type.
-
getParameterRegistration
ProcedureParameter getParameterRegistration(int position)
Retrieve a previously registered parameter memento by the position under which it was registered.- Parameters:
position
- The parameter position- Returns:
- The parameter registration memento
- Throws:
ParameterStrategyException
- If the ProcedureCall is defined using named parametersNoSuchParameterException
- If no parameter with that position exists
-
registerParameter
<T> ProcedureParameter<T> registerParameter(String parameterName, Class<T> type, ParameterMode mode) throws NamedParametersNotSupportedException
Basic form for registering a named parameter.- Type Parameters:
T
- The parameterized Java type of the parameter.- Parameters:
parameterName
- The parameter nametype
- The Java type of the parametermode
- The parameter mode (in, out, inout)- Returns:
- The parameter registration memento
- Throws:
NamedParametersNotSupportedException
- When the underlying database is known to not support named procedure parameters.
-
registerParameter
<T> ProcedureParameter<T> registerParameter(String parameterName, BasicTypeReference<T> type, ParameterMode mode) throws NamedParametersNotSupportedException
Basic form for registering a named parameter.- Type Parameters:
T
- The parameterized Java type of the parameter.- Parameters:
parameterName
- The parameter nametype
- The type reference of the parameter typemode
- The parameter mode (in, out, inout)- Returns:
- The parameter registration memento
- Throws:
NamedParametersNotSupportedException
- When the underlying database is known to not support named procedure parameters.
-
registerStoredProcedureParameter
ProcedureCall registerStoredProcedureParameter(String parameterName, BasicTypeReference<?> type, ParameterMode mode)
LikeregisterStoredProcedureParameter(String, Class, ParameterMode)
but a basic type reference is given instead of a class for the parameter type.
-
getParameterRegistration
ProcedureParameter getParameterRegistration(String name)
Retrieve a previously registered parameter memento by the name under which it was registered.- Parameters:
name
- The parameter name- Returns:
- The parameter registration memento
- Throws:
ParameterStrategyException
- If the ProcedureCall is defined using positional parametersNoSuchParameterException
- If no parameter with that name exists
-
getRegisteredParameters
List<ProcedureParameter> getRegisteredParameters()
Retrieve all registered parameters.- Returns:
- The (immutable) list of all registered parameters.
-
getOutputs
ProcedureOutputs getOutputs()
Retrieves access to outputs of this procedure call. Can be called multiple times, returning the same ProcedureOutputs instance each time.If the procedure call has not actually be executed yet, it will be executed and then the ProcedureOutputs will be returned.
- Returns:
- The ProcedureOutputs representation
-
close
default void close()
Release the underlying JDBCCallableStatement
- Specified by:
close
in interfaceAutoCloseable
-
addSynchronizedQuerySpace
ProcedureCall addSynchronizedQuerySpace(String querySpace)
Description copied from interface:SynchronizeableQuery
Add a query space. The effect of this call is to:- force an auto-flush if any entity associated with the current session and mapped to the given query space has pending changes which have not yet been synchronized with the database, and
- if the result set of this query is cached, mark it for invalidation when any entity mapped to the given query space is synchronized with the database in any session.
- Specified by:
addSynchronizedQuerySpace
in interfaceSynchronizeableQuery
- Parameters:
querySpace
- The name of the query space, usually the name of a database table.- Returns:
this
, for method chaining
-
addSynchronizedEntityName
ProcedureCall addSynchronizedEntityName(String entityName) throws MappingException
Description copied from interface:SynchronizeableQuery
Add all query spaces associated with the entity with the given names.Same as
SynchronizeableQuery.addSynchronizedQuerySpace(java.lang.String)
for all tables mapped by the given entity.- Specified by:
addSynchronizedEntityName
in interfaceSynchronizeableQuery
- Parameters:
entityName
- The name of an entity.- Returns:
this
, for method chaining- Throws:
MappingException
- Indicates the given name could not be resolved as an entity
-
addSynchronizedEntityClass
ProcedureCall addSynchronizedEntityClass(Class entityClass) throws MappingException
Description copied from interface:SynchronizeableQuery
Add all query spaces associated with the entity with the given type.Same as
SynchronizeableQuery.addSynchronizedQuerySpace(java.lang.String)
for all tables mapped by the given entity.- Specified by:
addSynchronizedEntityClass
in interfaceSynchronizeableQuery
- Parameters:
entityClass
- The class of the entity.- Returns:
this
, for method chaining- Throws:
MappingException
- Indicates the given class could not be resolved as an entity
-
toMemento
NamedCallableQueryMemento toMemento(String name)
Description copied from interface:NameableQuery
Convert the query into the memento- Specified by:
toMemento
in interfaceNameableQuery
-
setHint
ProcedureCall setHint(String hintName, Object value)
Description copied from interface:CommonQueryContract
Set a hint. The hints understood by Hibernate are enumerated byAvailableHints
.- Specified by:
setHint
in interfaceCommonQueryContract
- Specified by:
setHint
in interfaceQuery
- Specified by:
setHint
in interfaceStoredProcedureQuery
- See Also:
HibernateHints
,SpecHints
-
setParameter
<T> ProcedureCall setParameter(Parameter<T> param, T value)
- Specified by:
setParameter
in interfaceCommonQueryContract
- Specified by:
setParameter
in interfaceQuery
- Specified by:
setParameter
in interfaceStoredProcedureQuery
- See Also:
Query.setParameter(Parameter, Object)
-
setParameter
ProcedureCall setParameter(Parameter<Calendar> param, Calendar value, TemporalType temporalType)
- Specified by:
setParameter
in interfaceCommonQueryContract
- Specified by:
setParameter
in interfaceQuery
- Specified by:
setParameter
in interfaceStoredProcedureQuery
- See Also:
Query.setParameter(Parameter, Calendar, TemporalType)
-
setParameter
ProcedureCall setParameter(Parameter<Date> param, Date value, TemporalType temporalType)
- Specified by:
setParameter
in interfaceCommonQueryContract
- Specified by:
setParameter
in interfaceQuery
- Specified by:
setParameter
in interfaceStoredProcedureQuery
- See Also:
Query.setParameter(Parameter, Date, TemporalType)
-
setParameter
ProcedureCall setParameter(String name, Object value)
Description copied from interface:CommonQueryContract
Bind the given argument to a named query parameter.If the type of the parameter cannot be inferred from the context in which it occurs, use one of the forms which accepts a "type".
- Specified by:
setParameter
in interfaceCommonQueryContract
- Specified by:
setParameter
in interfaceQuery
- Specified by:
setParameter
in interfaceStoredProcedureQuery
- See Also:
CommonQueryContract.setParameter(String, Object, Class)
,CommonQueryContract.setParameter(String, Object, BindableType)
-
setParameter
ProcedureCall setParameter(String name, Calendar value, TemporalType temporalType)
- Specified by:
setParameter
in interfaceCommonQueryContract
- Specified by:
setParameter
in interfaceQuery
- Specified by:
setParameter
in interfaceStoredProcedureQuery
- See Also:
Query.setParameter(String, Calendar, TemporalType)
-
setParameter
ProcedureCall setParameter(String name, Date value, TemporalType temporalType)
- Specified by:
setParameter
in interfaceCommonQueryContract
- Specified by:
setParameter
in interfaceQuery
- Specified by:
setParameter
in interfaceStoredProcedureQuery
- See Also:
Query.setParameter(String, Date, TemporalType)
-
setParameter
ProcedureCall setParameter(int position, Object value)
Description copied from interface:CommonQueryContract
Bind the given argument to an ordinal query parameter.If the type of the parameter cannot be inferred from the context in which it occurs, use one of the forms which accepts a "type".
- Specified by:
setParameter
in interfaceCommonQueryContract
- Specified by:
setParameter
in interfaceQuery
- Specified by:
setParameter
in interfaceStoredProcedureQuery
- See Also:
CommonQueryContract.setParameter(int, Object, Class)
,CommonQueryContract.setParameter(int, Object, BindableType)
-
setParameter
ProcedureCall setParameter(int position, Calendar value, TemporalType temporalType)
- Specified by:
setParameter
in interfaceCommonQueryContract
- Specified by:
setParameter
in interfaceQuery
- Specified by:
setParameter
in interfaceStoredProcedureQuery
- See Also:
Query.setParameter(int, Calendar, TemporalType)
-
setParameter
ProcedureCall setParameter(int position, Date value, TemporalType temporalType)
- Specified by:
setParameter
in interfaceCommonQueryContract
- Specified by:
setParameter
in interfaceQuery
- Specified by:
setParameter
in interfaceStoredProcedureQuery
- See Also:
Query.setParameter(int, Date, TemporalType)
-
setFlushMode
ProcedureCall setFlushMode(FlushModeType flushMode)
Description copied from interface:CommonQueryContract
Set theFlushMode
in to use for this query.- Specified by:
setFlushMode
in interfaceCommonQueryContract
- Specified by:
setFlushMode
in interfaceQuery
- Specified by:
setFlushMode
in interfaceStoredProcedureQuery
- See Also:
CommonQueryContract.getHibernateFlushMode()
,Session.getHibernateFlushMode()
-
registerStoredProcedureParameter
ProcedureCall registerStoredProcedureParameter(int position, Class type, ParameterMode mode)
- Specified by:
registerStoredProcedureParameter
in interfaceStoredProcedureQuery
-
registerStoredProcedureParameter
ProcedureCall registerStoredProcedureParameter(String parameterName, Class type, ParameterMode mode)
- Specified by:
registerStoredProcedureParameter
in interfaceStoredProcedureQuery
-
-