jiriOndrusek-agent commented on code in PR #28496:
URL: https://github.com/apache/camel/pull/28496#discussion_r4413061998


##########
components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaHelper.java:
##########
@@ -83,6 +88,34 @@ public static EntityManager getTargetEntityManager(
         return em;
     }
 
+    /**
+     * Gets the {@link TransactionStrategy} to use when none has been 
configured: the single {@link TransactionStrategy}
+     * in the registry if there is one and autowiring is enabled, otherwise a 
new {@link DefaultTransactionStrategy} (a
+     * WARN is logged when the registry has more than one).
+     *
+     * @param  camelContext         the camel context, or <tt>null</tt> if not 
available (then the registry is not used)
+     * @param  entityManagerFactory the entity manager factory
+     * @param  autowiredEnabled     whether autowiring is enabled (otherwise 
the registry is not used)
+     * @return                      the transaction strategy (is never null)
+     */
+    public static TransactionStrategy resolveTransactionStrategy(
+            CamelContext camelContext, EntityManagerFactory 
entityManagerFactory, boolean autowiredEnabled) {
+        if (camelContext != null && autowiredEnabled) {
+            TransactionStrategy strategy = 
camelContext.getRegistry().findSingleByType(TransactionStrategy.class);
+            if (strategy != null) {
+                LOG.info("Using TransactionStrategy found in registry: {}", 
strategy);
+                return strategy;

Review Comment:
   Agreed, it is `LOG.debug` now (a6750d43b1). I made the change by hand: this 
suggestion sits on line 107 (`return strategy;`), so committing it from the UI 
would drop the `return`, and the bean from the registry would be ignored.
   
   I checked when the line runs, with DEBUG logs and jdb on a small reproducer:
   - In the usual setup, the context creates the component. Autowiring sets the 
option first and logs the bean at INFO (`LifecycleStrategySupport.java:264`), 
then `JpaComponent.java:180` logs it at INFO again. This line is not reached 
there, so nothing changes in that case.
   - It runs only when the component or endpoint has no strategy yet: a 
component added with `addComponent(...)` with an `EntityManagerFactory` (once, 
in `JpaComponent.doInit`), or endpoints of a component without a strategy (once 
per endpoint). Endpoint autowiring logs at DEBUG (`DefaultEndpoint.java:512`), 
so DEBUG fits.
   
   Small correction: component autowiring logs at INFO, not DEBUG, and I could 
not find `DefaultCamelContextExtension.autowireProperties`.
   
   _Generated with [Claude Code](https://claude.com/claude-code) on behalf of 
@JiriOndrusek_
   



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