diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/CallMetaDataContext.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/CallMetaDataContext.java index 2c3694667af5..5150f7a3f4d9 100755 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/CallMetaDataContext.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/CallMetaDataContext.java @@ -678,7 +678,7 @@ public String createCallString() { protected String createParameterBinding(SqlParameter parameter) { Assert.state(this.metaDataProvider != null, "No CallMetaDataProvider available"); - return (isNamedBinding() ? this.metaDataProvider.namedParamBindingToUse(parameter.getName()) : "?"); + return (isNamedBinding() ? this.metaDataProvider.namedParameterBindingToUse(parameter.getName()) : "?"); } private static String lowerCase(@Nullable String paramName) { diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/CallMetaDataProvider.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/CallMetaDataProvider.java index a6d88d52a818..4b6d30836248 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/CallMetaDataProvider.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/CallMetaDataProvider.java @@ -30,6 +30,8 @@ * {@link org.springframework.jdbc.core.simple.SimpleJdbcCall}. * * @author Thomas Risberg + * @author Juergen Hoeller + * @author Giuseppe Milicia * @since 2.5 */ public interface CallMetaDataProvider { @@ -55,6 +57,12 @@ public interface CallMetaDataProvider { void initializeWithProcedureColumnMetaData(DatabaseMetaData databaseMetaData, @Nullable String catalogName, @Nullable String schemaName, @Nullable String procedureName) throws SQLException; + /** + * Get the call parameter meta-data that is currently used. + * @return a List of {@link CallParameterMetaData} + */ + List getCallParameterMetaData(); + /** * Provide any modification of the procedure name passed in to match the meta-data currently used. *

This could include altering the case. @@ -100,6 +108,14 @@ void initializeWithProcedureColumnMetaData(DatabaseMetaData databaseMetaData, @N @Nullable String parameterNameToUse(@Nullable String parameterName); + /** + * Return the name of the named parameter to use for binding the given parameter name. + * @param parameterName the name of the parameter to bind + * @return the name of the named parameter to use for binding the given parameter name + * @since 6.1.2 + */ + String namedParameterBindingToUse(@Nullable String parameterName); + /** * Create a default out parameter based on the provided meta-data. *

This is used when no explicit parameter declaration has been made. @@ -164,12 +180,6 @@ void initializeWithProcedureColumnMetaData(DatabaseMetaData databaseMetaData, @N */ boolean byPassReturnParameter(String parameterName); - /** - * Get the call parameter meta-data that is currently used. - * @return a List of {@link CallParameterMetaData} - */ - List getCallParameterMetaData(); - /** * Does the database support the use of catalog name in procedure calls? */ @@ -180,11 +190,4 @@ void initializeWithProcedureColumnMetaData(DatabaseMetaData databaseMetaData, @N */ boolean isSupportsSchemasInProcedureCalls(); - /** - * Returns the name of the named parameter to use for binding the given parameter name. - * @param paramName the name of the parameter to bind - * @return the name of the named parameter to use for binding the given parameter name, - */ - String namedParamBindingToUse(@Nullable String paramName); - } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/GenericCallMetaDataProvider.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/GenericCallMetaDataProvider.java index 0f63d12c5721..15ac02b7569e 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/GenericCallMetaDataProvider.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/GenericCallMetaDataProvider.java @@ -171,8 +171,8 @@ public String parameterNameToUse(@Nullable String parameterName) { } @Override - public boolean byPassReturnParameter(String parameterName) { - return false; + public String namedParameterBindingToUse(@Nullable String parameterName) { + return parameterName + " => ?"; } @Override @@ -215,6 +215,11 @@ public boolean isProcedureColumnMetaDataUsed() { return this.procedureColumnMetaDataUsed; } + @Override + public boolean byPassReturnParameter(String parameterName) { + return false; + } + /** * Specify whether the database supports the use of catalog name in procedure calls. @@ -246,16 +251,6 @@ public boolean isSupportsSchemasInProcedureCalls() { return this.supportsSchemasInProcedureCalls; } - /** - * Returns the name of the named parameter to use for binding the given parameter name. - * @param paramName the name of the parameter to bind - * @return the name of the named parameter to use for binding the given parameter name, - */ - @Override - public String namedParamBindingToUse(@Nullable String paramName) { - return paramName + " => ?"; - } - /** * Specify whether the database uses upper case for identifiers. */ diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/SqlServerCallMetaDataProvider.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/SqlServerCallMetaDataProvider.java index ce408a1e0444..5e745930812e 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/SqlServerCallMetaDataProvider.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/SqlServerCallMetaDataProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 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. @@ -26,6 +26,7 @@ * This class is intended for internal use by the Simple JDBC classes. * * @author Thomas Risberg + * @author Juergen Hoeller * @since 2.5 */ public class SqlServerCallMetaDataProvider extends GenericCallMetaDataProvider { @@ -54,6 +55,11 @@ else if (parameterName.length() > 1 && parameterName.startsWith(REMOVABLE_COLUMN } } + @Override + public String namedParameterBindingToUse(@Nullable String parameterName) { + return parameterName + " = ?"; + } + @Override public boolean byPassReturnParameter(String parameterName) { return RETURN_VALUE_NAME.equals(parameterName); diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/SybaseCallMetaDataProvider.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/SybaseCallMetaDataProvider.java index c2f84e47758e..566361531209 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/SybaseCallMetaDataProvider.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/SybaseCallMetaDataProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 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. @@ -26,6 +26,7 @@ * This class is intended for internal use by the Simple JDBC classes. * * @author Thomas Risberg + * @author Giuseppe Milicia * @since 2.5 */ public class SybaseCallMetaDataProvider extends GenericCallMetaDataProvider { @@ -55,14 +56,14 @@ else if (parameterName.length() > 1 && parameterName.startsWith(REMOVABLE_COLUMN } @Override - public boolean byPassReturnParameter(String parameterName) { - return (RETURN_VALUE_NAME.equals(parameterName) || - RETURN_VALUE_NAME.equals(parameterNameToUse(parameterName))); + public String namedParameterBindingToUse(@Nullable String parameterName) { + return parameterName + " = ?"; } @Override - public String namedParamBindingToUse(@Nullable String paramName) { - return paramName + " = ?"; + public boolean byPassReturnParameter(String parameterName) { + return (RETURN_VALUE_NAME.equals(parameterName) || + RETURN_VALUE_NAME.equals(parameterNameToUse(parameterName))); } }