Author: davsclaus
Date: Thu Feb 12 10:57:37 2009
New Revision: 743686

URL: http://svn.apache.org/viewvc?rev=743686&view=rev
Log:
CAMEL-505: jpa endpoint can now be created using spring bean style.

Added:
    
camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaRouteEndpointTest.java
   (with props)
    
camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaRouteTest.java
      - copied, changed from r743658, 
camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/processor/interceptor/JpaTraceEventMessageTest.java
    
camel/trunk/components/camel-jpa/src/test/resources/org/apache/camel/processor/jpa/springJpaRouteTest.xml
   (with props)
Modified:
    
camel/trunk/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaEndpoint.java
    
camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaWithNamedQueryTest.java

Modified: 
camel/trunk/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaEndpoint.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaEndpoint.java?rev=743686&r1=743685&r2=743686&view=diff
==============================================================================
--- 
camel/trunk/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaEndpoint.java
 (original)
+++ 
camel/trunk/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaEndpoint.java
 Thu Feb 12 10:57:37 2009
@@ -49,6 +49,9 @@
     private boolean consumeLockEntity = true;
     private boolean flushOnSend = true;
 
+    public JpaEndpoint() {
+    }
+
     public JpaEndpoint(String uri, JpaComponent component) {
         super(uri, component);
         entityManagerFactory = component.getEntityManagerFactory();
@@ -88,6 +91,12 @@
         return false;
     }
 
+    @Override
+    protected String createEndpointUri() {
+        return "jpa" + entityType != null ? "://" + entityType.getName() : "";
+    }
+
+
     // Properties
     // 
