camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hekon...@apache.org
Subject git commit: [CAMEL-7126] Cleaning code from JpaTemplate references.
Date Thu, 23 Jan 2014 17:21:36 GMT
Updated Branches:
  refs/heads/master 2798d9301 -> 72e8240e2


[CAMEL-7126] Cleaning code from JpaTemplate references.


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

Branch: refs/heads/master
Commit: 72e8240e286d47c8cee82ecec9efa30dce5d7d23
Parents: 2798d93
Author: Henryk Konsek <hekonsek@gmail.com>
Authored: Thu Jan 23 18:21:15 2014 +0100
Committer: Henryk Konsek <hekonsek@gmail.com>
Committed: Thu Jan 23 18:21:15 2014 +0100

----------------------------------------------------------------------
 .../java/org/apache/camel/bam/EntityManagerTemplate.java | 10 ++++++++++
 .../main/java/org/apache/camel/bam/ProcessBuilder.java   |  9 ++++++---
 .../org/apache/camel/bam/model/ProcessDefinition.java    | 11 ++++-------
 .../camel/bam/processor/JpaBamProcessorSupport.java      |  3 ++-
 4 files changed, 22 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/72e8240e/components/camel-bam/src/main/java/org/apache/camel/bam/EntityManagerTemplate.java
----------------------------------------------------------------------
diff --git a/components/camel-bam/src/main/java/org/apache/camel/bam/EntityManagerTemplate.java
b/components/camel-bam/src/main/java/org/apache/camel/bam/EntityManagerTemplate.java
index 50db9bf..fe2fddd 100644
--- a/components/camel-bam/src/main/java/org/apache/camel/bam/EntityManagerTemplate.java
+++ b/components/camel-bam/src/main/java/org/apache/camel/bam/EntityManagerTemplate.java
@@ -40,4 +40,14 @@ public class EntityManagerTemplate {
         }
     }
 
