You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2019/05/22 14:18:02 UTC
[camel] branch master updated: [CAMEL-13529][ENTESB-10671] Update
to make sure the camel-jdbc work with the spring tx manager
This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new 40d454d [CAMEL-13529][ENTESB-10671] Update to make sure the camel-jdbc work with the spring tx manager
40d454d is described below
commit 40d454d03194370f5375603043923cf0204483ff
Author: Amos Feng <zf...@redhat.com>
AuthorDate: Tue May 21 15:53:24 2019 +0800
[CAMEL-13529][ENTESB-10671] 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 | 8 +++++---
platforms/karaf/features/src/main/resources/features.xml | 1 +
3 files changed, 11 insertions(+), 8 deletions(-)
diff --git a/components/camel-jdbc/pom.xml b/components/camel-jdbc/pom.xml
index 1ec5638..c0a5c51 100644
--- a/components/camel-jdbc/pom.xml
+++ b/components/camel-jdbc/pom.xml
@@ -41,6 +41,11 @@
<groupId>org.apache.camel</groupId>
<artifactId>camel-support</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 893a965..51493b7 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
@@ -36,6 +36,8 @@ import org.apache.camel.spi.Synchronization;
import org.apache.camel.support.DefaultProducer;
import org.apache.camel.support.IntrospectionSupport;
+import org.springframework.jdbc.datasource.DataSourceUtils;
+
public class JdbcProducer extends DefaultProducer {
private DataSource dataSource;
@@ -72,7 +74,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);
@@ -104,10 +106,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 241a301..afd8ac0 100644
--- a/platforms/karaf/features/src/main/resources/features.xml
+++ b/platforms/karaf/features/src/main/resources/features.xml
@@ -1436,6 +1436,7 @@
</feature>
<feature name='camel-jdbc' version='${project.version}' 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-jetty' version='${project.version}' start-level='50'>