activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r525201 - in /activemq/camel/trunk/camel-jpa/src: main/java/org/apache/camel/component/jpa/ main/resources/META-INF/services/org/apache/camel/EndpointResolver/ test/java/org/apache/camel/component/jpa/ test/resources/META-INF/
Date Tue, 03 Apr 2007 16:30:37 GMT
Author: jstrachan
Date: Tue Apr  3 09:30:33 2007
New Revision: 525201

URL: http://svn.apache.org/viewvc?view=rev&rev=525201
Log:
add the auto-discovery of JPA endpoints; also allow the persistence unit to be specified in
the URI. e.g. jpa:type or jpa:persistenceUnit:type

Added:
    activemq/camel/trunk/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaEndpointResolver.java
  (with props)
    activemq/camel/trunk/camel-jpa/src/main/resources/META-INF/services/org/apache/camel/EndpointResolver/
    activemq/camel/trunk/camel-jpa/src/main/resources/META-INF/services/org/apache/camel/EndpointResolver/jpa
    activemq/camel/trunk/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaUsingCustomPersistenceUnitTest.java
  (with props)
Modified:
    activemq/camel/trunk/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaComponent.java
    activemq/camel/trunk/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaConsumer.java
    activemq/camel/trunk/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaTest.java
    activemq/camel/trunk/camel-jpa/src/test/resources/META-INF/persistence.xml

Modified: activemq/camel/trunk/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaComponent.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaComponent.java?view=diff&rev=525201&r1=525200&r2=525201
==============================================================================
--- activemq/camel/trunk/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaComponent.java
(original)
+++ activemq/camel/trunk/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaComponent.java
Tue Apr  3 09:30:33 2007
@@ -69,6 +69,11 @@
         }
         URI u = new URI(uri);
         String path = u.getSchemeSpecificPart();
+        String[] paths = ObjectHelper.splitOnCharacter(path, ":", 2);
+        // ignore a prefix
+        if (paths[1] != null) {
+            path = paths[1];
+        }
         JpaEndpoint endpoint = new JpaEndpoint(uri, this);
 
         // lets interpret the next string as a class

