60
60
* of the class path (e.g. in the "/WEB-INF/classes" directory), as long as the
61
61
* Spring JDBC package is loaded from the same ClassLoader.
62
62
*
63
+ * <p>This translator is commonly used by default if a user-provided `sql-error-codes.xml`
64
+ * file has been found in the root of the classpath, as a signal to use this strategy.
65
+ * Otherwise, {@link SQLExceptionSubclassTranslator} serves as the default translator
66
+ * as of 6.0.
67
+ *
63
68
* @author Rod Johnson
64
69
* @author Thomas Risberg
65
70
* @author Juergen Hoeller
@@ -75,11 +80,10 @@ public class SQLErrorCodeSQLExceptionTranslator extends AbstractFallbackSQLExcep
75
80
private static final int MESSAGE_SQL_THROWABLE_CONSTRUCTOR = 4 ;
76
81
private static final int MESSAGE_SQL_SQLEX_CONSTRUCTOR = 5 ;
77
82
78
- private static final boolean USER_PROVIDED_ERROR_CODES_FILE_PRESENT =
79
- new ClassPathResource (SQLErrorCodesFactory .SQL_ERROR_CODE_OVERRIDE_PATH , SQLErrorCodesFactory . class . getClassLoader ()). exists ();
80
-
83
+ private static final boolean userProvidedErrorCodesFilePresent =
84
+ new ClassPathResource (SQLErrorCodesFactory .SQL_ERROR_CODE_OVERRIDE_PATH ,
85
+ SQLErrorCodesFactory . class . getClassLoader ()). exists ();
81
86
82
- /** Error codes used by this translator. */
83
87
@ Nullable
84
88
private SingletonSupplier <SQLErrorCodes > sqlErrorCodes ;
85
89
@@ -198,9 +202,9 @@ protected DataAccessException doTranslate(String task, @Nullable String sql, SQL
198
202
if (sqlErrorCodes != null ) {
199
203
SQLExceptionTranslator customTranslator = sqlErrorCodes .getCustomSqlExceptionTranslator ();
200
204
if (customTranslator != null ) {
201
- DataAccessException customDex = customTranslator .translate (task , sql , sqlEx );
202
- if (customDex != null ) {
203
- return customDex ;
205
+ dae = customTranslator .translate (task , sql , sqlEx );
206
+ if (dae != null ) {
207
+ return dae ;
204
208
}
205
209
}
206
210
}
@@ -228,11 +232,10 @@ protected DataAccessException doTranslate(String task, @Nullable String sql, SQL
228
232
for (CustomSQLErrorCodesTranslation customTranslation : customTranslations ) {
229
233
if (Arrays .binarySearch (customTranslation .getErrorCodes (), errorCode ) >= 0 &&
230
234
customTranslation .getExceptionClass () != null ) {
231
- DataAccessException customException = createCustomException (
232
- task , sql , sqlEx , customTranslation .getExceptionClass ());
233
- if (customException != null ) {
235
+ dae = createCustomException (task , sql , sqlEx , customTranslation .getExceptionClass ());
236
+ if (dae != null ) {
234
237
logTranslation (task , sql , sqlEx , true );
235
- return customException ;
238
+ return dae ;
236
239
}
237
240
}
238
241
}
@@ -306,7 +309,9 @@ else if (Arrays.binarySearch(sqlErrorCodes.getCannotSerializeTransactionCodes(),
306
309
* resulting from custom translation. This exception should include the {@code sqlEx} parameter
307
310
* as a nested root cause. This implementation always returns {@code null}, meaning that the
308
311
* translator always falls back to the default error codes.
312
+ * @deprecated as of 6.1, in favor of {@link #setCustomTranslator}
309
313
*/
314
+ @ Deprecated (since = "6.1" )
310
315
@ Nullable
311
316
protected DataAccessException customTranslate (String task , @ Nullable String sql , SQLException sqlEx ) {
312
317
return null ;
@@ -426,7 +431,7 @@ private void logTranslation(String task, @Nullable String sql, SQLException sqlE
426
431
* in the root of the classpath.
427
432
*/
428
433
static boolean hasUserProvidedErrorCodesFile () {
429
- return USER_PROVIDED_ERROR_CODES_FILE_PRESENT ;
434
+ return userProvidedErrorCodesFilePresent ;
430
435
}
431
436
432
437
}
0 commit comments