diff options
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/com/amazon/carbonado/repo/jdbc/JDBCExceptionTransformer.java | 37 | ||||
-rw-r--r-- | src/main/java/com/amazon/carbonado/repo/jdbc/OracleExceptionTransformer.java | 14 |
2 files changed, 51 insertions, 0 deletions
diff --git a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCExceptionTransformer.java b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCExceptionTransformer.java index 9863a69..f72c717 100644 --- a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCExceptionTransformer.java +++ b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCExceptionTransformer.java @@ -21,6 +21,9 @@ package com.amazon.carbonado.repo.jdbc; import java.sql.SQLException;
import com.amazon.carbonado.ConstraintException;
+import com.amazon.carbonado.FetchDeadlockException;
+import com.amazon.carbonado.FetchException;
+import com.amazon.carbonado.PersistDeadlockException;
import com.amazon.carbonado.PersistDeniedException;
import com.amazon.carbonado.PersistException;
import com.amazon.carbonado.UniqueConstraintException;
@@ -51,6 +54,12 @@ class JDBCExceptionTransformer extends ExceptionTransformer { public static String SQLSTATE_UNIQUE_CONSTRAINT_VIOLATION = "23505";
/**
+ * Five digit SQLSTATE code for "Deadlock or timeout with automatic
+ * rollback occurred"
+ */
+ public static String SQLSTATE_DEADLOCK_WITH_ROLLBACK = "40001";
+
+ /**
* Examines the SQLSTATE code of the given SQL exception and determines if
* it is a generic constaint violation.
*/
@@ -84,10 +93,35 @@ class JDBCExceptionTransformer extends ExceptionTransformer { return false;
}
+ public boolean isDeadlockError(SQLException e) {
+ if (e != null) {
+ String sqlstate = e.getSQLState();
+ if (sqlstate != null) {
+ return sqlstate.startsWith(SQLSTATE_DEADLOCK_WITH_ROLLBACK);
+ }
+ }
+ return false;
+ }
+
JDBCExceptionTransformer() {
}
@Override
+ protected FetchException transformIntoFetchException(Throwable e) {
+ FetchException fe = super.transformIntoFetchException(e);
+ if (fe != null) {
+ return fe;
+ }
+ if (e instanceof SQLException) {
+ SQLException se = (SQLException) e;
+ if (isDeadlockError(se)) {
+ return new FetchDeadlockException(e);
+ }
+ }
+ return null;
+ }
+
+ @Override
protected PersistException transformIntoPersistException(Throwable e) {
PersistException pe = super.transformIntoPersistException(e);
if (pe != null) {
@@ -104,6 +138,9 @@ class JDBCExceptionTransformer extends ExceptionTransformer { if (isInsufficientPrivilegesError(se)) {
return new PersistDeniedException(e);
}
+ if (isDeadlockError(se)) {
+ return new PersistDeadlockException(e);
+ }
}
return null;
}
diff --git a/src/main/java/com/amazon/carbonado/repo/jdbc/OracleExceptionTransformer.java b/src/main/java/com/amazon/carbonado/repo/jdbc/OracleExceptionTransformer.java index ccd1011..ad63941 100644 --- a/src/main/java/com/amazon/carbonado/repo/jdbc/OracleExceptionTransformer.java +++ b/src/main/java/com/amazon/carbonado/repo/jdbc/OracleExceptionTransformer.java @@ -30,6 +30,8 @@ class OracleExceptionTransformer extends JDBCExceptionTransformer { public static int INSUFFICIENT_PRIVILEGES = 1031;
+ public static int DEADLOCK_DETECTED = 60;
+
@Override
public boolean isUniqueConstraintError(SQLException e) {
if (isConstraintError(e)) {
@@ -49,4 +51,16 @@ class OracleExceptionTransformer extends JDBCExceptionTransformer { }
return false;
}
+
+ @Override
+ public boolean isDeadlockError(SQLException e) {
+ if (super.isDeadlockError(e)) {
+ return true;
+ }
+ if (e != null) {
+ int errorCode = e.getErrorCode();
+ return DEADLOCK_DETECTED == errorCode;
+ }
+ return false;
+ }
}
|