[camel] branch camel-2.25.x updated: [CAMEL-7810] Use OptimisticLockingException for version conflicts (#3852)

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[camel] branch camel-2.25.x updated: [CAMEL-7810] Use OptimisticLockingException for version conflicts (#3852)

davsclaus-2
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch camel-2.25.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/camel-2.25.x by this push:
     new 91d0627  [CAMEL-7810] Use OptimisticLockingException for version conflicts (#3852)
91d0627 is described below

commit 91d0627823d8ca10a9df2f6fa5c88e005ab67885
Author: Federico Valeri <[hidden email]>
AuthorDate: Fri May 22 14:52:07 2020 +0200

    [CAMEL-7810] Use OptimisticLockingException for version conflicts (#3852)
   
    Co-authored-by: Federico Valeri <fvaleri@localhost>
---
 .../aggregate/jdbc/DefaultJdbcOptimisticLockingExceptionMapper.java   | 4 ++++
 .../camel/processor/aggregate/jdbc/JdbcAggregationRepositoryNew.java  | 4 +++-
 2 files changed, 7 insertions(+), 1 deletion(-)

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 e6903b1..aa22f8c 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
@@ -21,6 +21,7 @@ import java.util.Iterator;
 import java.util.LinkedHashSet;
 import java.util.Set;
 
+import org.apache.camel.spi.OptimisticLockingAggregationRepository.OptimisticLockingException;
 import org.apache.camel.util.ObjectHelper;
 import org.springframework.dao.DataIntegrityViolationException;
 
@@ -47,6 +48,9 @@ public class DefaultJdbcOptimisticLockingExceptionMapper implements JdbcOptimist
         Iterator<Throwable> it = ObjectHelper.createExceptionIterator(cause);
         while (it.hasNext()) {
             Throwable throwable = it.next();
+            if (throwable instanceof OptimisticLockingException) {
+                return true;
+            }
             // if its a SQL exception
             if (throwable instanceof SQLException) {
                 SQLException se = (SQLException) throwable;
diff --git a/components/camel-sql/src/main/java/org/apache/camel/processor/aggregate/jdbc/JdbcAggregationRepositoryNew.java b/components/camel-sql/src/main/java/org/apache/camel/processor/aggregate/jdbc/JdbcAggregationRepositoryNew.java
index d559af8..31fe7c0 100644
--- a/components/camel-sql/src/main/java/org/apache/camel/processor/aggregate/jdbc/JdbcAggregationRepositoryNew.java
+++ b/components/camel-sql/src/main/java/org/apache/camel/processor/aggregate/jdbc/JdbcAggregationRepositoryNew.java
@@ -31,6 +31,7 @@ import javax.sql.DataSource;
 import org.apache.camel.CamelContext;
 import org.apache.camel.Exchange;
 import org.apache.camel.spi.OptimisticLockingAggregationRepository;
+import org.apache.camel.spi.OptimisticLockingAggregationRepository.OptimisticLockingException;
 import org.apache.camel.spi.RecoverableAggregationRepository;
 import org.apache.camel.support.ServiceSupport;
 import org.apache.camel.util.ObjectHelper;
@@ -310,7 +311,8 @@ public class JdbcAggregationRepositoryNew extends ServiceSupport implements Reco
         if (updateCount == 1) {
             return updateCount;
         } else {
-            throw new RuntimeException(String.format("Stale version: error updating record with key %s and version %s", key, version));
+            // Found stale version while updating record
+            throw new OptimisticLockingException();
         }
     }