camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [2/2] git commit: CAMEL-7269: Added option joinTransaction to camel-jpa to allow to turn this off in case jpa provider does not work with that for RESOURCE_LOCAL which seems to be a problem for EclipseLink.
Date Wed, 12 Mar 2014 16:21:06 GMT
CAMEL-7269: Added option joinTransaction to camel-jpa to allow to turn this off in case jpa
provider does not work with that for RESOURCE_LOCAL which seems to be a problem for EclipseLink.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/709595fc
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/709595fc
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/709595fc

Branch: refs/heads/camel-2.12.x
Commit: 709595fcc1936953a596920e01715f43b7f19396
Parents: e170feb
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Wed Mar 12 17:22:53 2014 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Wed Mar 12 17:23:36 2014 +0100

----------------------------------------------------------------------
 .../camel/component/jpa/JpaComponent.java       | 11 +++++++++-
 .../apache/camel/component/jpa/JpaConsumer.java |  4 +++-
 .../apache/camel/component/jpa/JpaEndpoint.java |  9 +++++++++
 .../apache/camel/component/jpa/JpaProducer.java |  8 ++++++--
 .../idempotent/jpa/JpaMessageIdRepository.java  | 21 +++++++++++++++++---
 5 files changed, 46 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/709595fc/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaComponent.java
