Package org.hibernate.procedure
Interface ProcedureCall
-
- All Superinterfaces:
AutoCloseable,CommonQueryContract,NameableQuery,Query,StoredProcedureQuery,SynchronizeableQuery
- All Known Subinterfaces:
ProcedureCallImplementor<R>
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(...)}
markAsFunctionCall(int). JPA users could either:- use
storedProcedureQuery.unwrap( ProcedureCall.class.markAsFunctionCall() - set the
FUNCTION_RETURN_TYPE_HINThint (avoids casting to Hibernate-specific classes)
- 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
-
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 StringFUNCTION_RETURN_TYPE_HINTThe hint key (for use with JPA's "hint system") indicating the function's return JDBC type code (aka,Typescode)
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description ProcedureCalladdSynchronizedEntityClass(Class entityClass)Adds an entity for (a) auto-flush checking and (b) query result cache invalidation checking.ProcedureCalladdSynchronizedEntityName(String entityName)Adds an entity name for (a) auto-flush checking and (b) query result cache invalidation checking.ProcedureCalladdSynchronizedQuerySpace(String querySpace)Adds a query space.default voidclose()Release the underlying JDBCCallableStatementProcedureOutputsgetOutputs()Retrieves access to outputs of this procedure call.ProcedureParametergetParameterRegistration(int position)Retrieve a previously registered parameter memento by the position under which it was registered.ProcedureParametergetParameterRegistration(String name)Retrieve a previously registered parameter memento by the name under which it was registered.StringgetProcedureName()Get the name of the stored procedure (or function) to be called.List<ProcedureParameter>getRegisteredParameters()Retrieve all registered parameters.booleanisFunctionCall()Does this ProcedureCall represent a call to a database FUNCTION (as opposed to a PROCEDURE call)? NOTE : this will only report whether this ProcedureCall was marked as a function via call tomarkAsFunctionCall(int).ProcedureCallmarkAsFunctionCall(int sqlType)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.ProcedureCallregisterStoredProcedureParameter(int position, Class type, ParameterMode mode)ProcedureCallregisterStoredProcedureParameter(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.ProcedureCallregisterStoredProcedureParameter(String parameterName, Class type, ParameterMode mode)ProcedureCallregisterStoredProcedureParameter(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.ProcedureCallsetFlushMode(FlushModeType flushMode)ProcedureCallsetHint(String hintName, Object value)ProcedureCallsetParameter(int position, Object value)ProcedureCallsetParameter(int position, Calendar value, TemporalType temporalType)ProcedureCallsetParameter(int position, Date value, TemporalType temporalType)ProcedureCallsetParameter(Parameter<Calendar> param, Calendar value, TemporalType temporalType)ProcedureCallsetParameter(Parameter<Date> param, Date value, TemporalType temporalType)<T> ProcedureCallsetParameter(Parameter<T> param, T value)ProcedureCallsetParameter(String name, Object value)ProcedureCallsetParameter(String name, Calendar value, TemporalType temporalType)ProcedureCallsetParameter(String name, Date value, TemporalType temporalType)NamedCallableQueryMementotoMemento(String name)Convert the query into the memento-
Methods inherited from interface org.hibernate.query.CommonQueryContract
getCacheMode, getCacheRegion, getFetchSize, getHibernateFlushMode, getTimeout, isCacheable, isReadOnly, setCacheable, setCacheMode, setCacheRegion, setFetchSize, setHibernateFlushMode, setReadOnly, 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.SynchronizeableQuery
addSynchronizedEntityClass, addSynchronizedEntityName, addSynchronizedQuerySpace, addSynchronizedTable, addSynchronizedTable, 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,Typescode)- 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 this ProcedureCall represent a call to a database FUNCTION (as opposed to a PROCEDURE call)? NOTE : this will only report whether this ProcedureCall was marked as a function via call tomarkAsFunctionCall(int). Specifically will not returntruewhen using JPA query hint.- Returns:
trueindicates that this ProcedureCall represents a function call;falseindicates a procedure call.
-
markAsFunctionCall
ProcedureCall markAsFunctionCall(int sqlType)
Mark this ProcedureCall as representing a call to a database function, rather than a database procedure.- Parameters:
sqlType- TheTypescode for the function return- Returns:
this, for method chaining
-
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:
closein interfaceAutoCloseable
-
addSynchronizedQuerySpace
ProcedureCall addSynchronizedQuerySpace(String querySpace)
Description copied from interface:SynchronizeableQueryAdds a query space.- Specified by:
addSynchronizedQuerySpacein interfaceSynchronizeableQuery- Parameters:
querySpace- The query space to be auto-flushed for this query.- Returns:
this, for method chaining
-
addSynchronizedEntityName
ProcedureCall addSynchronizedEntityName(String entityName) throws MappingException
Description copied from interface:SynchronizeableQueryAdds an entity name for (a) auto-flush checking and (b) query result cache invalidation checking. Same asSynchronizeableQuery.addSynchronizedQuerySpace(java.lang.String)for all tables associated with the given entity.- Specified by:
addSynchronizedEntityNamein interfaceSynchronizeableQuery- Parameters:
entityName- The name of the entity upon whose defined query spaces we should additionally synchronize.- 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:SynchronizeableQueryAdds an entity for (a) auto-flush checking and (b) query result cache invalidation checking. Same asSynchronizeableQuery.addSynchronizedQuerySpace(java.lang.String)for all tables associated with the given entity.- Specified by:
addSynchronizedEntityClassin interfaceSynchronizeableQuery- Parameters:
entityClass- The class of the entity upon whose defined query spaces we should additionally synchronize.- 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:NameableQueryConvert the query into the memento- Specified by:
toMementoin interfaceNameableQuery
-
setHint
ProcedureCall setHint(String hintName, Object value)
- Specified by:
setHintin interfaceQuery- Specified by:
setHintin interfaceStoredProcedureQuery
-
setParameter
<T> ProcedureCall setParameter(Parameter<T> param, T value)
- Specified by:
setParameterin interfaceQuery- Specified by:
setParameterin interfaceStoredProcedureQuery
-
setParameter
ProcedureCall setParameter(Parameter<Calendar> param, Calendar value, TemporalType temporalType)
- Specified by:
setParameterin interfaceQuery- Specified by:
setParameterin interfaceStoredProcedureQuery
-
setParameter
ProcedureCall setParameter(Parameter<Date> param, Date value, TemporalType temporalType)
- Specified by:
setParameterin interfaceQuery- Specified by:
setParameterin interfaceStoredProcedureQuery
-
setParameter
ProcedureCall setParameter(String name, Object value)
- Specified by:
setParameterin interfaceQuery- Specified by:
setParameterin interfaceStoredProcedureQuery
-
setParameter
ProcedureCall setParameter(String name, Calendar value, TemporalType temporalType)
- Specified by:
setParameterin interfaceQuery- Specified by:
setParameterin interfaceStoredProcedureQuery
-
setParameter
ProcedureCall setParameter(String name, Date value, TemporalType temporalType)
- Specified by:
setParameterin interfaceQuery- Specified by:
setParameterin interfaceStoredProcedureQuery
-
setParameter
ProcedureCall setParameter(int position, Object value)
- Specified by:
setParameterin interfaceQuery- Specified by:
setParameterin interfaceStoredProcedureQuery
-
setParameter
ProcedureCall setParameter(int position, Calendar value, TemporalType temporalType)
- Specified by:
setParameterin interfaceQuery- Specified by:
setParameterin interfaceStoredProcedureQuery
-
setParameter
ProcedureCall setParameter(int position, Date value, TemporalType temporalType)
- Specified by:
setParameterin interfaceQuery- Specified by:
setParameterin interfaceStoredProcedureQuery
-
setFlushMode
ProcedureCall setFlushMode(FlushModeType flushMode)
- Specified by:
setFlushModein interfaceQuery- Specified by:
setFlushModein interfaceStoredProcedureQuery
-
registerStoredProcedureParameter
ProcedureCall registerStoredProcedureParameter(int position, Class type, ParameterMode mode)
- Specified by:
registerStoredProcedureParameterin interfaceStoredProcedureQuery
-
registerStoredProcedureParameter
ProcedureCall registerStoredProcedureParameter(String parameterName, Class type, ParameterMode mode)
- Specified by:
registerStoredProcedureParameterin interfaceStoredProcedureQuery
-
-