camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject git commit: CAMEL-6144: Added support for optimistick locking in JDBC based aggregation repository.
Date Wed, 24 Jul 2013 12:00:33 GMT
Updated Branches:
  refs/heads/master 0be323f0d -> 12186266c


CAMEL-6144: Added support for optimistick locking in JDBC based aggregation repository.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/12186266
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/12186266
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/12186266

Branch: refs/heads/master
Commit: 12186266cef2b9fd627a99d7b191f07901d763b7
Parents: 0be323f
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Wed Jul 24 13:54:21 2013 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Wed Jul 24 13:54:21 2013 +0200

----------------------------------------------------------------------
 ...ultJdbcOptimisticLockingExceptionMapper.java | 28 ++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/12186266/components/camel-sql/src/main/java/org/apache/camel/processor/aggregate/jdbc/DefaultJdbcOptimisticLockingExceptionMapper.java
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/main/java/org/apache/camel/processor/aggregate/jdbc/DefaultJdbcOptimisticLockingExceptionMapper.java
b/components/camel-sql/src/main/java/org/apache/camel/processor/aggregate/jdbc/DefaultJdbcOptimisticLockingExceptionMapper.java
index 805397f..ed3c8fb 100644
--- a/components/camel-sql/src/main/java/org/apache/camel/processor/aggregate/jdbc/DefaultJdbcOptimisticLockingExceptionMapper.java
+++ b/components/camel-sql/src/main/java/org/apache/camel/processor/aggregate/jdbc/DefaultJdbcOptimisticLockingExceptionMapper.java
@@ -16,17 +16,25 @@
  */
 package org.apache.camel.processor.aggregate.jdbc;
 
+import java.sql.SQLException;
 import java.util.Iterator;
 import java.util.LinkedHashSet;
 import java.util.Set;
 
 import org.apache.camel.util.ObjectHelper;
+import org.springframework.dao.DataIntegrityViolationException;
 
 /**
  * A default {@link JdbcOptimisticLockingExceptionMapper} which checks the caused exception
(and its nested)
- * whether any of them has <tt>ConstraintViolation</tt> in the class name. If
there is such a class name
- * then {@link #isOptimisticLocking(Exception)} returns <tt>true</tt>.
+ * whether any of them is a constraint violation exception.
  * <p/>
+ * The following check is done:
+ * <ul>
+ *     <li>If the caused exception is an {@link SQLException}</li> then the SQLState
is checked if starts with <tt>23</tt>.
+ *     <li>If the caused exception is a {@link DataIntegrityViolationException}</li>
+ *     <li>If the caused exception class name has <tt>ConstraintViolation</tt></li>
in its name.
+ *     <li>optional checking for FQN class name matches if any class names has been
configured</li>
+ * </ul>
  * In addition you can add FQN classnames using the {@link #addClassName(String)} or {@link
#setClassNames(java.util.Set)}
  * methods. These class names is also matched. This allows to add vendor specific exception
classes.
  */
@@ -38,6 +46,18 @@ public class DefaultJdbcOptimisticLockingExceptionMapper implements JdbcOptimist
     public boolean isOptimisticLocking(Exception cause) {
         Iterator<Throwable> it = ObjectHelper.createExceptionIterator(cause);
         while (it.hasNext()) {
+            // if its a SQL exception
+            if (it instanceof SQLException) {
+                SQLException se = (SQLException) it;
+                if (isConstraintViolation(se)) {
+                    return true;
+                }
+            }
+            if (it instanceof DataIntegrityViolationException) {
+                return true;
+            }
+
+            // fallback to names
             String name = it.next().getClass().getName();
             if (name.contains("ConstraintViolation") || hasClassName(name)) {
                 return true;
@@ -47,6 +67,10 @@ public class DefaultJdbcOptimisticLockingExceptionMapper implements JdbcOptimist
         return false;
     }
 
+    public static boolean isConstraintViolation(SQLException e) {
+        return e.getSQLState().startsWith("23");
+    }
+
     private boolean hasClassName(String name) {
         for (String className : classNames) {
             if (className.equals(name)) {


Mime
View raw message