Polishing (collapsed if checks, consistent downcasts, refined javadoc)

This commit is contained in:
Juergen Hoeller
2018-03-08 18:11:57 +01:00
parent 0f7485b01d
commit 139dc1d373
50 changed files with 336 additions and 435 deletions

View File

@@ -348,15 +348,13 @@ public class CallMetaDataContext {
declaredParams.put(paramNameToMatch, param);
if (param instanceof SqlOutParameter) {
outParamNames.add(paramName);
if (isFunction() && !metaDataParamNames.contains(paramNameToMatch)) {
if (!returnDeclared) {
if (logger.isDebugEnabled()) {
logger.debug("Using declared out parameter '" + paramName +
"' for function return value");
}
setFunctionReturnName(paramName);
returnDeclared = true;
if (isFunction() && !metaDataParamNames.contains(paramNameToMatch) && !returnDeclared) {
if (logger.isDebugEnabled()) {
logger.debug("Using declared out parameter '" + paramName +
"' for function return value");
}
setFunctionReturnName(paramName);
returnDeclared = true;
}
}
}
@@ -365,7 +363,6 @@ public class CallMetaDataContext {
List<SqlParameter> workParams = new ArrayList<>();
workParams.addAll(declaredReturnParams);
if (!provider.isProcedureColumnMetaDataUsed()) {
workParams.addAll(declaredParams.values());
return workParams;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 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.
@@ -28,16 +28,14 @@ import org.springframework.jdbc.core.SqlParameter;
/**
* Superclass for object abstractions of RDBMS stored procedures.
* This class is abstract and it is intended that subclasses will provide
* a typed method for invocation that delegates to the supplied
* {@link #execute} method.
* This class is abstract and it is intended that subclasses will provide a typed
* method for invocation that delegates to the supplied {@link #execute} method.
*
* <p>The inherited {@code sql} property is the name of the stored
* procedure in the RDBMS.
* <p>The inherited {@link #setSql sql} property is the name of the stored procedure
* in the RDBMS.
*
* @author Rod Johnson
* @author Thomas Risberg
* @see #setSql
*/
public abstract class StoredProcedure extends SqlCall {
@@ -113,10 +111,8 @@ public abstract class StoredProcedure extends SqlCall {
validateParameters(inParams);
int i = 0;
for (SqlParameter sqlParameter : getDeclaredParameters()) {
if (sqlParameter.isInputValueProvided()) {
if (i < inParams.length) {
paramsToUse.put(sqlParameter.getName(), inParams[i++]);
}
if (sqlParameter.isInputValueProvided() && i < inParams.length) {
paramsToUse.put(sqlParameter.getName(), inParams[i++]);
}
}
return getJdbcTemplate().call(newCallableStatementCreator(paramsToUse), getDeclaredParameters());

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 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.
@@ -217,14 +217,13 @@ public class SQLErrorCodeSQLExceptionTranslator extends AbstractFallbackSQLExcep
CustomSQLErrorCodesTranslation[] customTranslations = this.sqlErrorCodes.getCustomTranslations();
if (customTranslations != null) {
for (CustomSQLErrorCodesTranslation customTranslation : customTranslations) {
if (Arrays.binarySearch(customTranslation.getErrorCodes(), errorCode) >= 0) {
if (customTranslation.getExceptionClass() != null) {
DataAccessException customException = createCustomException(
task, sql, sqlEx, customTranslation.getExceptionClass());
if (customException != null) {
logTranslation(task, sql, sqlEx, true);
return customException;
}
if (Arrays.binarySearch(customTranslation.getErrorCodes(), errorCode) >= 0 &&
customTranslation.getExceptionClass() != null) {
DataAccessException customException = createCustomException(
task, sql, sqlEx, customTranslation.getExceptionClass());
if (customException != null) {
logTranslation(task, sql, sqlEx, true);
return customException;
}
}
}
@@ -321,35 +320,35 @@ public class SQLErrorCodeSQLExceptionTranslator extends AbstractFallbackSQLExcep
protected DataAccessException createCustomException(
String task, @Nullable String sql, SQLException sqlEx, Class<?> exceptionClass) {
// find appropriate constructor
// Find appropriate constructor for the given exception class
try {
int constructorType = 0;
Constructor<?>[] constructors = exceptionClass.getConstructors();
for (Constructor<?> constructor : constructors) {
Class<?>[] parameterTypes = constructor.getParameterTypes();
if (parameterTypes.length == 1 && String.class == parameterTypes[0]) {
if (constructorType < MESSAGE_ONLY_CONSTRUCTOR)
constructorType = MESSAGE_ONLY_CONSTRUCTOR;
if (parameterTypes.length == 1 && String.class == parameterTypes[0] &&
constructorType < MESSAGE_ONLY_CONSTRUCTOR) {
constructorType = MESSAGE_ONLY_CONSTRUCTOR;
}
if (parameterTypes.length == 2 && String.class == parameterTypes[0] &&
Throwable.class == parameterTypes[1]) {
if (constructorType < MESSAGE_THROWABLE_CONSTRUCTOR)
constructorType = MESSAGE_THROWABLE_CONSTRUCTOR;
Throwable.class == parameterTypes[1] &&
constructorType < MESSAGE_THROWABLE_CONSTRUCTOR) {
constructorType = MESSAGE_THROWABLE_CONSTRUCTOR;
}
if (parameterTypes.length == 2 && String.class == parameterTypes[0] &&
SQLException.class == parameterTypes[1]) {
if (constructorType < MESSAGE_SQLEX_CONSTRUCTOR)
constructorType = MESSAGE_SQLEX_CONSTRUCTOR;
SQLException.class == parameterTypes[1] &&
constructorType < MESSAGE_SQLEX_CONSTRUCTOR) {
constructorType = MESSAGE_SQLEX_CONSTRUCTOR;
}
if (parameterTypes.length == 3 && String.class == parameterTypes[0] &&
String.class == parameterTypes[1] && Throwable.class == parameterTypes[2]) {
if (constructorType < MESSAGE_SQL_THROWABLE_CONSTRUCTOR)
constructorType = MESSAGE_SQL_THROWABLE_CONSTRUCTOR;
String.class == parameterTypes[1] && Throwable.class == parameterTypes[2] &&
constructorType < MESSAGE_SQL_THROWABLE_CONSTRUCTOR) {
constructorType = MESSAGE_SQL_THROWABLE_CONSTRUCTOR;
}
if (parameterTypes.length == 3 && String.class == parameterTypes[0] &&
String.class == parameterTypes[1] && SQLException.class == parameterTypes[2]) {
if (constructorType < MESSAGE_SQL_SQLEX_CONSTRUCTOR)
constructorType = MESSAGE_SQL_SQLEX_CONSTRUCTOR;
String.class == parameterTypes[1] && SQLException.class == parameterTypes[2] &&
constructorType < MESSAGE_SQL_SQLEX_CONSTRUCTOR) {
constructorType = MESSAGE_SQL_SQLEX_CONSTRUCTOR;
}
}