You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by bv...@apache.org on 2018/10/26 16:08:38 UTC

[camel] branch master updated: polish the camel-jpa codebase a bit

This is an automated email from the ASF dual-hosted git repository.

bvahdat 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 29c7278  polish the camel-jpa codebase a bit
29c7278 is described below

commit 29c7278517037d8b3597ca339ce0bf67e5248119
Author: Babak Vahdat <bv...@apache.org>
AuthorDate: Fri Oct 26 18:08:09 2018 +0200

    polish the camel-jpa codebase a bit
---
 components/camel-jpa/src/main/docs/jpa-component.adoc              | 2 +-
 .../src/main/java/org/apache/camel/component/jpa/JpaEndpoint.java  | 2 +-
 .../src/main/java/org/apache/camel/component/jpa/JpaProducer.java  | 4 ++--
 .../java/org/apache/camel/component/jpa/AbstractJpaMethodTest.java | 2 +-
 .../camel/component/jpa/JpaWithNativeQueryWithResultClassTest.java | 2 +-
 .../camel/processor/jpa/JpaProducerPassingEntityManagerTest.java   | 2 +-
 .../processor/jpa/JpaProducerWithQueryParametersHeaderTest.java    | 7 +++----
 .../src/test/java/org/apache/camel/processor/jpa/JpaRouteTest.java | 2 +-
 8 files changed, 11 insertions(+), 12 deletions(-)

diff --git a/components/camel-jpa/src/main/docs/jpa-component.adoc b/components/camel-jpa/src/main/docs/jpa-component.adoc
index 2e1d4bf..548cb20 100644
--- a/components/camel-jpa/src/main/docs/jpa-component.adoc
+++ b/components/camel-jpa/src/main/docs/jpa-component.adoc
@@ -167,7 +167,7 @@ with the following path and query parameters:
 | *flushOnSend* (producer) | Flushes the EntityManager after the entity bean has been persisted. | true | boolean
 | *remove* (producer) | Indicates to use entityManager.remove(entity). | false | boolean
 | *useExecuteUpdate* (producer) | To configure whether to use executeUpdate() when producer executes a query. When you use INSERT, UPDATE or DELETE statement as a named query, you need to specify this option to 'true'. |  | Boolean
