camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [1/2] git commit: CAMEL-6681: Allow to configure lock mode on jpa consumer. Thanks to Bart De Neuter for the patch.
Date Thu, 29 Aug 2013 10:03:20 GMT
Updated Branches:
  refs/heads/camel-2.11.x b8c850025 -> fc199ac74
  refs/heads/master 82bb28403 -> c1a520dbe


CAMEL-6681: Allow to configure lock mode on jpa consumer. Thanks to Bart De Neuter for the
patch.


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

Branch: refs/heads/master
Commit: c1a520dbe50ecf685ea8af38e34d97e86747d606
Parents: 82bb284
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Thu Aug 29 12:00:11 2013 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Thu Aug 29 12:00:11 2013 +0200

----------------------------------------------------------------------
 .../apache/camel/component/jpa/JpaConsumer.java   | 11 ++++++++++-
 .../camel/component/jpa/JpaComponentTest.java     | 18 ++++++++++++++++--
 2 files changed, 26 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/c1a520db/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 b48b871..8cfd3e8 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
@@ -54,6 +54,7 @@ public class JpaConsumer extends ScheduledBatchPollingConsumer {
     private String query;
     private String namedQuery;
     private String nativeQuery;
+    private LockModeType lockModeType = LockModeType.WRITE;
     private Map<String, Object> parameters;
     private Class<?> resultClass;
     private boolean transacted;
@@ -220,6 +221,14 @@ public class JpaConsumer extends ScheduledBatchPollingConsumer {
         this.namedQuery = namedQuery;
     }
 
+    public LockModeType getLockModeType() {
+        return lockModeType;
+    }
+
+    public void setLockModeType(LockModeType lockModeType) {
+        this.lockModeType = lockModeType;
+    }
+
     public String getNativeQuery() {
         return nativeQuery;
     }
@@ -276,7 +285,7 @@ public class JpaConsumer extends ScheduledBatchPollingConsumer {
         }
         try {
             LOG.debug("Acquiring exclusive lock on entity: {}", entity);
-            entityManager.lock(entity, LockModeType.WRITE);
+            entityManager.lock(entity, lockModeType);
             return true;
         } catch (Exception e) {
             if (LOG.isDebugEnabled()) {

http://git-wip-us.apache.org/repos/asf/camel/blob/c1a520db/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaComponentTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaComponentTest.java
b/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaComponentTest.java
index d487539..614c29a 100644
--- a/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaComponentTest.java
+++ b/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaComponentTest.java
@@ -17,6 +17,7 @@
 package org.apache.camel.component.jpa;
 
 import javax.persistence.EntityManagerFactory;
+import javax.persistence.LockModeType;
 import javax.persistence.Persistence;
 
 import org.apache.camel.examples.SendEmail;
@@ -25,11 +26,24 @@ import org.junit.Test;
 import org.springframework.orm.jpa.JpaTransactionManager;
 
 /**
- * @version 
+ * @version
  */
 public class JpaComponentTest extends CamelTestSupport {
 
     @Test
+    public void testJpaComponentConsumerHasLockModeType() throws Exception {
+        JpaComponent comp = new JpaComponent();
+        comp.setCamelContext(context);
+        assertNull(comp.getEntityManagerFactory());
+        assertNull(comp.getTransactionManager());
+
+        JpaEndpoint jpa = (JpaEndpoint) comp.createEndpoint("jpa://" + SendEmail.class.getName()
+ "?consumer.lockModeType=PESSIMISTIC_WRITE");
+        JpaConsumer consumer = (JpaConsumer) jpa.createConsumer(null);
+
+        assertEquals(consumer.getLockModeType(), LockModeType.PESSIMISTIC_WRITE);
+    }
+
+    @Test
     public void testJpaComponentCtr() throws Exception {
         JpaComponent comp = new JpaComponent();
         comp.setCamelContext(context);
@@ -62,7 +76,7 @@ public class JpaComponentTest extends CamelTestSupport {
         assertNotNull(jpa);
         assertNotNull(jpa.getEntityType());
     }
-    
+
     @Test
     public void testJpaComponentWithPath() throws Exception {
         JpaComponent comp = new JpaComponent();


Mime
View raw message