This is an automated email from the ASF dual-hosted git repository. acosentino pushed a commit to branch camel-2.x in repository https://gitbox.apache.org/repos/asf/camel.git
commit 7e9438e5ef84a2c21803992d58d94f497b8be222 Author: Amos Feng <zf...@redhat.com> AuthorDate: Thu May 23 11:11:39 2019 +0800 [CAMEL-13529] Update to make sure the camel-jdbc work with the spring tx manager --- components/camel-jdbc/pom.xml | 10 +++++----- .../java/org/apache/camel/component/jdbc/JdbcProducer.java | 6 +++--- platforms/karaf/features/src/main/resources/features.xml | 1 + 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/components/camel-jdbc/pom.xml b/components/camel-jdbc/pom.xml index 5406016..2c72072 100644 --- a/components/camel-jdbc/pom.xml +++ b/components/camel-jdbc/pom.xml @@ -41,6 +41,11 @@ <groupId>org.apache.camel</groupId> <artifactId>camel-core</artifactId> </dependency> + <!-- it needs to ensure transaction support works with Spring and JEE --> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-jdbc</artifactId> + </dependency> <!-- test dependencies --> <dependency> @@ -54,11 +59,6 @@ <scope>test</scope> </dependency> <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-jdbc</artifactId> - <scope>test</scope> - </dependency> - <dependency> <groupId>org.apache.derby</groupId> <artifactId>derby</artifactId> <scope>test</scope> diff --git a/components/camel-jdbc/src/main/java/org/apache/camel/component/jdbc/JdbcProducer.java b/components/camel-jdbc/src/main/java/org/apache/camel/component/jdbc/JdbcProducer.java index 0406930..bd8243f 100644 --- a/components/camel-jdbc/src/main/java/org/apache/camel/component/jdbc/JdbcProducer.java +++ b/components/camel-jdbc/src/main/java/org/apache/camel/component/jdbc/JdbcProducer.java @@ -77,7 +77,7 @@ public class JdbcProducer extends DefaultProducer { boolean shouldCloseResources = true; try { - conn = dataSource.getConnection(); + conn = DataSourceUtils.getConnection(dataSource); autoCommit = conn.getAutoCommit(); if (autoCommit) { conn.setAutoCommit(false); @@ -109,10 +109,10 @@ public class JdbcProducer extends DefaultProducer { boolean shouldCloseResources = true; try { - conn = dataSource.getConnection(); + conn = DataSourceUtils.getConnection(dataSource); shouldCloseResources = createAndExecuteSqlStatement(exchange, sql, conn); } finally { - if (shouldCloseResources) { + if (shouldCloseResources && !DataSourceUtils.isConnectionTransactional(conn, dataSource) { closeQuietly(conn); } } diff --git a/platforms/karaf/features/src/main/resources/features.xml b/platforms/karaf/features/src/main/resources/features.xml index d80b16a..8bf808c 100644 --- a/platforms/karaf/features/src/main/resources/features.xml +++ b/platforms/karaf/features/src/main/resources/features.xml @@ -1246,6 +1246,7 @@ </feature> <feature name='camel-jdbc' version='${project.version}' resolver='(obr)' start-level='50'> <feature version='${project.version}'>camel-core</feature> + <feature version='${spring-version-range}'>spring-jdbc</feature> <bundle>mvn:org.apache.camel/camel-jdbc/${project.version}</bundle> </feature> <feature name='camel-jetty9' version='${project.version}' resolver='(obr)' start-level='50'>