-| *usePassedInEntityManager* (producer) | If set to true, then Camel will use the EntityManager from the header JpaConstants.ENTITYMANAGER instead of the configured entity manager on the component/endpoint. This allows end users to control which entity manager will be in use. | false | boolean
+| *usePassedInEntityManager* (producer) | If set to true, then Camel will use the EntityManager from the header JpaConstants.ENTITY_MANAGER instead of the configured entity manager on the component/endpoint. This allows end users to control which entity manager will be in use. | false | boolean
 | *usePersist* (producer) | Indicates to use entityManager.persist(entity) instead of entityManager.merge(entity). Note: entityManager.persist(entity) doesn't work for detached entities (where the EntityManager has to execute an UPDATE instead of an INSERT query)! | false | boolean
 | *entityManagerProperties* (advanced) | Additional properties for the entity manager to use. |  | Map
 | *synchronous* (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean
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 42631bb..71bc1cd 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
@@ -388,7 +388,7 @@ public class JpaEndpoint extends ScheduledPollEndpoint {
 
     /**
      * If set to true, then Camel will use the EntityManager from the header
-     * JpaConstants.ENTITYMANAGER instead of the configured entity manager on the component/endpoint.
+     * JpaConstants.ENTITY_MANAGER instead of the configured entity manager on the component/endpoint.
      * This allows end users to control which entity manager will be in use.
      */
     public void setUsePassedInEntityManager(boolean usePassedIn) {
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 5ee7702..913e4de 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
@@ -192,11 +192,11 @@ public class JpaProducer extends DefaultProducer {
             query.setMaxResults(maxResults);
         }
         // setup the parameters
-        Map<String, Object> params = null;
+        Map<String, ?> params;
         if (parameters != null) {
             params = parameters;
         } else {
-            params = (Map<String, Object>)exchange.getIn().getHeader(JpaConstants.JPA_PARAMETERS_HEADER);
+            params = exchange.getIn().getHeader(JpaConstants.JPA_PARAMETERS_HEADER, Map.class);
         }
         if (params != null) {
             params.forEach((key, value) -> {
diff --git a/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/AbstractJpaMethodTest.java b/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/AbstractJpaMethodTest.java
index de654ec..fd47736 100644
--- a/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/AbstractJpaMethodTest.java
+++ b/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/AbstractJpaMethodTest.java
@@ -121,7 +121,7 @@ public abstract class AbstractJpaMethodTest extends CamelTestSupport {
         consumer = endpoint.createConsumer(new Processor() {
             public void process(Exchange e) {
                 receivedExchange = e;
-                assertNotNull(e.getIn().getHeader(JpaConstants.ENTITYMANAGER, EntityManager.class));
+                assertNotNull(e.getIn().getHeader(JpaConstants.ENTITY_MANAGER, EntityManager.class));
                 latch.countDown();
             }
         });
diff --git a/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaWithNativeQueryWithResultClassTest.java b/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaWithNativeQueryWithResultClassTest.java
index 4ecaa83..d9e092a 100644
--- a/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaWithNativeQueryWithResultClassTest.java
+++ b/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaWithNativeQueryWithResultClassTest.java
@@ -30,7 +30,7 @@ public class JpaWithNativeQueryWithResultClassTest extends JpaWithNamedQueryTest
     @Override
     protected void assertReceivedResult(Exchange exchange) {
         assertNotNull(exchange);
-        MultiSteps result = (MultiSteps) exchange.getIn().getBody();
+        MultiSteps result = exchange.getIn().getBody(MultiSteps.class);
         assertNotNull("Received an object array", result);
         assertEquals("address property", "foo@bar.com", result.getAddress());
     }
diff --git a/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaProducerPassingEntityManagerTest.java b/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaProducerPassingEntityManagerTest.java
index 1f04de2..ba33dca 100644
--- a/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaProducerPassingEntityManagerTest.java
+++ b/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaProducerPassingEntityManagerTest.java
@@ -53,7 +53,7 @@ public class JpaProducerPassingEntityManagerTest extends AbstractJpaTest {
 
         // The same EntityManager returns same entity instance from its 1st level cache
         entityManager = emf.createEntityManager();
-        template.sendBodyAndHeader("direct:start", new SendEmail("bar@beer.org"), JpaConstants.ENTITYMANAGER, entityManager);
+        template.sendBodyAndHeader("direct:start", new SendEmail("bar@beer.org"), JpaConstants.ENTITY_MANAGER, entityManager);
         exchange = mock.getReceivedExchanges().get(0);
         persistedEntity = exchange.getIn().getBody(SendEmail.class);
         emfindEntity = entityManager.find(SendEmail.class, persistedEntity.getId());
diff --git a/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaProducerWithQueryParametersHeaderTest.java b/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaProducerWithQueryParametersHeaderTest.java
index 3afb7ee..27a08b2 100644
--- a/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaProducerWithQueryParametersHeaderTest.java
+++ b/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaProducerWithQueryParametersHeaderTest.java
@@ -54,13 +54,12 @@ public class JpaProducerWithQueryParametersHeaderTest extends Assert {
         Map<String, Object> params = new HashMap<>();
         params.put("custName", "${body}");
 
-        Object answer = template.requestBodyAndHeader("direct:namedQuery", "Willem", JpaConstants.JPA_PARAMETERS_HEADER, params);
-        List list = (List)answer;
+        List list = template.requestBodyAndHeader("direct:namedQuery", "Willem", JpaConstants.JPA_PARAMETERS_HEADER, params, List.class);
         assertEquals(1, list.size());
         assertEquals("Willem", ((Customer)list.get(0)).getName());
 
-        answer = template.requestBody("direct:deleteCustomers", "");
-        assertEquals(2, ((Integer)answer).intValue());
+        int integer = template.requestBody("direct:deleteCustomers", null, int.class);
+        assertEquals(2, integer);
     }
 
     @Before
diff --git a/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaRouteTest.java b/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaRouteTest.java
index 2336e36..7106cd3 100644
--- a/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaRouteTest.java
+++ b/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaRouteTest.java
@@ -42,7 +42,7 @@ public class JpaRouteTest extends AbstractJpaTest {
 
         MockEndpoint mock = getMockEndpoint("mock:result");
         mock.expectedMessageCount(1);
-        ValueBuilder header = mock.message(0).header(JpaConstants.ENTITYMANAGER);
+        ValueBuilder header = mock.message(0).header(JpaConstants.ENTITY_MANAGER);
         header.isNotNull();
         header.isInstanceOf(EntityManager.class);