+    public void persist(final Object entity) {
+        execute(new EntityManagerCallback<Object>() {
+            @Override
+            public Object execute(EntityManager entityManager) {
+                entityManager.persist(entity);
+                return null;
+            }
+        });
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/72e8240e/components/camel-bam/src/main/java/org/apache/camel/bam/ProcessBuilder.java
----------------------------------------------------------------------
diff --git a/components/camel-bam/src/main/java/org/apache/camel/bam/ProcessBuilder.java b/components/camel-bam/src/main/java/org/apache/camel/bam/ProcessBuilder.java
index aec8681..ff34ee2 100644
--- a/components/camel-bam/src/main/java/org/apache/camel/bam/ProcessBuilder.java
+++ b/components/camel-bam/src/main/java/org/apache/camel/bam/ProcessBuilder.java
@@ -48,6 +48,7 @@ import static org.apache.camel.util.ObjectHelper.notNull;
 public abstract class ProcessBuilder extends RouteBuilder {
     private static int processCounter;
     private JpaTemplate jpaTemplate;
+    private EntityManagerTemplate entityManagerTemplate;
     private TransactionTemplate transactionTemplate;
     private String processName;
     private final List<ActivityBuilder> activityBuilders = new ArrayList<ActivityBuilder>();
@@ -67,6 +68,7 @@ public abstract class ProcessBuilder extends RouteBuilder {
         this.jpaTemplate = jpaTemplate;
         this.transactionTemplate = transactionTemplate;
         this.processName = processName;
+        this.entityManagerTemplate = new EntityManagerTemplate(jpaTemplate.getEntityManagerFactory());
     }
 
     protected static synchronized String createProcessName() {
@@ -117,6 +119,7 @@ public abstract class ProcessBuilder extends RouteBuilder {
 
     public void setJpaTemplate(JpaTemplate jpaTemplate) {
         this.jpaTemplate = jpaTemplate;
+        this.entityManagerTemplate = new EntityManagerTemplate(jpaTemplate.getEntityManagerFactory());
     }
 
     public TransactionTemplate getTransactionTemplate() {
@@ -189,8 +192,8 @@ public abstract class ProcessBuilder extends RouteBuilder {
         } else {
             ActivityDefinition answer = new ActivityDefinition();
             answer.setName(activityName);
-            answer.setProcessDefinition(ProcessDefinition.getRefreshedProcessDefinition(jpaTemplate,
definition));
-            jpaTemplate.persist(answer);
+            answer.setProcessDefinition(ProcessDefinition.getRefreshedProcessDefinition(entityManagerTemplate,
definition));
+            entityManagerTemplate.persist(answer);
             return answer;
         }
     }
@@ -206,7 +209,7 @@ public abstract class ProcessBuilder extends RouteBuilder {
         } else {
             ProcessDefinition answer = new ProcessDefinition();
             answer.setName(processName);
-            jpaTemplate.persist(answer);
+            entityManagerTemplate.persist(answer);
             return answer;
         }
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/72e8240e/components/camel-bam/src/main/java/org/apache/camel/bam/model/ProcessDefinition.java
----------------------------------------------------------------------
diff --git a/components/camel-bam/src/main/java/org/apache/camel/bam/model/ProcessDefinition.java
b/components/camel-bam/src/main/java/org/apache/camel/bam/model/ProcessDefinition.java
index 1d07785..dadf781 100644
--- a/components/camel-bam/src/main/java/org/apache/camel/bam/model/ProcessDefinition.java
+++ b/components/camel-bam/src/main/java/org/apache/camel/bam/model/ProcessDefinition.java
@@ -29,7 +29,6 @@ import org.apache.camel.bam.QueryUtils;
 import org.apache.camel.util.ObjectHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.springframework.orm.jpa.JpaTemplate;
 
 /**
  * @version 
@@ -50,8 +49,7 @@ public class ProcessDefinition extends EntitySupport {
         this.name = name;
     }
 
-    public static ProcessDefinition getRefreshedProcessDefinition(JpaTemplate template, ProcessDefinition
definition) {
-        EntityManagerTemplate entityManagerTemplate = new EntityManagerTemplate(template.getEntityManagerFactory());
+    public static ProcessDefinition getRefreshedProcessDefinition(EntityManagerTemplate entityManagerTemplate,
ProcessDefinition definition) {
         // TODO refresh doesn't tend to work - maybe its a spring thing?
         // template.refresh(definition);
 
@@ -59,7 +57,7 @@ public class ProcessDefinition extends EntitySupport {
         final Long id = definition.getId();
         if (id == null) {
             LOG.warn("No primary key is available!");
-            return findOrCreateProcessDefinition(template, definition.getName());
+            return findOrCreateProcessDefinition(entityManagerTemplate, definition.getName());
         }
         return entityManagerTemplate.execute(new EntityManagerCallback<ProcessDefinition>()
{
             @Override
@@ -69,8 +67,7 @@ public class ProcessDefinition extends EntitySupport {
         });
     }
 
-    public static ProcessDefinition findOrCreateProcessDefinition(JpaTemplate template, final
String processName) {
-        EntityManagerTemplate entityManagerTemplate = new EntityManagerTemplate(template.getEntityManagerFactory());
+    public static ProcessDefinition findOrCreateProcessDefinition(EntityManagerTemplate entityManagerTemplate,
final String processName) {
         final String definitionsQuery = "select x from " + QueryUtils.getTypeName(ProcessDefinition.class)
                 + " x where x.name = :processName";
         List<ProcessDefinition> list = entityManagerTemplate.execute(new EntityManagerCallback<List<ProcessDefinition>>()
{
@@ -86,7 +83,7 @@ public class ProcessDefinition extends EntitySupport {
         } else {
             ProcessDefinition answer = new ProcessDefinition();
             answer.setName(processName);
-            template.persist(answer);
+            entityManagerTemplate.persist(answer);
             return answer;
         }
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/72e8240e/components/camel-bam/src/main/java/org/apache/camel/bam/processor/JpaBamProcessorSupport.java
----------------------------------------------------------------------
diff --git a/components/camel-bam/src/main/java/org/apache/camel/bam/processor/JpaBamProcessorSupport.java
b/components/camel-bam/src/main/java/org/apache/camel/bam/processor/JpaBamProcessorSupport.java
index e728f50..816d626 100644
--- a/components/camel-bam/src/main/java/org/apache/camel/bam/processor/JpaBamProcessorSupport.java
+++ b/components/camel-bam/src/main/java/org/apache/camel/bam/processor/JpaBamProcessorSupport.java
@@ -105,6 +105,7 @@ public class JpaBamProcessorSupport<T> extends BamProcessorSupport<T>
{
 
     public void setTemplate(JpaTemplate template) {
         this.template = template;
+        this.entityManagerTemplate = new EntityManagerTemplate(template.getEntityManagerFactory());
     }
 
     public boolean isCorrelationKeyIsPrimary() {
@@ -125,7 +126,7 @@ public class JpaBamProcessorSupport<T> extends BamProcessorSupport<T>
{
             if (entity == null) {
                 entity = createEntity(exchange, key);
                 setKeyProperty(entity, key);
-                ProcessDefinition definition = ProcessDefinition.getRefreshedProcessDefinition(template,
+                ProcessDefinition definition = ProcessDefinition.getRefreshedProcessDefinition(entityManagerTemplate,
                         getActivityRules().getProcessRules().getProcessDefinition());
                 setProcessDefinitionProperty(entity, definition);
                 final T finalEntity = entity;


Mime
View raw message