@@ -70,6 +70,11 @@ public class SQLStateSQLExceptionTranslator extends AbstractFallbackSQLException
70
70
"44" // With check violation
71
71
);
72
72
73
+ private static final Set <String > PESSIMISTIC_LOCKING_FAILURE_CODES = Set .of (
74
+ "40" , // Transaction rollback
75
+ "61" // Oracle: deadlock
76
+ );
77
+
73
78
private static final Set <String > DATA_ACCESS_RESOURCE_FAILURE_CODES = Set .of (
74
79
"08" , // Connection exception
75
80
"53" , // PostgreSQL: insufficient resources (for example, disk full)
@@ -84,11 +89,6 @@ public class SQLStateSQLExceptionTranslator extends AbstractFallbackSQLException
84
89
"S1" // DB2: communication failure
85
90
);
86
91
87
- private static final Set <String > PESSIMISTIC_LOCKING_FAILURE_CODES = Set .of (
88
- "40" , // Transaction rollback
89
- "61" // Oracle: deadlock
90
- );
91
-
92
92
private static final Set <Integer > DUPLICATE_KEY_ERROR_CODES = Set .of (
93
93
1 , // Oracle
94
94
301 , // SAP HANA
@@ -117,18 +117,21 @@ else if (DATA_INTEGRITY_VIOLATION_CODES.contains(classCode)) {
117
117
}
118
118
return new DataIntegrityViolationException (buildMessage (task , sql , ex ), ex );
119
119
}
120
- else if (DATA_ACCESS_RESOURCE_FAILURE_CODES .contains (classCode )) {
121
- return new DataAccessResourceFailureException (buildMessage (task , sql , ex ), ex );
122
- }
123
- else if (TRANSIENT_DATA_ACCESS_RESOURCE_CODES .contains (classCode )) {
124
- return new TransientDataAccessResourceException (buildMessage (task , sql , ex ), ex );
125
- }
126
120
else if (PESSIMISTIC_LOCKING_FAILURE_CODES .contains (classCode )) {
127
121
if (indicatesCannotAcquireLock (sqlState )) {
128
122
return new CannotAcquireLockException (buildMessage (task , sql , ex ), ex );
129
123
}
130
124
return new PessimisticLockingFailureException (buildMessage (task , sql , ex ), ex );
131
125
}
126
+ else if (DATA_ACCESS_RESOURCE_FAILURE_CODES .contains (classCode )) {
127
+ if (indicatesQueryTimeout (sqlState )) {
128
+ return new QueryTimeoutException (buildMessage (task , sql , ex ), ex );
129
+ }
130
+ return new DataAccessResourceFailureException (buildMessage (task , sql , ex ), ex );
131
+ }
132
+ else if (TRANSIENT_DATA_ACCESS_RESOURCE_CODES .contains (classCode )) {
133
+ return new TransientDataAccessResourceException (buildMessage (task , sql , ex ), ex );
134
+ }
132
135
}
133
136
134
137
// For MySQL: exception class name indicating a timeout?
@@ -184,4 +187,13 @@ static boolean indicatesCannotAcquireLock(@Nullable String sqlState) {
184
187
return "40001" .equals (sqlState );
185
188
}
186
189
190
+ /**
191
+ * Check whether the given SQL state indicates a {@link QueryTimeoutException},
192
+ * with SQL state 57014 as a specific indication.
193
+ * @param sqlState the SQL state value
194
+ */
195
+ static boolean indicatesQueryTimeout (@ Nullable String sqlState ) {
196
+ return "57014" .equals (sqlState );
197
+ }
198
+
187
199
}
0 commit comments