@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
/ *
* Copyright 2002 - 2020 the original author or authors .
* Copyright 2002 - 2022 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 .
@ -64,6 +64,7 @@ import org.springframework.util.function.SupplierUtils;
@@ -64,6 +64,7 @@ import org.springframework.util.function.SupplierUtils;
* @author Rod Johnson
* @author Thomas Risberg
* @author Juergen Hoeller
* @author Sam Brannen
* @see SQLErrorCodesFactory
* @see SQLStateSQLExceptionTranslator
* /
@ -359,39 +360,45 @@ public class SQLErrorCodeSQLExceptionTranslator extends AbstractFallbackSQLExcep
@@ -359,39 +360,45 @@ public class SQLErrorCodeSQLExceptionTranslator extends AbstractFallbackSQLExcep
// invoke constructor
Constructor < ? > exceptionConstructor ;
switch ( constructorType ) {
case MESSAGE_SQL_SQLEX_CONSTRUCTOR :
return switch ( constructorType ) {
case MESSAGE_SQL_SQLEX_CONSTRUCTOR - > {
Class < ? > [ ] messageAndSqlAndSqlExArgsClass = new Class < ? > [ ] { String . class , String . class , SQLException . class } ;
Object [ ] messageAndSqlAndSqlExArgs = new Object [ ] { task , sql , sqlEx } ;
exceptionConstructor = exceptionClass . getConstructor ( messageAndSqlAndSqlExArgsClass ) ;
return ( DataAccessException ) exceptionConstructor . newInstance ( messageAndSqlAndSqlExArgs ) ;
case MESSAGE_SQL_THROWABLE_CONSTRUCTOR :
yield ( DataAccessException ) exceptionConstructor . newInstance ( messageAndSqlAndSqlExArgs ) ;
}
case MESSAGE_SQL_THROWABLE_CONSTRUCTOR - > {
Class < ? > [ ] messageAndSqlAndThrowableArgsClass = new Class < ? > [ ] { String . class , String . class , Throwable . class } ;
Object [ ] messageAndSqlAndThrowableArgs = new Object [ ] { task , sql , sqlEx } ;
exceptionConstructor = exceptionClass . getConstructor ( messageAndSqlAndThrowableArgsClass ) ;
return ( DataAccessException ) exceptionConstructor . newInstance ( messageAndSqlAndThrowableArgs ) ;
case MESSAGE_SQLEX_CONSTRUCTOR :
yield ( DataAccessException ) exceptionConstructor . newInstance ( messageAndSqlAndThrowableArgs ) ;
}
case MESSAGE_SQLEX_CONSTRUCTOR - > {
Class < ? > [ ] messageAndSqlExArgsClass = new Class < ? > [ ] { String . class , SQLException . class } ;
Object [ ] messageAndSqlExArgs = new Object [ ] { task + ": " + sqlEx . getMessage ( ) , sqlEx } ;
exceptionConstructor = exceptionClass . getConstructor ( messageAndSqlExArgsClass ) ;
return ( DataAccessException ) exceptionConstructor . newInstance ( messageAndSqlExArgs ) ;
case MESSAGE_THROWABLE_CONSTRUCTOR :
yield ( DataAccessException ) exceptionConstructor . newInstance ( messageAndSqlExArgs ) ;
}
case MESSAGE_THROWABLE_CONSTRUCTOR - > {
Class < ? > [ ] messageAndThrowableArgsClass = new Class < ? > [ ] { String . class , Throwable . class } ;
Object [ ] messageAndThrowableArgs = new Object [ ] { task + ": " + sqlEx . getMessage ( ) , sqlEx } ;
exceptionConstructor = exceptionClass . getConstructor ( messageAndThrowableArgsClass ) ;
return ( DataAccessException ) exceptionConstructor . newInstance ( messageAndThrowableArgs ) ;
case MESSAGE_ONLY_CONSTRUCTOR :
yield ( DataAccessException ) exceptionConstructor . newInstance ( messageAndThrowableArgs ) ;
}
case MESSAGE_ONLY_CONSTRUCTOR - > {
Class < ? > [ ] messageOnlyArgsClass = new Class < ? > [ ] { String . class } ;
Object [ ] messageOnlyArgs = new Object [ ] { task + ": " + sqlEx . getMessage ( ) } ;
exceptionConstructor = exceptionClass . getConstructor ( messageOnlyArgsClass ) ;
return ( DataAccessException ) exceptionConstructor . newInstance ( messageOnlyArgs ) ;
default :
yield ( DataAccessException ) exceptionConstructor . newInstance ( messageOnlyArgs ) ;
}
default - > {
if ( logger . isWarnEnabled ( ) ) {
logger . warn ( "Unable to find appropriate constructor of custom exception class [" +
exceptionClass . getName ( ) + "]" ) ;
}
return null ;
yield null ;
}
} ;
}
catch ( Throwable ex ) {
if ( logger . isWarnEnabled ( ) ) {