This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new d5a137e OptimisticLockingException when race condition (#6371)
d5a137e is described below
commit d5a137e30ff0ebab131c9b66ba5ac9cd3d1dc1b0
Author: Benjamin BONNET <[email protected]>
AuthorDate: Wed Nov 3 06:40:24 2021 +0100
OptimisticLockingException when race condition (#6371)
---
.../processor/aggregate/jdbc/JdbcAggregationRepository.java | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git
a/components/camel-sql/src/main/java/org/apache/camel/processor/aggregate/jdbc/JdbcAggregationRepository.java
b/components/camel-sql/src/main/java/org/apache/camel/processor/aggregate/jdbc/JdbcAggregationRepository.java
index cf573fb..5cc88a6 100644
---
a/components/camel-sql/src/main/java/org/apache/camel/processor/aggregate/jdbc/JdbcAggregationRepository.java
+++
b/components/camel-sql/src/main/java/org/apache/camel/processor/aggregate/jdbc/JdbcAggregationRepository.java
@@ -168,9 +168,15 @@ public class JdbcAggregationRepository extends
ServiceSupport
}
if (present) {
- long version = exchange.getProperty(VERSION_PROPERTY,
Long.class);
- LOG.debug("Updating record with key {} and version
{}", key, version);
- update(camelContext, correlationId, exchange,
getRepositoryName(), version);
+ Long versionLong =
exchange.getProperty(VERSION_PROPERTY, Long.class);
+ if (versionLong == null) {
+ LOG.debug("Race while inserting record with key
{}", key);
+ throw new OptimisticLockingException();
+ } else {
+ long version = versionLong.longValue();
+ LOG.debug("Updating record with key {} and version
{}", key, version);
+ update(camelContext, correlationId, exchange,
getRepositoryName(), version);
+ }
} else {
LOG.debug("Inserting record with key {}", key);
insert(camelContext, correlationId, exchange,
getRepositoryName(), 1L);