Skip to content

Commit f8e1ce3

Browse files
committed
Check for procedure vs function constants in CallMetaDataContext
Closes gh-31550 (cherry picked from commit 9957bb6)
1 parent d3ec939 commit f8e1ce3

File tree

3 files changed

+56
-62
lines changed

3 files changed

+56
-62
lines changed

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

+9-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2023 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.
@@ -16,7 +16,6 @@
1616

1717
package org.springframework.jdbc.core.metadata;
1818

19-
import java.sql.DatabaseMetaData;
2019
import java.util.ArrayList;
2120
import java.util.HashSet;
2221
import java.util.LinkedHashMap;
@@ -115,28 +114,28 @@ public String getFunctionReturnName() {
115114
}
116115

117116
/**
118-
* Specify a limited set of in parameters to be used.
117+
* Specify a limited set of the {@code in} parameters to be used.
119118
*/
120119
public void setLimitedInParameterNames(Set<String> limitedInParameterNames) {
121120
this.limitedInParameterNames = limitedInParameterNames;
122121
}
123122

124123
/**
125-
* Get a limited set of in parameters to be used.
124+
* Get the limited set of the {@code in} parameters to be used.
126125
*/
127126
public Set<String> getLimitedInParameterNames() {
128127
return this.limitedInParameterNames;
129128
}
130129

131130
/**
132-
* Specify the names of the out parameters.
131+
* Specify the names of the {@code out} parameters.
133132
*/
134133
public void setOutParameterNames(List<String> outParameterNames) {
135134
this.outParameterNames = outParameterNames;
136135
}
137136

