Skip to content

Commit

Permalink
Check for procedure vs function constants in CallMetaDataContext
Browse files Browse the repository at this point in the history
Closes gh-31550

(cherry picked from commit 9957bb6)
  • Loading branch information
jhoeller committed Nov 9, 2023
1 parent d3ec939 commit f8e1ce3
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 62 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,7 +16,6 @@

package org.springframework.jdbc.core.metadata;

import java.sql.DatabaseMetaData;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashMap;
Expand Down Expand Up @@ -115,28 +114,28 @@ public String getFunctionReturnName() {
}

/**
* Specify a limited set of in parameters to be used.
* Specify a limited set of the {@code in} parameters to be used.
*/
public void setLimitedInParameterNames(Set<String> limitedInParameterNames) {
this.limitedInParameterNames = limitedInParameterNames;
}

/**
* Get a limited set of in parameters to be used.
* Get the limited set of the {@code in} parameters to be used.
*/
public Set<String> getLimitedInParameterNames() {
return this.limitedInParameterNames;
}

/**
* Specify the names of the out parameters.
* Specify the names of the {@code out} parameters.
*/
public void setOutParameterNames(List<String> outParameterNames) {
this.outParameterNames = outParameterNames;
}

/**
* Get a list of the out parameter names.
* Get the list of the {@code out} parameter names.
*/
public List<String> getOutParameterNames() {
return this.outParameterNames;
Expand Down Expand Up @@ -434,14 +433,14 @@ protected List<SqlParameter> reconcileParameters(List<SqlParameter> parameters)
if (paramNameToUse == null) {
paramNameToUse = "";
}
if (meta.getParameterType() == DatabaseMetaData.procedureColumnOut) {
if (meta.isOutParameter()) {
workParams.add(provider.createDefaultOutParameter(paramNameToUse, meta));
outParamNames.add(paramNameToUse);
if (logger.isDebugEnabled()) {
logger.debug("Added meta-data out parameter for '" + paramNameToUse + "'");
}
}
else if (meta.getParameterType() == DatabaseMetaData.procedureColumnInOut) {
else if (meta.isInOutParameter()) {
workParams.add(provider.createDefaultInOutParameter(paramNameToUse, meta));
outParamNames.add(paramNameToUse);
if (logger.isDebugEnabled()) {
Expand Down Expand Up @@ -554,7 +553,7 @@ else if (logger.isInfoEnabled()) {
Map<String, String> callParameterNames = CollectionUtils.newHashMap(this.callParameters.size());
for (SqlParameter parameter : this.callParameters) {
if (parameter.isInputValueProvided()) {
String parameterName = parameter.getName();
String parameterName = parameter.getName();
String parameterNameToMatch = provider.parameterNameToUse(parameterName);
if (parameterNameToMatch != null) {
callParameterNames.put(parameterNameToMatch.toLowerCase(), parameterName);
Expand Down Expand Up @@ -606,7 +605,7 @@ else if (logger.isInfoEnabled()) {
int i = 0;
for (SqlParameter parameter : this.callParameters) {
if (parameter.isInputValueProvided()) {
String parameterName = parameter.getName();
String parameterName = parameter.getName();
matchedParameters.put(parameterName, parameterValues[i++]);
}
}
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -107,6 +107,28 @@ public boolean isReturnParameter() {
this.parameterType == DatabaseMetaData.procedureColumnResult));
}

/**
* Determine whether the declared parameter qualifies as an 'out' parameter
* for our purposes: type {@link DatabaseMetaData#procedureColumnOut},
* or in case of a function, {@link DatabaseMetaData#functionColumnOut}.
* @since 5.3.31
*/
public boolean isOutParameter() {
return (this.function ? this.parameterType == DatabaseMetaData.functionColumnOut :
this.parameterType == DatabaseMetaData.procedureColumnOut);
}

/**
* Determine whether the declared parameter qualifies as an 'in-out' parameter
* for our purposes: type {@link DatabaseMetaData#procedureColumnInOut},
* or in case of a function, {@link DatabaseMetaData#functionColumnInOut}.
* @since 5.3.31
*/
public boolean isInOutParameter() {
return (this.function ? this.parameterType == DatabaseMetaData.functionColumnInOut :
this.parameterType == DatabaseMetaData.procedureColumnInOut);
}

/**
* Return the parameter SQL type.
*/
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -35,7 +35,8 @@

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

this.procedureColumnMetaDataUsed = true;
processProcedureColumns(databaseMetaData, catalogName, schemaName, procedureName);
processProcedureColumns(databaseMetaData, catalogName, schemaName, procedureName);
}

@Override
Expand All @@ -124,52 +125,19 @@ public List<CallParameterMetaData> getCallParameterMetaData() {
@Override
@Nullable
public String procedureNameToUse(@Nullable String procedureName) {
if (procedureName == null) {
return null;
}
else if (isStoresUpperCaseIdentifiers()) {
return procedureName.toUpperCase();
}
else if (isStoresLowerCaseIdentifiers()) {
return procedureName.toLowerCase();
}
else {
return procedureName;
}
return identifierNameToUse(procedureName);
}

@Override
@Nullable
public String catalogNameToUse(@Nullable String catalogName) {
if (catalogName == null) {
return null;
}
else if (isStoresUpperCaseIdentifiers()) {
return catalogName.toUpperCase();
}
else if (isStoresLowerCaseIdentifiers()) {
return catalogName.toLowerCase();
}
else {
return catalogName;
}
return identifierNameToUse(catalogName);
}

@Override
@Nullable
public String schemaNameToUse(@Nullable String schemaName) {
if (schemaName == null) {
return null;
}
else if (isStoresUpperCaseIdentifiers()) {
return schemaName.toUpperCase();
}
else if (isStoresLowerCaseIdentifiers()) {
return schemaName.toLowerCase();
}
else {
return schemaName;
}
return identifierNameToUse(schemaName);
}

@Override
Expand Down Expand Up @@ -197,18 +165,7 @@ public String metaDataSchemaNameToUse(@Nullable String schemaName) {
@Override
@Nullable
public String parameterNameToUse(@Nullable String parameterName) {
if (parameterName == null) {
return null;
}
else if (isStoresUpperCaseIdentifiers()) {
return parameterName.toUpperCase();
}
else if (isStoresLowerCaseIdentifiers()) {
return parameterName.toLowerCase();
}
else {
return parameterName;
}
return identifierNameToUse(parameterName);
}

@Override
Expand Down Expand Up @@ -316,6 +273,22 @@ protected boolean isStoresLowerCaseIdentifiers() {
}


@Nullable
private String identifierNameToUse(@Nullable String identifierName) {
if (identifierName == null) {
return null;
}
else if (isStoresUpperCaseIdentifiers()) {
return identifierName.toUpperCase();
}
else if (isStoresLowerCaseIdentifiers()) {
return identifierName.toLowerCase();
}
else {
return identifierName;
}
}

/**
* Process the procedure column meta-data.
*/
Expand Down

0 comments on commit f8e1ce3

Please sign in to comment.