davsclaus commented on code in PR #29629:
URL: https://github.com/apache/camel/pull/29629#discussion_r4538410788
##########
core/camel-core-reifier/src/main/java/org/apache/camel/reifier/AbstractPolicyReifier.java:
##########
@@ -119,4 +129,34 @@ public Policy resolvePolicy(Policy policy, String ref,
Class<? extends Policy> t
return answer;
}
+
+ /**
+ * A local transaction manager for the one DataSource of the registry,
when the registry has no transaction manager,
+ * as with Camel Main and camel run (CAMEL-26851). It is bound as
transactionManager, so the other transacted routes
+ * use it too. Null without exactly one DataSource, or without spring-jdbc
on the classpath.
+ */
+ private Object localTransactionManager(Class<?> tmClazz) {
+ Class<?> dsClazz =
camelContext.getClassResolver().resolveClass("javax.sql.DataSource");
+ Class<?> jtmClazz = camelContext.getClassResolver()
+
.resolveClass("org.springframework.jdbc.support.JdbcTransactionManager");
+ if (dsClazz == null || jtmClazz == null ||
!tmClazz.isAssignableFrom(jtmClazz)) {
+ return null;
+ }
+ Set<?> dataSources = camelContext.getRegistry().findByType(dsClazz);
+ if (dataSources.size() != 1) {
+ return null;
+ }
+ Object dataSource = dataSources.iterator().next();
+ Object transactionManager;
+ try {
+ transactionManager =
jtmClazz.getConstructor(dsClazz).newInstance(dataSource);
+ } catch (Exception e) {
+ throw new RuntimeCamelException("Cannot create a
JdbcTransactionManager for the DataSource: " + dataSource, e);
+ }
+ if (camelContext.getRegistry().lookupByName("transactionManager") ==
null) {
+ camelContext.getRegistry().bind("transactionManager",
transactionManager);
+ }
+ LOG.info("Using a local JdbcTransactionManager for transacted routes,
with the DataSource: {}", dataSource);
Review Comment:
Fixed in 9ef69fb67781: the INFO log is now inside the `if`, so it only shows
when the local transaction manager is bound as `transactionManager`. When
another bean already holds that name, a DEBUG line says the local one is used
for this route only.
_Claude Code on behalf of
##########
core/camel-core-reifier/src/main/java/org/apache/camel/reifier/AbstractPolicyReifier.java:
##########
@@ -119,4 +129,34 @@ public Policy resolvePolicy(Policy policy, String ref,
Class<? extends Policy> t
return answer;
}
+
+ /**
+ * A local transaction manager for the one DataSource of the registry,
when the registry has no transaction manager,
+ * as with Camel Main and camel run (CAMEL-26851). It is bound as
transactionManager, so the other transacted routes
+ * use it too. Null without exactly one DataSource, or without spring-jdbc
on the classpath.
+ */
+ private Object localTransactionManager(Class<?> tmClazz) {
+ Class<?> dsClazz =
camelContext.getClassResolver().resolveClass("javax.sql.DataSource");
+ Class<?> jtmClazz = camelContext.getClassResolver()
+
.resolveClass("org.springframework.jdbc.support.JdbcTransactionManager");
+ if (dsClazz == null || jtmClazz == null ||
!tmClazz.isAssignableFrom(jtmClazz)) {
+ return null;
+ }
+ Set<?> dataSources = camelContext.getRegistry().findByType(dsClazz);
+ if (dataSources.size() != 1) {
+ return null;
+ }
+ Object dataSource = dataSources.iterator().next();
+ Object transactionManager;
+ try {
+ transactionManager =
jtmClazz.getConstructor(dsClazz).newInstance(dataSource);
+ } catch (Exception e) {
+ throw new RuntimeCamelException("Cannot create a
JdbcTransactionManager for the DataSource: " + dataSource, e);
+ }
+ if (camelContext.getRegistry().lookupByName("transactionManager") ==
null) {
+ camelContext.getRegistry().bind("transactionManager",
transactionManager);
+ }
+ LOG.info("Using a local JdbcTransactionManager for transacted routes,
with the DataSource: {}", dataSource);
Review Comment:
Fixed in 9ef69fb67781: the INFO log is now inside the `if`, so it only shows
when the local transaction manager is bound as `transactionManager`. When
another bean already holds that name, a DEBUG line says the local one is used
for this route only.
_Claude Code on behalf of
--
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]