b/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaComponent.java
index de38f9a..3b0cae5 100644
--- a/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaComponent.java
+++ b/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaComponent.java
@@ -36,6 +36,7 @@ public class JpaComponent extends DefaultComponent {
     private static final Logger LOG = LoggerFactory.getLogger(JpaComponent.class);
     private EntityManagerFactory entityManagerFactory;
     private PlatformTransactionManager transactionManager;
+    private boolean joinTransaction = true;
 
     // Properties
     //-------------------------------------------------------------------------
@@ -61,6 +62,7 @@ public class JpaComponent extends DefaultComponent {
     @Override
     protected Endpoint createEndpoint(String uri, String path, Map<String, Object>
options) throws Exception {
         JpaEndpoint endpoint = new JpaEndpoint(uri, this);
+        endpoint.setJoinTransaction(isJoinTransaction());
 
         // lets interpret the next string as a class
         if (ObjectHelper.isNotEmpty(path)) {
@@ -71,7 +73,6 @@ public class JpaComponent extends DefaultComponent {
                 endpoint.setEntityType(type);
             }
         }
-
         return endpoint;
     }
 
@@ -133,4 +134,12 @@ public class JpaComponent extends DefaultComponent {
             LOG.warn("No TransactionManager has been configured on this JpaComponent. Each
JpaEndpoint will auto create their own JpaTransactionManager.");
         }
     }
+
+    public boolean isJoinTransaction() {
+        return joinTransaction;
+    }
+
+    public void setJoinTransaction(boolean joinTransaction) {
+        this.joinTransaction = joinTransaction;
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/709595fc/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaConsumer.java
b/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaConsumer.java
index 3d5a03f..9dadbe4 100644
--- a/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaConsumer.java
+++ b/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaConsumer.java
@@ -79,7 +79,9 @@ public class JpaConsumer extends ScheduledBatchPollingConsumer {
 
         Object messagePolled = transactionTemplate.execute(new TransactionCallback<Object>()
{
             public Object doInTransaction(TransactionStatus status) {
-                entityManager.joinTransaction();
+                if (getEndpoint().isJoinTransaction()) {
+                    entityManager.joinTransaction();
+                }
 
                 Queue<DataHolder> answer = new LinkedList<DataHolder>();
 

http://git-wip-us.apache.org/repos/asf/camel/blob/709595fc/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaEndpoint.java
b/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaEndpoint.java
index 97d7fdc..4d8eb00 100644
--- a/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaEndpoint.java
+++ b/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaEndpoint.java
@@ -53,6 +53,7 @@ public class JpaEndpoint extends ScheduledPollEndpoint {
     private boolean flushOnSend = true;
     private int maxMessagesPerPoll;
     private boolean usePersist;
+    private boolean joinTransaction = true;
 
     public JpaEndpoint() {
     }
@@ -241,6 +242,14 @@ public class JpaEndpoint extends ScheduledPollEndpoint {
         this.usePersist = usePersist;
     }
 
+    public boolean isJoinTransaction() {
+        return joinTransaction;
+    }
+
+    public void setJoinTransaction(boolean joinTransaction) {
+        this.joinTransaction = joinTransaction;
+    }
+
     // Implementation methods
     // -------------------------------------------------------------------------
 

http://git-wip-us.apache.org/repos/asf/camel/blob/709595fc/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaProducer.java
b/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaProducer.java
index 202f1d9..8afb038 100644
--- a/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaProducer.java
+++ b/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaProducer.java
@@ -57,7 +57,9 @@ public class JpaProducer extends DefaultProducer {
         if (values != null) {
             transactionTemplate.execute(new TransactionCallback<Object>() {
                 public Object doInTransaction(TransactionStatus status) {
-                    entityManager.joinTransaction();
+                    if (getEndpoint().isJoinTransaction()) {
+                        entityManager.joinTransaction();
+                    }
                     if (values.getClass().isArray()) {
                         Object[] array = (Object[])values;
                         for (int index = 0; index < array.length; index++) {
@@ -77,7 +79,9 @@ public class JpaProducer extends DefaultProducer {
 
                     if (getEndpoint().isFlushOnSend()) {
                         // there may be concurrency so need to join tx before flush
-                        entityManager.joinTransaction();
+                        if (getEndpoint().isJoinTransaction()) {
+                            entityManager.joinTransaction();
+                        }
                         entityManager.flush();
                     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/709595fc/components/camel-jpa/src/main/java/org/apache/camel/processor/idempotent/jpa/JpaMessageIdRepository.java
----------------------------------------------------------------------
diff --git a/components/camel-jpa/src/main/java/org/apache/camel/processor/idempotent/jpa/JpaMessageIdRepository.java
b/components/camel-jpa/src/main/java/org/apache/camel/processor/idempotent/jpa/JpaMessageIdRepository.java
index 78c2084..e0989f2 100644
--- a/components/camel-jpa/src/main/java/org/apache/camel/processor/idempotent/jpa/JpaMessageIdRepository.java
+++ b/components/camel-jpa/src/main/java/org/apache/camel/processor/idempotent/jpa/JpaMessageIdRepository.java
@@ -44,6 +44,7 @@ public class JpaMessageIdRepository extends ServiceSupport implements Idempotent
     private final String processorName;
     private final EntityManager entityManager;
     private final TransactionTemplate transactionTemplate;
+    private boolean joinTransaction = true;
 
     public JpaMessageIdRepository(EntityManagerFactory entityManagerFactory, String processorName)
{
         this(entityManagerFactory, createTransactionTemplate(entityManagerFactory), processorName);
@@ -75,7 +76,9 @@ public class JpaMessageIdRepository extends ServiceSupport implements Idempotent
         // Run this in single transaction.
         Boolean rc = transactionTemplate.execute(new TransactionCallback<Boolean>()
{
             public Boolean doInTransaction(TransactionStatus arg0) {
-                entityManager.joinTransaction();
+                if (isJoinTransaction()) {
+                    entityManager.joinTransaction();
+                }
 
                 List<?> list = query(messageId);
                 if (list.isEmpty()) {
@@ -99,7 +102,9 @@ public class JpaMessageIdRepository extends ServiceSupport implements Idempotent
         // Run this in single transaction.
         Boolean rc = transactionTemplate.execute(new TransactionCallback<Boolean>()
{
             public Boolean doInTransaction(TransactionStatus arg0) {
-                entityManager.joinTransaction();
+                if (isJoinTransaction()) {
+                    entityManager.joinTransaction();
+                }
 
                 List<?> list = query(messageId);
                 if (list.isEmpty()) {
@@ -116,7 +121,9 @@ public class JpaMessageIdRepository extends ServiceSupport implements
Idempotent
     public boolean remove(final String messageId) {
         Boolean rc = transactionTemplate.execute(new TransactionCallback<Boolean>()
{
             public Boolean doInTransaction(TransactionStatus arg0) {
-                entityManager.joinTransaction();
+                if (isJoinTransaction()) {
+                    entityManager.joinTransaction();
+                }
 
                 List<?> list = query(messageId);
                 if (list.isEmpty()) {
@@ -149,6 +156,14 @@ public class JpaMessageIdRepository extends ServiceSupport implements
Idempotent
         return processorName;
     }
 
+    public boolean isJoinTransaction() {
+        return joinTransaction;
+    }
+
+    public void setJoinTransaction(boolean joinTransaction) {
+        this.joinTransaction = joinTransaction;
+    }
+
     @Override
     protected void doStart() throws Exception {
     }


Mime
View raw message