gnodet-bot commented on code in PR #30531:
URL: https://github.com/apache/camel/pull/30531#discussion_r4651444386
##########
components/camel-jpa/src/main/java/org/apache/camel/processor/idempotent/jpa/JpaMessageIdRepository.java:
##########
@@ -109,26 +163,40 @@ public boolean add(final Exchange exchange, final String
messageId) {
}
} catch (Exception ex) {
if (isConstraintViolation(ex)) {
- // concurrent insert of the same messageId detected via
unique constraint
- // treat as duplicate rather than failing the exchange
- LOG.debug("Duplicate message detected during concurrent
insert: {}", messageId);
- rc[0] = Boolean.FALSE;
+ // possibly a concurrent insert of the same messageId: add
checks it in a new transaction
+ violation[0] = ex;
} else {
String contextInfo = String.format(SOMETHING_WENT_WRONG,
ex.getMessage());
throw new PersistenceException(contextInfo, ex);
}
} finally {
- try {
- if (entityManager.isOpen()) {
- entityManager.close();
- }
- } catch (Exception e) {
- // ignore
- }
+ closeEntityManager(entityManager);
}
});
+ }
- LOG.debug("add {} -> {}", messageId, rc[0]);
+ /**
+ * Whether the message id is in the repository, read in a new transaction
after the one of the insert, or in the
Review Comment:
💡 **Readability suggestion**: The Javadoc packs two distinct scenarios into
a single complex sentence, making it harder to parse at a glance. Consider
splitting the two cases:
```suggestion
* Whether the message id is in the repository.
* <p>
* When called outside of a transaction: reads in a new transaction
after the insert completes,
* using a new EntityManager.
* When called inside a transaction: reads in the caller's transaction;
uses the shared
* EntityManager if one is configured, otherwise creates a new
EntityManager that joins the transaction.
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]