138137
/**
139-
* Get a list of the out parameter names.
138+
* Get the list of the {@code out} parameter names.
140139
*/
141140
public List<String> getOutParameterNames() {
142141
return this.outParameterNames;
@@ -434,14 +433,14 @@ protected List<SqlParameter> reconcileParameters(List<SqlParameter> parameters)
434433
if (paramNameToUse == null) {
435434
paramNameToUse = "";
436435
}
437-
if (meta.getParameterType() == DatabaseMetaData.procedureColumnOut) {
436+
if (meta.isOutParameter()) {
438437
workParams.add(provider.createDefaultOutParameter(paramNameToUse, meta));
439438
outParamNames.add(paramNameToUse);
440439
if (logger.isDebugEnabled()) {
441440
logger.debug("Added meta-data out parameter for '" + paramNameToUse + "'");
442441
}
443442
}
444-
else if (meta.getParameterType() == DatabaseMetaData.procedureColumnInOut) {
443+
else if (meta.isInOutParameter()) {
445444
workParams.add(provider.createDefaultInOutParameter(paramNameToUse, meta));
446445
outParamNames.add(paramNameToUse);
447446
if (logger.isDebugEnabled()) {
@@ -554,7 +553,7 @@ else if (logger.isInfoEnabled()) {
554553
Map<String, String> callParameterNames = CollectionUtils.newHashMap(this.callParameters.size());
555554
for (SqlParameter parameter : this.callParameters) {
556555
if (parameter.isInputValueProvided()) {
557-
String parameterName = parameter.getName();
556+
String parameterName = parameter.getName();
558557
String parameterNameToMatch = provider.parameterNameToUse(parameterName);
559558
if (parameterNameToMatch != null) {
560559
callParameterNames.put(parameterNameToMatch.toLowerCase(), parameterName);
@@ -606,7 +605,7 @@ else if (logger.isInfoEnabled()) {
606605
int i = 0;
607606
for (SqlParameter parameter : this.callParameters) {
608607
if (parameter.isInputValueProvided()) {
609-
String parameterName = parameter.getName();
608+
String parameterName = parameter.getName();
610609
matchedParameters.put(parameterName, parameterValues[i++]);
611610
}
612611
}

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

+23-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2023 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.
@@ -107,6 +107,28 @@ public boolean isReturnParameter() {
107107
this.parameterType == DatabaseMetaData.procedureColumnResult));
108108
}
109109

110+
/**
111+
* Determine whether the declared parameter qualifies as an 'out' parameter
112+
* for our purposes: type {@link DatabaseMetaData#procedureColumnOut},
113+
* or in case of a function, {@link DatabaseMetaData#functionColumnOut}.
114+
* @since 5.3.31
115+
*/
116+
public boolean isOutParameter() {
117+
return (this.function ? this.parameterType == DatabaseMetaData.functionColumnOut :
118+
this.parameterType == DatabaseMetaData.procedureColumnOut);
119+
}
120+
121+
/**
122+
* Determine whether the declared parameter qualifies as an 'in-out' parameter
123+
* for our purposes: type {@link DatabaseMetaData#procedureColumnInOut},
124+
* or in case of a function, {@link DatabaseMetaData#functionColumnInOut}.
125+
* @since 5.3.31
126+
*/
127+
public boolean isInOutParameter() {
128+
return (this.function ? this.parameterType == DatabaseMetaData.functionColumnInOut :
129+
this.parameterType == DatabaseMetaData.procedureColumnInOut);
130+
}
131+
110132
/**
111133
* Return the parameter SQL type.
112134
*/

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

+24-51
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2023 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.
@@ -35,7 +35,8 @@
3535

3636
/**
3737
* A generic implementation of the {@link CallMetaDataProvider} interface.
38-
* This class can be extended to provide database specific behavior.
38+
*
39+
* <p>This class can be extended to provide database specific behavior.
3940
*
4041
* @author Thomas Risberg
4142
* @author Juergen Hoeller
@@ -113,7 +114,7 @@ public void initializeWithProcedureColumnMetaData(DatabaseMetaData databaseMetaD
113114
@Nullable String schemaName, @Nullable String procedureName) throws SQLException {
114115

115116
this.procedureColumnMetaDataUsed = true;
116-
processProcedureColumns(databaseMetaData, catalogName, schemaName, procedureName);
117+
processProcedureColumns(databaseMetaData, catalogName, schemaName, procedureName);
117118
}
118119

119120
@Override
@@ -124,52 +125,19 @@ public List<CallParameterMetaData> getCallParameterMetaData() {
124125
@Override
125126
@Nullable
126127
public String procedureNameToUse(@Nullable String procedureName) {
127-
if (procedureName == null) {
128-
return null;
129-
}
130-
else if (isStoresUpperCaseIdentifiers()) {
131-
return procedureName.toUpperCase();
132-
}
133-
else if (isStoresLowerCaseIdentifiers()) {
134-
return procedureName.toLowerCase();
135-
}
136-
else {
137-
return procedureName;
138-
}
128+
return identifierNameToUse(procedureName);
139129
}
140130

141131
@Override
142132
@Nullable
143133
public String catalogNameToUse(@Nullable String catalogName) {
144-
if (catalogName == null) {
145-
return null;
146-
}
147-
else if (isStoresUpperCaseIdentifiers()) {
148-
return catalogName.toUpperCase();
149-
}
150-
else if (isStoresLowerCaseIdentifiers()) {
151-
return catalogName.toLowerCase();
152-
}
153-
else {
154-
return catalogName;
155-
}
134+
return identifierNameToUse(catalogName);
156135
}
157136

158137
@Override
159138
@Nullable
160139
public String schemaNameToUse(@Nullable String schemaName) {
161-
if (schemaName == null) {
162-
return null;
163-
}
164-
else if (isStoresUpperCaseIdentifiers()) {
165-
return schemaName.toUpperCase();
166-
}
167-
else if (isStoresLowerCaseIdentifiers()) {
168-
return schemaName.toLowerCase();
169-
}
170-
else {
171-
return schemaName;
172-
}
140+
return identifierNameToUse(schemaName);
173141
}
174142

175143
@Override
@@ -197,18 +165,7 @@ public String metaDataSchemaNameToUse(@Nullable String schemaName) {
197165
@Override
198166
@Nullable
199167
public String parameterNameToUse(@Nullable String parameterName) {
200-
if (parameterName == null) {
201-
return null;
202-
}
203-
else if (isStoresUpperCaseIdentifiers()) {
204-
return parameterName.toUpperCase();
205-
}
206-
else if (isStoresLowerCaseIdentifiers()) {
207-
return parameterName.toLowerCase();
208-
}
209-
else {
210-
return parameterName;
211-
}
168+
return identifierNameToUse(parameterName);
212169
}
213170

214171
@Override
@@ -316,6 +273,22 @@ protected boolean isStoresLowerCaseIdentifiers() {
316273
}
317274

318275

276+
@Nullable
277+
private String identifierNameToUse(@Nullable String identifierName) {
278+
if (identifierName == null) {
279+
return null;
280+
}
281+
else if (isStoresUpperCaseIdentifiers()) {
282+
return identifierName.toUpperCase();
283+
}
284+
else if (isStoresLowerCaseIdentifiers()) {
285+
return identifierName.toLowerCase();
286+
}
287+
else {
288+
return identifierName;
289+
}
290+
}
291+
319292
/**
320293
* Process the procedure column meta-data.
321294
*/

0 commit comments

Comments
 (0)