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