diff options
author | Brian S. O'Neill <bronee@gmail.com> | 2010-06-04 15:40:17 +0000 |
---|---|---|
committer | Brian S. O'Neill <bronee@gmail.com> | 2010-06-04 15:40:17 +0000 |
commit | 87827c768c2d54cc5e90ba0ecb2342463bce787b (patch) | |
tree | 5b25915004da2425d7e9df47a1f9b19569a5cf62 /src/main/java/com/amazon/carbonado | |
parent | 5796053875ce9fe32da83cc09b73bbd6c76e11c3 (diff) |
Added deadlock detection for JDBC.
Diffstat (limited to 'src/main/java/com/amazon/carbonado')
-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;
+ }
}
|