|
21 | 21 | import org.hibernate.query.procedure.ProcedureParameter; |
22 | 22 |
|
23 | 23 | /** |
24 | | - * Defines support for executing database stored procedures and functions. |
| 24 | + * Defines support for executing database stored procedures and functions using the |
| 25 | + * {@linkplain java.sql.CallableStatement JDBC stored procedure SQL escape syntax}. |
25 | 26 | * <p> |
26 | | - * Note that here we use the terms "procedure" and "function" as follows:<ul> |
27 | | - * <li>procedure is a named database executable we expect to call via : {@code {call procedureName(...)}}</li> |
28 | | - * <li>function is a named database executable we expect to call via : {@code {? = call functionName(...)}}</li> |
| 27 | + * Here we use the terms "procedure" and "function" as follows:<ul> |
| 28 | + * <li>A <em>procedure</em> is a named database executable called via: |
| 29 | + * {@code {call procedureName(...)}}</li> |
| 30 | + * <li>A <em>function</em> is a named database executable called via: |
| 31 | + * {@code {? = call functionName(...)}}</li> |
29 | 32 | * </ul> |
30 | 33 | * <p> |
31 | | - * Unless explicitly specified, the ProcedureCall is assumed to follow the |
32 | | - * procedure call syntax. To explicitly specify that this should be a function |
33 | | - * call, use {@link #markAsFunctionCall}. |
| 34 | + * Unless explicitly specified, the {@code ProcedureCall} is executed using the |
| 35 | + * procedure call syntax. To explicitly specify that the function call syntax |
| 36 | + * should be used, call {@link #markAsFunctionCall}. Clients of the JPA-standard |
| 37 | + * {@link StoredProcedureQuery} interface may choose between: |
| 38 | + * <ul> |
| 39 | + * <li>using {@link #unwrap storedProcedureQuery.unwrap(ProcedureCall.class).markAsFunctionCall(returnType)}, |
| 40 | + * or |
| 41 | + * <li>setting the {@value org.hibernate.jpa.HibernateHints#HINT_CALLABLE_FUNCTION} |
| 42 | + * or {@value org.hibernate.jpa.HibernateHints#HINT_CALLABLE_FUNCTION_RETURN_TYPE} |
| 43 | + * {@linkplain #setHint(String, Object) hint} to avoid the cast to a |
| 44 | + * Hibernate-specific class. |
| 45 | + * </ul> |
34 | 46 | * <p> |
35 | | - * When using function-call syntax:<ul> |
36 | | - * <li>parameters must be registered by position (not name)</li> |
37 | | - * <li>The first parameter is considered to be the function return (the `?` before the call)</li> |
38 | | - * <li>the first parameter must have mode of OUT, INOUT or REF_CURSOR; IN is invalid</li> |
| 47 | + * When the function call syntax is used: |
| 48 | + * <ul> |
| 49 | + * <li>parameters must be registered by position (not name), |
| 50 | + * <li>the first parameter is considered to represent the function return value |
| 51 | + * (corresponding to the {@code ?} which occurs before the {@code =}), and |
| 52 | + * <li>the first parameter must have {@linkplain ParameterMode mode} OUT, INOUT, |
| 53 | + * or REF_CURSOR; {@linkplain ParameterMode#IN IN} is illegal. |
39 | 54 | * </ul> |
40 | 55 | * <p> |
41 | | - * In some cases, based on the Dialect, we will have other validations and |
42 | | - * assumptions as well. For example, on PGSQL, whenever we see a REF_CURSOR mode |
43 | | - * parameter, we know that:<ul> |
44 | | - * <li> |
45 | | - * this will be a function call (so we call {@link #markAsFunctionCall} implicitly) because |
46 | | - * that is the only way PGSQL supports returning REF_CURSOR results. |
47 | | - * </li> |
48 | | - * <li>there can be only one REF_CURSOR mode parameter</li> |
| 56 | + * Depending on the {@linkplain org.hibernate.dialect.Dialect SQL dialect}, |
| 57 | + * further constraints are enforced or inferred. For example, on PostgreSQL: |
| 58 | + * <ul> |
| 59 | + * <li>If a parameter has mode {@linkplain ParameterMode#REF_CURSOR REF_CURSOR}, |
| 60 | + * it's automatically inferred that the call is a function call because this |
| 61 | + * is the only context in which PostgreSQL returns REF_CURSOR results. |
| 62 | + * So it's not necessary to call {@link #markAsFunctionCall} explicitly. |
| 63 | + * <li>The restriction that there may be at most one REF_CURSOR mode parameter |
| 64 | + * is enforced. |
49 | 65 | * </ul> |
50 | 66 | * |
51 | 67 | * @author Steve Ebersole |
| 68 | + * |
| 69 | + * @see java.sql.CallableStatement |
| 70 | + * @see StoredProcedureQuery |
52 | 71 | */ |
53 | 72 | public interface ProcedureCall |
54 | 73 | extends CommonQueryContract, SynchronizeableQuery, StoredProcedureQuery, AutoCloseable { |
@@ -274,10 +293,10 @@ default void close() { |
274 | 293 | ProcedureCall registerStoredProcedureParameter(String parameterName, Class<?> type, ParameterMode mode); |
275 | 294 |
|
276 | 295 | /** |
277 | | - * The hint key indicating the function's return {@linkplain java.sql.Types JDBC type code}. |
| 296 | + * The hint key indicating the return {@linkplain java.sql.Types JDBC type code} of a function. |
278 | 297 | * |
279 | | - * @deprecated This hint no longer has any effect. Use {@link #markAsFunctionCall(int)}. |
| 298 | + * @deprecated Use {@link org.hibernate.jpa.HibernateHints#HINT_CALLABLE_FUNCTION_RETURN_TYPE}. |
280 | 299 | */ |
281 | 300 | @Deprecated(since="7", forRemoval = true) |
282 | | - String FUNCTION_RETURN_TYPE_HINT = "hibernate.procedure.function_return_jdbc_type_code"; |
| 301 | + String FUNCTION_RETURN_TYPE_HINT = org.hibernate.jpa.HibernateHints.HINT_CALLABLE_FUNCTION_RETURN_TYPE; |
283 | 302 | } |
0 commit comments