gnodet-bot commented on code in PR #29629:
URL: https://github.com/apache/camel/pull/29629#discussion_r4537323067


##########
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:
   💡 **Nit:** The `LOG.info` fires unconditionally after the `lookupByName` 
guard. When a different bean already holds the `"transactionManager"` name and 
the `bind` is skipped, the message *"Using a local JdbcTransactionManager"* is 
still logged, while the registry still holds the other bean. Consider moving 
the log inside the `if`-block, or rewording it to reflect that the TM was 
created (not necessarily registered).
   
   ```suggestion
           if (camelContext.getRegistry().lookupByName("transactionManager") == 
null) {
               camelContext.getRegistry().bind("transactionManager", 
transactionManager);
               LOG.info("Using a local JdbcTransactionManager for transacted 
routes, with the DataSource: {}", dataSource);
           }
   ```



-- 
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]

Reply via email to