-------------------------------------------------------------------------
     public JpaTemplate getTemplate() {
@@ -212,7 +221,12 @@
         } else {
             return new ExpressionAdapter() {
                 public Object evaluate(Exchange exchange) {
-                    Object answer = exchange.getIn().getBody(type);
+                    Object answer = null;
+                    try {
+                        answer = exchange.getIn().getBody(type);
+                    } catch (NoTypeConversionAvailableException e) {
+                        // ignore
+                    }
                     if (answer == null) {
                         Object defaultValue = exchange.getIn().getBody();
                         if (defaultValue != null) {

Modified: 
camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaWithNamedQueryTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaWithNamedQueryTest.java?rev=743686&r1=743685&r2=743686&view=diff
==============================================================================
--- 
camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaWithNamedQueryTest.java
 (original)
+++ 
camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaWithNamedQueryTest.java
 Thu Feb 12 10:57:37 2009
@@ -104,8 +104,7 @@
         assertEquals("address property", "[email protected]", result.getAddress());
 
         // lets now test that the database is updated
-        // TODO we need to sleep as we will be invoked from inside the
-        // transaction!
+        // we need to sleep as we will be invoked from inside the transaction!
         Thread.sleep(1000);
 
         transactionStrategy.execute(new JpaCallback() {

Added: 
camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaRouteEndpointTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaRouteEndpointTest.java?rev=743686&view=auto
==============================================================================
--- 
camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaRouteEndpointTest.java
 (added)
+++ 
camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaRouteEndpointTest.java
 Thu Feb 12 10:57:37 2009
@@ -0,0 +1,45 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.processor.jpa;
+
+import javax.persistence.EntityManagerFactory;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.jpa.JpaEndpoint;
+import org.apache.camel.examples.SendEmail;
+import org.apache.camel.spring.SpringRouteBuilder;
+
+/**
+ * @version $Revision$
+ */
+public class JpaRouteEndpointTest extends JpaRouteTest {
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        return new SpringRouteBuilder() {
+            public void configure() throws Exception {
+                JpaEndpoint jpa = new JpaEndpoint();
+                jpa.setCamelContext(context);
+                jpa.setEntityType(SendEmail.class);
+                
jpa.setEntityManagerFactory(context.getRegistry().lookup("entityManagerFactory",
 EntityManagerFactory.class));
+
+                from("direct:start").to(jpa).to("mock:result");
+            }
+        };
+    }
+
+}
\ No newline at end of file

Propchange: 
camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaRouteEndpointTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaRouteEndpointTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Copied: 
camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaRouteTest.java
 (from r743658, 
camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/processor/interceptor/JpaTraceEventMessageTest.java)
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaRouteTest.java?p2=camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaRouteTest.java&p1=camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/processor/interceptor/JpaTraceEventMessageTest.java&r1=743658&r2=743686&rev=743686&view=diff
==============================================================================
--- 
camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/processor/interceptor/JpaTraceEventMessageTest.java
 (original)
+++ 
camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaRouteTest.java
 Thu Feb 12 10:57:37 2009
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.camel.processor.interceptor;
+package org.apache.camel.processor.jpa;
 
 import java.util.List;
 
@@ -22,6 +22,7 @@
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.examples.SendEmail;
 import org.apache.camel.spring.SpringCamelContext;
 import org.apache.camel.spring.SpringRouteBuilder;
 import org.springframework.context.ApplicationContext;
@@ -36,17 +37,17 @@
 /**
  * @version $Revision$
  */
-public class JpaTraceEventMessageTest extends ContextTestSupport {
-    protected static final String SELECT_ALL_STRING = "select x from " + 
JpaTraceEventMessage.class.getName() + " x";
+public class JpaRouteTest extends ContextTestSupport {
+    protected static final String SELECT_ALL_STRING = "select x from " + 
SendEmail.class.getName() + " x";
 
     protected ApplicationContext applicationContext;
     protected JpaTemplate jpaTemplate;
 
-    public void testSendTraceMessage() throws Exception {
+    public void testRouteJpa() throws Exception {
         MockEndpoint mock = getMockEndpoint("mock:result");
         mock.expectedMessageCount(1);
 
-        template.sendBody("direct:start", "Hello World");
+        template.sendBody("direct:start", new 
SendEmail("[email protected]"));
 
         assertMockEndpointsSatisfied();
         assertEntityInDB();
@@ -54,7 +55,7 @@
 
     @Override
     protected CamelContext createCamelContext() throws Exception {
-        applicationContext = new 
ClassPathXmlApplicationContext("org/apache/camel/processor/interceptor/springJpaTraveEvent.xml");
+        applicationContext = new 
ClassPathXmlApplicationContext("org/apache/camel/processor/jpa/springJpaRouteTest.xml");
         cleanupRepository();
         return SpringCamelContext.springCamelContext(applicationContext);
     }
@@ -63,12 +64,7 @@
     protected RouteBuilder createRouteBuilder() {
         return new SpringRouteBuilder() {
             public void configure() {
-                Tracer tracer = new Tracer();
-                tracer.setDestinationUri("jpa://" + 
JpaTraceEventMessage.class.getName() + "?persistenceUnit=trace");
-                tracer.setUseJpa(true);
-                getContext().addInterceptStrategy(tracer);
-
-                from("direct:start").to("mock:result");
+                from("direct:start").to("jpa://" + 
SendEmail.class.getName()).to("mock:result");
             }
         };
     }
@@ -79,10 +75,7 @@
         List list = jpaTemplate.find(SELECT_ALL_STRING);
         assertEquals(1, list.size());
         
-        JpaTraceEventMessage db = (JpaTraceEventMessage) list.get(0);
-        assertNotNull(db.getId());
-        assertEquals("direct:start", db.getFromEndpointUri());
-        assertEquals("to(mock:result)", db.getToNode());
+        assertIsInstanceOf(SendEmail.class, list.get(0));
     }
 
     protected void cleanupRepository() {

Added: 
camel/trunk/components/camel-jpa/src/test/resources/org/apache/camel/processor/jpa/springJpaRouteTest.xml
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-jpa/src/test/resources/org/apache/camel/processor/jpa/springJpaRouteTest.xml?rev=743686&view=auto
==============================================================================
--- 
camel/trunk/components/camel-jpa/src/test/resources/org/apache/camel/processor/jpa/springJpaRouteTest.xml
 (added)
+++ 
camel/trunk/components/camel-jpa/src/test/resources/org/apache/camel/processor/jpa/springJpaRouteTest.xml
 Thu Feb 12 10:57:37 2009
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+  
+  http://www.apache.org/licenses/LICENSE-2.0
+  
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans";
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd";>
+
+    <bean id="transactionTemplate" 
class="org.springframework.transaction.support.TransactionTemplate">
+        <property name="transactionManager">
+            <bean class="org.springframework.orm.jpa.JpaTransactionManager">
+                <property name="entityManagerFactory" 
ref="entityManagerFactory"/>
+            </bean>
+        </property>
+    </bean>
+
+    <bean id="jpaTemplate" class="org.springframework.orm.jpa.JpaTemplate">
+        <property name="entityManagerFactory" ref="entityManagerFactory"/>
+    </bean>
+
+    <bean id="entityManagerFactory" 
class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
+        <property name="persistenceUnitName" value="camel"/>
+    </bean>
+
+</beans>

Propchange: 
camel/trunk/components/camel-jpa/src/test/resources/org/apache/camel/processor/jpa/springJpaRouteTest.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
camel/trunk/components/camel-jpa/src/test/resources/org/apache/camel/processor/jpa/springJpaRouteTest.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: 
camel/trunk/components/camel-jpa/src/test/resources/org/apache/camel/processor/jpa/springJpaRouteTest.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml


Reply via email to