polishing
This commit is contained in:
parent
c7aaa85ef6
commit
5da5fc6499
|
|
@ -38,6 +38,7 @@ import org.springframework.jdbc.core.SqlReturnResultSet;
|
|||
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
|
||||
import org.springframework.jdbc.core.namedparam.SqlParameterSourceUtils;
|
||||
import org.springframework.jdbc.support.JdbcUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Class to manage context metadata used for the configuration and execution of the call.
|
||||
|
|
@ -288,7 +289,7 @@ public class CallMetaDataContext {
|
|||
List<String> metaDataParameterNames = new ArrayList<String>();
|
||||
|
||||
// get the names of the meta data parameters
|
||||
for (CallParameterMetaData meta : metaDataProvider.getCallParameterMetaData()) {
|
||||
for (CallParameterMetaData meta : this.metaDataProvider.getCallParameterMetaData()) {
|
||||
if (meta.getParameterType() != DatabaseMetaData.procedureColumnReturn) {
|
||||
metaDataParameterNames.add(meta.getParameterName().toLowerCase());
|
||||
}
|
||||
|
|
@ -304,21 +305,21 @@ public class CallMetaDataContext {
|
|||
declaredParameters.put(parameterNameToMatch, parameter);
|
||||
if (parameter instanceof SqlOutParameter) {
|
||||
outParameterNames.add(parameter.getName());
|
||||
if (this.isFunction() && !metaDataParameterNames.contains(parameterNameToMatch)) {
|
||||
if (isFunction() && !metaDataParameterNames.contains(parameterNameToMatch)) {
|
||||
if (!returnDeclared) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Using declared out parameter '" + parameter.getName() + "' for function return value");
|
||||
}
|
||||
this.setFunctionReturnName(parameter.getName());
|
||||
setFunctionReturnName(parameter.getName());
|
||||
returnDeclared = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
this.setOutParameterNames(outParameterNames);
|
||||
setOutParameterNames(outParameterNames);
|
||||
|
||||
final List<SqlParameter> workParameters = new ArrayList<SqlParameter>();
|
||||
List<SqlParameter> workParameters = new ArrayList<SqlParameter>();
|
||||
workParameters.addAll(declaredReturnParameters);
|
||||
|
||||
if (!this.metaDataProvider.isProcedureColumnMetaDataUsed()) {
|
||||
|
|
@ -332,7 +333,7 @@ public class CallMetaDataContext {
|
|||
this.metaDataProvider.parameterNameToUse(limitedParameterName).toLowerCase(), limitedParameterName);
|
||||
}
|
||||
|
||||
for (CallParameterMetaData meta : metaDataProvider.getCallParameterMetaData()) {
|
||||
for (CallParameterMetaData meta : this.metaDataProvider.getCallParameterMetaData()) {
|
||||
String parNameToCheck = null;
|
||||
if (meta.getParameterName() != null) {
|
||||
parNameToCheck = this.metaDataProvider.parameterNameToUse(meta.getParameterName()).toLowerCase();
|
||||
|
|
@ -342,17 +343,17 @@ public class CallMetaDataContext {
|
|||
(meta.getParameterType() == DatabaseMetaData.procedureColumnReturn && returnDeclared)) {
|
||||
SqlParameter parameter;
|
||||
if (meta.getParameterType() == DatabaseMetaData.procedureColumnReturn) {
|
||||
parameter = declaredParameters.get(this.getFunctionReturnName());
|
||||
if (parameter == null && this.getOutParameterNames().size() > 0) {
|
||||
parameter = declaredParameters.get(this.getOutParameterNames().get(0).toLowerCase());
|
||||
parameter = declaredParameters.get(getFunctionReturnName());
|
||||
if (parameter == null && getOutParameterNames().size() > 0) {
|
||||
parameter = declaredParameters.get(getOutParameterNames().get(0).toLowerCase());
|
||||
}
|
||||
if (parameter == null) {
|
||||
throw new InvalidDataAccessApiUsageException(
|
||||
"Unable to locate declared parameter for function return value - " +
|
||||
" add an SqlOutParameter with name \"" + getFunctionReturnName() +"\"");
|
||||
" add a SqlOutParameter with name \"" + getFunctionReturnName() +"\"");
|
||||
}
|
||||
else {
|
||||
this.setFunctionReturnName(parameter.getName());
|
||||
setFunctionReturnName(parameter.getName());
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
|
@ -375,12 +376,11 @@ public class CallMetaDataContext {
|
|||
}
|
||||
}
|
||||
else {
|
||||
String returnNameToUse =
|
||||
( meta.getParameterName() == null || meta.getParameterName().length() < 1 ) ?
|
||||
this.getFunctionReturnName() : parNameToUse;
|
||||
String returnNameToUse =(StringUtils.hasLength(meta.getParameterName()) ?
|
||||
parNameToUse : getFunctionReturnName());
|
||||
workParameters.add(new SqlOutParameter(returnNameToUse, meta.getSqlType()));
|
||||
if (this.isFunction()) {
|
||||
this.setFunctionReturnName(returnNameToUse);
|
||||
if (isFunction()) {
|
||||
setFunctionReturnName(returnNameToUse);
|
||||
outParameterNames.add(returnNameToUse);
|
||||
}
|
||||
if (logger.isDebugEnabled()) {
|
||||
|
|
@ -404,7 +404,7 @@ public class CallMetaDataContext {
|
|||
}
|
||||
}
|
||||
else {
|
||||
if (this.limitedInParameterNames.size() == 0 ||
|
||||
if (this.limitedInParameterNames.isEmpty() ||
|
||||
limitedInParamNamesMap.containsKey(parNameToUse.toLowerCase())) {
|
||||
workParameters.add(this.metaDataProvider.createDefaultInParameter(parNameToUse, meta));
|
||||
if (logger.isDebugEnabled()) {
|
||||
|
|
@ -575,15 +575,15 @@ public class CallMetaDataContext {
|
|||
String procedureNameToUse = this.metaDataProvider.procedureNameToUse(this.getProcedureName());
|
||||
if (this.isFunction() || this.isReturnValueRequired()) {
|
||||
callString = "{? = call " +
|
||||
(catalogNameToUse != null && catalogNameToUse.length() > 0 ? catalogNameToUse + "." : "") +
|
||||
(schemaNameToUse != null && schemaNameToUse.length() > 0 ? schemaNameToUse + "." : "") +
|
||||
(StringUtils.hasLength(catalogNameToUse) ? catalogNameToUse + "." : "") +
|
||||
(StringUtils.hasLength(schemaNameToUse) ? schemaNameToUse + "." : "") +
|
||||
procedureNameToUse + "(";
|
||||
parameterCount = -1;
|
||||
}
|
||||
else {
|
||||
callString = "{call " +
|
||||
(catalogNameToUse != null && catalogNameToUse.length() > 0 ? catalogNameToUse + "." : "") +
|
||||
(schemaNameToUse != null && schemaNameToUse.length() > 0 ? schemaNameToUse + "." : "") +
|
||||
(StringUtils.hasLength(catalogNameToUse) ? catalogNameToUse + "." : "") +
|
||||
(StringUtils.hasLength(schemaNameToUse) ? schemaNameToUse + "." : "") +
|
||||
procedureNameToUse + "(";
|
||||
}
|
||||
for (SqlParameter parameter : this.callParameters) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2010 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.
|
||||
|
|
@ -74,28 +74,28 @@ public interface CallMetaDataProvider {
|
|||
|
||||
/**
|
||||
* Provide any modification of the catalog name passed in to match the meta data currently used.
|
||||
* The reyurned value will be used for meta data lookups. This could include alterig the case used or
|
||||
* providing a base catalog if mone provided.
|
||||
* The reyurned value will be used for meta data lookups. This could include alterig the case used
|
||||
* or providing a base catalog if mone provided.
|
||||
*/
|
||||
String metaDataCatalogNameToUse(String catalogName) ;
|
||||
|
||||
/**
|
||||
* Provide any modification of the schema name passed in to match the meta data currently used.
|
||||
* The reyurned value will be used for meta data lookups. This could include alterig the case used or
|
||||
* providing a base schema if mone provided.
|
||||
* The reyurned value will be used for meta data lookups. This could include alterig the case used
|
||||
* or providing a base schema if mone provided.
|
||||
*/
|
||||
String metaDataSchemaNameToUse(String schemaName) ;
|
||||
|
||||
/**
|
||||
* Provide any modification of the column name passed in to match the meta data currently used.
|
||||
* This could include alterig the case.
|
||||
* This could include altering the case.
|
||||
* @param parameterName name of the parameter of column
|
||||
*/
|
||||
String parameterNameToUse(String parameterName);
|
||||
|
||||
/**
|
||||
* Create a default out parameter based on the provided meta data. This is used when no expicit
|
||||
* parameter declaration has been made.
|
||||
* Create a default out parameter based on the provided meta data. This is used when no
|
||||
* explicit parameter declaration has been made.
|
||||
* @param parameterName the name of the parameter
|
||||
* @param meta meta data used for this call
|
||||
* @return the configured SqlOutParameter
|
||||
|
|
@ -103,8 +103,8 @@ public interface CallMetaDataProvider {
|
|||
SqlParameter createDefaultOutParameter(String parameterName, CallParameterMetaData meta);
|
||||
|
||||
/**
|
||||
* Create a default inout parameter based on the provided meta data. This is used when no expicit
|
||||
* parameter declaration has been made.
|
||||
* Create a default inout parameter based on the provided meta data. This is used when no
|
||||
* explicit parameter declaration has been made.
|
||||
* @param parameterName the name of the parameter
|
||||
* @param meta meta data used for this call
|
||||
* @return the configured SqlInOutParameter
|
||||
|
|
@ -112,8 +112,8 @@ public interface CallMetaDataProvider {
|
|||
SqlParameter createDefaultInOutParameter(String parameterName, CallParameterMetaData meta);
|
||||
|
||||
/**
|
||||
* Create a default in parameter based on the provided meta data. This is used when no expicit
|
||||
* parameter declaration has been made.
|
||||
* Create a default in parameter based on the provided meta data. This is used when no
|
||||
* explicit parameter declaration has been made.
|
||||
* @param parameterName the name of the parameter
|
||||
* @param meta meta data used for this call
|
||||
* @return the configured SqlParameter
|
||||
|
|
|
|||
Loading…
Reference in New Issue