Skip to content

Commit e797398

Browse files
committed
CallParameterMetaData detects function return parameter specifically
Closes gh-25588
1 parent 613b05d commit e797398

File tree

2 files changed

+40
-16
lines changed

2 files changed

+40
-16
lines changed

spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/CallParameterMetaData.java

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -30,25 +30,39 @@
3030
*/
3131
public class CallParameterMetaData {
3232

33+
private final boolean function;
34+
3335
@Nullable
34-
private String parameterName;
36+
private final String parameterName;
3537

36-
private int parameterType;
38+
private final int parameterType;
3739

38-
private int sqlType;
40+
private final int sqlType;
3941

4042
@Nullable
41-
private String typeName;
43+
private final String typeName;
4244

43-
private boolean nullable;
45+
private final boolean nullable;
4446

4547

4648
/**
47-
* Constructor taking all the properties.
49+
* Constructor taking all the properties except the function marker.
4850
*/
51+
@Deprecated
4952
public CallParameterMetaData(
5053
@Nullable String columnName, int columnType, int sqlType, @Nullable String typeName, boolean nullable) {
5154

55+
this(false, columnName, columnType, sqlType, typeName, nullable);
56+
}
57+
58+
/**
59+
* Constructor taking all the properties including the function marker.
60+
* @since 5.2.9
61+
*/
62+
public CallParameterMetaData(boolean function, @Nullable String columnName, int columnType,
63+
int sqlType, @Nullable String typeName, boolean nullable) {
64+
65+
this.function = function;
5266
this.parameterName = columnName;
5367
this.parameterType = columnType;
5468
this.sqlType = sqlType;
@@ -58,15 +72,23 @@ public CallParameterMetaData(
5872

5973

6074
/**
61-
* Get the parameter name.
75+
* Return whether this parameter is declared in a function.
76+
* @since 5.2.9
77+
*/
78+
public boolean isFunction() {
79+
return this.function;
80+
}
81+
82+
/**
83+
* Return the parameter name.
6284
*/
6385
@Nullable
6486
public String getParameterName() {
6587
return this.parameterName;
6688
}
6789

6890
/**
69-
* Get the parameter type.
91+
* Return the parameter type.
7092
*/
7193
public int getParameterType() {
7294
return this.parameterType;
@@ -75,31 +97,33 @@ public int getParameterType() {
7597
/**
7698
* Determine whether the declared parameter qualifies as a 'return' parameter
7799
* for our purposes: type {@link DatabaseMetaData#procedureColumnReturn} or
78-
* {@link DatabaseMetaData#procedureColumnResult}.
100+
* {@link DatabaseMetaData#procedureColumnResult}, or in case of a function,
101+
* {@link DatabaseMetaData#functionReturn}.
79102
* @since 4.3.15
80103
*/
81104
public boolean isReturnParameter() {
82-
return (this.parameterType == DatabaseMetaData.procedureColumnReturn ||
83-
this.parameterType == DatabaseMetaData.procedureColumnResult);
105+
return (this.function ? this.parameterType == DatabaseMetaData.functionReturn :
106+
(this.parameterType == DatabaseMetaData.procedureColumnReturn ||
107+
this.parameterType == DatabaseMetaData.procedureColumnResult));
84108
}
85109

86110
/**
87-
* Get the parameter SQL type.
111+
* Return the parameter SQL type.
88112
*/
89113
public int getSqlType() {
90114
return this.sqlType;
91115
}
92116

93117
/**
94-
* Get the parameter type name.
118+
* Return the parameter type name.
95119
*/
96120
@Nullable
97121
public String getTypeName() {
98122
return this.typeName;
99123
}
100124

101125
/**
102-
* Get whether the parameter is nullable.
126+
* Return whether the parameter is nullable.
103127
*/
104128
public boolean isNullable() {
105129
return this.nullable;

spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/GenericCallMetaDataProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ else if ("Oracle".equals(databaseMetaData.getDatabaseProductName())) {
399399
}
400400
else {
401401
int nullable = (function ? DatabaseMetaData.functionNullable : DatabaseMetaData.procedureNullable);
402-
CallParameterMetaData meta = new CallParameterMetaData(columnName, columnType,
402+
CallParameterMetaData meta = new CallParameterMetaData(function, columnName, columnType,
403403
columns.getInt("DATA_TYPE"), columns.getString("TYPE_NAME"),
404404
columns.getInt("NULLABLE") == nullable);
405405
this.callParameterMetaData.add(meta);

0 commit comments

Comments
 (0)