Modified: activemq/camel/trunk/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaConsumer.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaConsumer.java?view=diff&rev=525201&r1=525200&r2=525201
==============================================================================
--- activemq/camel/trunk/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaConsumer.java
(original)
+++ activemq/camel/trunk/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaConsumer.java
Tue Apr  3 09:30:33 2007
@@ -88,6 +88,10 @@
     public QueryFactory getQueryFactory() {
         if (queryFactory == null) {
             queryFactory = createQueryFactory();
+            if (queryFactory == null) {
+                throw new IllegalArgumentException("No queryType property configured on this
consumer, nor an entityType configured on the endpoint so cannot consume");
+            }
+
         }
         return queryFactory;
     }

Added: activemq/camel/trunk/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaEndpointResolver.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaEndpointResolver.java?view=auto&rev=525201
==============================================================================
--- activemq/camel/trunk/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaEndpointResolver.java
(added)
+++ activemq/camel/trunk/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaEndpointResolver.java
Tue Apr  3 09:30:33 2007
@@ -0,0 +1,84 @@
+/**
+ *
+ * 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.component.jpa;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Component;
+import org.apache.camel.Endpoint;
+import org.apache.camel.EndpointResolver;
+import org.apache.camel.util.ObjectHelper;
+
+import java.net.URISyntaxException;
+import java.util.concurrent.Callable;
+
+/**
+ * @version $Revision$
+ */
+public class JpaEndpointResolver implements EndpointResolver {
+    public static final String DEFAULT_COMPONENT_NAME = JpaComponent.class.getName();
+
+    /**
+     * Finds the {@see JpaComponent} specified by the uri.  If the {@see JpaComponent}
+     * object do not exist, it will be created.
+     */
+    public Component resolveComponent(CamelContext container, String uri) {
+        String id[] = getEndpointId(uri);
+        return resolveJpaComponent(container, id[0]);
+    }
+
+    /**
+     * Finds the {@see QueueEndpoint} specified by the uri.  If the {@see QueueEndpoint}
or it's associated
+     * {@see QueueComponent} object do not exist, they will be created.
+     */
+    public Endpoint resolveEndpoint(CamelContext container, String uri) throws Exception
{
+        String id[] = getEndpointId(uri);
+        JpaComponent component = resolveJpaComponent(container, id[0]);
+        return component.resolveEndpoint(container, uri);
+    }
+
+    /**
+     * @return an array that looks like: [componentName,endpointName]
+     */
+    private String[] getEndpointId(String uri) {
+        String rc[] = {DEFAULT_COMPONENT_NAME, null};
+        String splitURI[] = ObjectHelper.splitOnCharacter(uri, ":", 3);
+        if (splitURI[2] != null) {
+            rc[0] = splitURI[1];
+            rc[1] = splitURI[2];
+        }
+        else {
+            rc[1] = splitURI[1];
+        }
+        return rc;
+    }
+
+    @SuppressWarnings("unchecked")
+    private JpaComponent resolveJpaComponent(final CamelContext context, final String componentName)
{
+        Component rc = context.getOrCreateComponent(componentName, new Callable() {
+            public JpaComponent call() throws Exception {
+                JpaComponent answer = new JpaComponent();
+                answer.setCamelContext(context);
+                if (!componentName.equals(DEFAULT_COMPONENT_NAME)) {
+                    answer.setEntityManagerName(componentName);
+                }
+                return answer;
+            }
+        });
+        return (JpaComponent) rc;
+    }
+}

Propchange: activemq/camel/trunk/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaEndpointResolver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaEndpointResolver.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/camel/trunk/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaEndpointResolver.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: activemq/camel/trunk/camel-jpa/src/main/resources/META-INF/services/org/apache/camel/EndpointResolver/jpa
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-jpa/src/main/resources/META-INF/services/org/apache/camel/EndpointResolver/jpa?view=auto&rev=525201
==============================================================================
--- activemq/camel/trunk/camel-jpa/src/main/resources/META-INF/services/org/apache/camel/EndpointResolver/jpa
(added)
+++ activemq/camel/trunk/camel-jpa/src/main/resources/META-INF/services/org/apache/camel/EndpointResolver/jpa
Tue Apr  3 09:30:33 2007
@@ -0,0 +1 @@
+class=org.apache.camel.component.jpa.JpaEndpointResolver

Modified: activemq/camel/trunk/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaTest.java?view=diff&rev=525201&r1=525200&r2=525201
==============================================================================
--- activemq/camel/trunk/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaTest.java
(original)
+++ activemq/camel/trunk/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaTest.java
Tue Apr  3 09:30:33 2007
@@ -101,11 +101,10 @@
     @Override
     protected void setUp() throws Exception {
         super.setUp();
-        camelContext.addComponent("foo", createJpaComponent());
 
         startServices(client, camelContext);
 
-        Endpoint value = camelContext.resolveEndpoint("jpa:" + SendEmail.class.getName());
+        Endpoint value = camelContext.resolveEndpoint(getEndpointUri());
         assertNotNull("Could not find endpoint!", value);
         assertTrue("Should be a JPA endpoint but was: " + value, value instanceof JpaEndpoint);
         endpoint = (JpaEndpoint) value;
@@ -114,19 +113,8 @@
         template = endpoint.getTemplate();
     }
 
-    protected JpaComponent createJpaComponent() {
-        // TODO zap this!
-        
-        JpaComponent answer = new JpaComponent();
-/*
-        Properties properties = new Properties();
-        properties.setProperty("openjpa.ConnectionDriverName", "org.apache.derby.jdbc.EmbeddedDriver");
-        properties.setProperty("openjpa.ConnectionURL", "jdbc:derby:target/derby;create=true");
-        properties.setProperty("openjpa.jdbc.SynchronizeMappings", "buildSchema");
-        properties.setProperty("openjpa.Log", "DefaultLevel=WARN,SQL=TRACE");
-        answer.setEntityManagerProperties(properties);
-*/
-        return answer;
+    protected String getEndpointUri() {
+        return "jpa:" + SendEmail.class.getName();
     }
 
     @Override

Added: activemq/camel/trunk/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaUsingCustomPersistenceUnitTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaUsingCustomPersistenceUnitTest.java?view=auto&rev=525201
==============================================================================
--- activemq/camel/trunk/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaUsingCustomPersistenceUnitTest.java
(added)
+++ activemq/camel/trunk/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaUsingCustomPersistenceUnitTest.java
Tue Apr  3 09:30:33 2007
@@ -0,0 +1,30 @@
+/**
+ *
+ * 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.component.jpa;
+
+import org.apache.camel.examples.SendEmail;
+
+/**
+ * @version $Revision$
+ */
+public class JpaUsingCustomPersistenceUnitTest extends JpaTest {
+
+    protected String getEndpointUri() {
+        return "jpa:custom:" + SendEmail.class.getName();
+    }
+}

Propchange: activemq/camel/trunk/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaUsingCustomPersistenceUnitTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaUsingCustomPersistenceUnitTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/camel/trunk/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaUsingCustomPersistenceUnitTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: activemq/camel/trunk/camel-jpa/src/test/resources/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-jpa/src/test/resources/META-INF/persistence.xml?view=diff&rev=525201&r1=525200&r2=525201
==============================================================================
--- activemq/camel/trunk/camel-jpa/src/test/resources/META-INF/persistence.xml (original)
+++ activemq/camel/trunk/camel-jpa/src/test/resources/META-INF/persistence.xml Tue Apr  3
09:30:33 2007
@@ -43,4 +43,15 @@
       <property name="openjpa.Log" value="DefaultLevel=WARN, Tool=INFO, SQL=TRACE"/>
     </properties>
   </persistence-unit>
+
+    <persistence-unit name="custom" transaction-type="RESOURCE_LOCAL">
+    <class>org.apache.camel.examples.SendEmail</class>
+
+    <properties>
+      <property name="openjpa.ConnectionURL" value="jdbc:derby:target/custom;create=true"/>
+      <property name="openjpa.ConnectionDriverName" value="org.apache.derby.jdbc.EmbeddedDriver"/>
+      <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema"/>
+      <property name="openjpa.Log" value="DefaultLevel=WARN, Tool=INFO"/>
+    </properties>
+  </persistence-unit>
 </persistence>



Mime
View raw message