diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..e4f26a5 --- /dev/null +++ b/README.txt @@ -0,0 +1,196 @@ + + +DESCRIPTION +=========== + +This is the material accompanying the presentation of webinar part II - Transaction Management with Fuse ESB, Camel and Persistent EIPs. +It covers the different demo made during the talk and is organized like that : + +aggregator = Camel route project to persist aggregate in H2 DB using JDBCAggregateRepository +idempotent = Camel route using JPAIdempotentRepository to persist messages already processed +dao = DAO layer to persist Incident record in H2 DB using OpenJPA +dao-jta = Idem but configured to use JTA +features = features to be deployed on Fuse ESB +route-one-tx-manager = Camel routes using one Global Tx Manager (Aries Tx Manager on Fuse ESB) +route-two-tx-manager = Camel routes using tewo separate Tx Managers (JMS and JDBC) + +H2 DATABASE +=========== + + 1) Open a DOS/UNIX console in the folder persistence/database + + 2) Download H2 Database (http://www.h2database.com/html/download.html) and install it + + 3) Start H2 Server using the bat or shell script + + ./h2.sh & + + The H2 server is started and to manage the databases from your web browser, simply click on the following url http://localhost:8082/ + + 4) Next create the report database + + In the login.jsp screen, select Generic (H2) - Server + Add as settings name : Generic H2 (Server) - Webinar + and modify the JDBC ur las such : jdbc:h2:tcp://localhost/~/reportdb + + Next click on "connect" and the screen to manage the reportdb appears + + 5) Create Schema and Tables using the script located in the file camel-persistence-part2/datasource/src/config/hsqldb/reportdb-scripts.sql + + Execute the scripts 1), 2) and 3) defined in this file + + Check that the records are well created using the command : SELECT * FROM REPORT.T_INCIDENT; + + +FUSE ESB INSTALLATION +===================== + + 1) Download and install the Fuse ESB server : http://repo.fusesource.com/nexus/content/repositories/releases/org/apache/servicemix/apache-servicemix/4.4.1-fuse-01-06/ + 2) Start Fuse ESB server /bin/karaf.sh + + +Camel Route with 2 Tx Managers +============================== + +This example is comprised of the following projects: datasource, dao, route-two-tx-manager. +Ensure you have installed the H2 database and the REPORT schema as per the steps above. +To install and test, perform the following steps: + + 1) cd camel-persistence-part2/ + 2) Run: mvn clean install + + 3) ServiceMix offers a simple JNDI implementation for OSGi, but for this example we are interested in leveraging the more sophisticated Aries JNDI + lookup handler. Thus, we need to remove the ServiceMix Naming bundle as it will conflict with the Aries JNDI implementation. Run the following command: + + list | grep -i naming | grep -i servicemix + + Make note of the bundle id (the number inside the leftmost square brackets). + + Run the following command: + + uninstall + + Restart Karaf (use Ctrl-D to stop it). + + 3) Install the relevant bundles by executing the following command in the FUSE ESB console: + + features:addurl mvn:com.fusesource.examples.camel-persistence-part2/persistence/1.0/xml/features + features:install reportincident-jpa-two + + N.B.: You may safely disregard the openjpa.Runtime Warning if it appears. + + 4) Execute the "list" command in the ESB shell and check that the following bundles are Active: + + [...] [Active ] [Created ] [ ] [ 60] FuseSource :: Examples :: Fuse ESB & Persistence :: Datasource (1.0) + [...] [Active ] [ ] [Started] [ 60] FuseSource :: Examples :: Fuse ESB & Persistence :: DAO (1.0) + [...] [Active ] [ ] [Started] [ 60] FuseSource :: Examples :: Fuse ESB & Persistence :: Camel - 2 Tx Manager (1.0) + + 5) Start H2 console and connect to the DB using the following parameters + Driver class = org.h2.Driver + JDBC URL : jdbc:h2:tcp://localhost/~/reportdb + User name : sa + Password : + + Run the following SQL sentence to ensure that the REPORT.T_INCIDENT is empty: SELECT * FROM REPORT.T_INCIDENT; + + 6) Launch JConsole (inside $JAVA_HOME/bin) and connect to the local process named "org.apache.karaf.main.Main". Switch to the MBeans tab at the top. + On the left pane, expand the org.apache.activemq domain, then navigate to: default > Queue. You will see the incident and rollback queues. + The registerCall queue will appear when it is first used. For these queues, you will be interested in tracking the EnqueueCount attribute. + + 7) Copy the following files and notice the effect in the registerCall queue and the REPORT.T_INCIDENT table: + + - camel-persistence-part2/data/csv-one-record-allok.txt to $SERVICEMIX_HOME/datainsert --> record written in table, new message on registerCall queue + - camel-persistence-part2/data/csv-one-record-failjms-dbok.txt to $SERVICEMIX_HOME/datainsert --> record written in table, NO new message on registerCall queue + - camel-persistence-part2/data/csv-one-record-jmsok-faildb.txt to $SERVICEMIX_HOME/datainsert --> NO record written in table, new message on registerCall queue + - camel-persistence-part2/data/csv-one-record-failjms-faildb.txt to $SERVICEMIX_HOME/datainsert --> NO record written in table, NO new message on registerCall queue + + +Camel route with 1 Global Tx Manager +==================================== + +This example is comprised of the following projects: datasource, dao-jta, route-one-tx-manager. (NOTICE bundle names: dao-*jta* and route-*one*-tx-manager) +Ensure you have installed the H2 database and the REPORT schema as per the steps above. + +To install and test, assuming that you have previously run the "Camel Route with 2 Tx Managers" example above: + + 1) First uninstall the reportincident-jpa-two feature: + + features:uninstall reportincident-jpa-two + + 2) Install the reportincident-jpa-one feature: + + features:install reportincident-jpa-one + + 3) Execute the "list" command in the ESB shell and check that the following bundles are Active: + + [...] [Active ] [Created ] [ ] [ 60] FuseSource :: Examples :: Fuse ESB & Persistence :: Datasource (1.0) + [...] [Active ] [ ] [ ] [ 60] FuseSource :: Examples :: Fuse ESB & Persistence :: DAO - JTA (1.0) + [...] [Active ] [ ] [Started] [ 60] FuseSource :: Examples :: Fuse ESB & Persistence :: Camel - 1 Tx Manager (1.0) + + 4) Copy the following files and notice the new behaviours in the second and third cases, in terms of the registerCall queue and the REPORT.T_INCIDENT table: + + - camel-persistence-part2/data/csv-one-record-allok.txt to $SERVICEMIX_HOME/datainsert --> record written in table, new message on registerCall queue + - camel-persistence-part2/data/csv-one-record-failjms-dbok.txt to $SERVICEMIX_HOME/datainsert --> NO record written in table, NO new message on registerCall queue + - camel-persistence-part2/data/csv-one-record-jmsok-faildb.txt to $SERVICEMIX_HOME/datainsert --> NO record written in table, NO new message on registerCall queue + - camel-persistence-part2/data/csv-one-record-failjms-faildb.txt to $SERVICEMIX_HOME/datainsert --> NO record written in table, NO new message on registerCall queue + +Idempotent example +================== + + 1) Cd idempotent + 2) Execute mvn camel:run + 3) Start H2 console and connect to the DB using the following parameters + Driver class = org.h2.Driver + JDBC URL : jdbc:h2:tcp://localhost/~/idempotentReport + User name : sa + Password : + 4) Enter the following request to verify that no records have been inserted + SELECT * FROM CAMEL_MESSAGEPROCESSED + 5) Copy the following file + cp cp ../data/csv-one-record.txt datainsert/ + 6) The exchange is not filters out and camel logs that + %%% File receive -> csv-one-record.txt + 7) Shutdown the camel route and restart + Verify after copying the file that the camel route will not display the following message + %%% File receive -> csv-one-record.txt + +Aggregator example +================== + + 1) Cd aggregator + 2) Start H2 console and connect to the DB using the following parameters + Driver class = org.h2.Driver + JDBC URL : jdbc:h2:tcp://localhost/~/aggregationReport + User name : sa + Password : + 3) Create the DB using script in directory sql/init.sql + 4) Execute mvn camel:run + 5) Shutdown camel when 2-3 exchanges have been aggregated + + >>> (file-to-queue) from(timer://demo?period=2000&repeatCount=15) --> ref:users method: getUser <<< Pattern:InOnly, Headers:{firedTime=Wed Nov 23 11:38:51 CET 2011, breadcrumbId=ID-biker-chm-local-53796-1322044729997-0-2}, BodyType:null, Body:[Body is null] + >>> (file-to-queue) ref:users method: getUser --> aggregate <<< Pattern:InOnly, Headers:{firedTime=Wed Nov 23 11:38:51 CET 2011, breadcrumbId=ID-biker-chm-local-53796-1322044729997-0-2, id=FUSE}, BodyType:String, Body:Charles, + >>> (file-to-queue) from(timer://demo?period=2000&repeatCount=15) --> ref:users method: getUser <<< Pattern:InOnly, Headers:{breadcrumbId=ID-biker-chm-local-53796-1322044729997-0-5, firedTime=Wed Nov 23 11:38:53 CET 2011}, BodyType:null, Body:[Body is null] + >>> (file-to-queue) ref:users method: getUser --> aggregate <<< Pattern:InOnly, Headers:{firedTime=Wed Nov 23 11:38:53 CET 2011, id=FUSE, breadcrumbId=ID-biker-chm-local-53796-1322044729997-0-5}, BodyType:String, Body:Raul, + + 6) Verify that a blob object exist in the DB + SELECT * FROM AGGREGATIONREPO1 + 7) Restart camel route and verify that aggregation process continues + + + + + diff --git a/aggregator/pom.xml b/aggregator/pom.xml new file mode 100644 index 0000000..7123fed --- /dev/null +++ b/aggregator/pom.xml @@ -0,0 +1,91 @@ + + + + 4.0.0 + + + com.fusesource.examples + camel-persistence-part2 + 1.0 + + + com.fusesource.examples.camel-persistence-part2 + aggregator + FuseSource :: Examples :: Fuse ESB & Persistence :: Camel - Aggregator + + + + com.fusesource.examples.camel-persistence-part2 + dao + ${project.version} + + + + org.springframework + org.springframework.jdbc + ${spring-version} + + + com.h2database + h2 + ${h2-version} + + + commons-dbcp + commons-dbcp + 1.4 + + + + org.apache.openjpa + openjpa + 2.1.0 + compile + + + org.apache.camel + camel-core + ${camel-version} + + + org.apache.camel + camel-spring + ${camel-version} + + + org.apache.camel + camel-sql + ${camel-version} + + + org.apache.camel + camel-bindy + ${camel-version} + + + + org.slf4j + slf4j-log4j12 + ${slf4j-version} + + + log4j + log4j + ${log4j-version} + + + + + + + org.apache.camel + camel-maven-plugin + ${camel-version} + + META-INF/spring/camelRoutes.xml + + + + + + \ No newline at end of file diff --git a/aggregator/src/main/java/com/fusesource/examples/persistence/part2/aggregator/MyAggregationStrategy.java b/aggregator/src/main/java/com/fusesource/examples/persistence/part2/aggregator/MyAggregationStrategy.java new file mode 100644 index 0000000..9f2ef6a --- /dev/null +++ b/aggregator/src/main/java/com/fusesource/examples/persistence/part2/aggregator/MyAggregationStrategy.java @@ -0,0 +1,34 @@ +package com.fusesource.examples.persistence.part2.aggregator; + +/** + * Copyright 2011 FuseSource + * + * Licensed 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. + */ + +import org.apache.camel.Exchange; +import org.apache.camel.processor.aggregate.AggregationStrategy; + +public class MyAggregationStrategy implements AggregationStrategy { + + public Exchange aggregate(Exchange oldExchange, Exchange newExchange) { + if (oldExchange == null) { + return newExchange; + } + String body1 = oldExchange.getIn().getBody(String.class); + String body2 = newExchange.getIn().getBody(String.class); + + oldExchange.getIn().setBody(body1 + body2); + return oldExchange; + } + } \ No newline at end of file diff --git a/aggregator/src/main/java/com/fusesource/examples/persistence/part2/aggregator/Users.java b/aggregator/src/main/java/com/fusesource/examples/persistence/part2/aggregator/Users.java new file mode 100644 index 0000000..88c81b8 --- /dev/null +++ b/aggregator/src/main/java/com/fusesource/examples/persistence/part2/aggregator/Users.java @@ -0,0 +1,59 @@ +package com.fusesource.examples.persistence.part2.aggregator; + +/** + * Copyright 2011 FuseSource + * + * Licensed 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. + */ + +import org.apache.camel.Exchange; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +public class Users implements Serializable { + + private static List aList = new ArrayList(); + private static int count = -1; + + static { + aList.add("Charles, "); + aList.add("Raul, "); + aList.add("Emma, "); + aList.add("Corine, "); + aList.add("James, "); + aList.add("Rich, "); + aList.add("Claus, "); + aList.add("Hiram, "); + aList.add("Gert, "); + aList.add("Willem, "); + aList.add("Larry, "); + aList.add("Matt."); + } + + public void getUser(Exchange ex) throws Exception { + if (count <= 10) { + count++; + } + + if (count == 3) { + // throw new Exception("$$$ The machine has crashed."); + } + + ex.getIn().setHeader("id","FUSE"); + ex.getIn().setBody(aList.get(count)); + + } + +} diff --git a/aggregator/src/main/resources/META-INF/spring/camelRoutes.xml b/aggregator/src/main/resources/META-INF/spring/camelRoutes.xml new file mode 100644 index 0000000..a0323e8 --- /dev/null +++ b/aggregator/src/main/resources/META-INF/spring/camelRoutes.xml @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
id
+
+ +
+
+ +
+ + +
diff --git a/aggregator/src/main/resources/log4j.properties b/aggregator/src/main/resources/log4j.properties new file mode 100644 index 0000000..7febcf7 --- /dev/null +++ b/aggregator/src/main/resources/log4j.properties @@ -0,0 +1,21 @@ +# +# The logging properties used +# +log4j.rootLogger=INFO, out + +# uncomment the following line to turn on Camel debugging +#log4j.logger.org.apache.camel=DEBUG + +# uncomment the following line to turn on ActiveMQ debugging +#log4j.logger.org.apache.activemq=DEBUG + +log4j.logger.org.springframework=WARN + + +# CONSOLE appender not used by default +log4j.appender.out=org.apache.log4j.ConsoleAppender +log4j.appender.out.layout=org.apache.log4j.PatternLayout +log4j.appender.out.layout.ConversionPattern=[%30.30t] %-30.30c{1} %-5p %m%n +#log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n + +log4j.throwableRenderer=org.apache.log4j.EnhancedThrowableRenderer \ No newline at end of file diff --git a/dao-jta/pom.xml b/dao-jta/pom.xml new file mode 100644 index 0000000..e5403f6 --- /dev/null +++ b/dao-jta/pom.xml @@ -0,0 +1,164 @@ + + + + + 4.0.0 + + + com.fusesource.examples + camel-persistence-part2 + 1.0 + + + com.fusesource.examples.camel-persistence-part2 + dao-jta + FuseSource :: Examples :: Fuse ESB & Persistence :: DAO - JTA + bundle + + + + javax.persistence;resolution:=optional;version="[1.1.0,2.1.0)", + javax.persistence.criteria;resolution:=optional;version="[1.1.0,2.1.0)", + javax.persistence.metamodel;resolution:=optional;version="[1.1.0,2.1.0)", + javax.persistence.spi;resolution:=optional;version="[1.1.0,2.1.0)", + javax.sql;resolution:=optional, + javax.transaction;resolution:=optional;version=1.1, + org.aopalliance.aop;resolution:=optional, + org.aspectj.lang;resolution:=optional, + org.apache.camel.dataformat.bindy.annotation;version=2.6, + org.apache.commons.dbcp;resolution:=optional;version="[1.2,1.5)", + org.apache.commons.lang.builder;version="[2.4,3.0)", + org.apache.commons.logging, + org.apache.log4j, + org.apache.openjpa.conf;resolution:=optional;version="[2.0,3.0)", + org.apache.openjpa.enhance;version=2.1, + org.apache.openjpa.persistence;resolution:=optional;version="[2.0,3.0)", + org.apache.openjpa.persistence.criteria;resolution:=optional;version="[2.0,3.0)", + org.apache.openjpa.persistence.query;resolution:=optional;version="[2.0,3.0)", + org.apache.openjpa.util;version=2.1, + org.apache.xbean.spring.jndi, + org.h2;resolution:=optional, + org.springframework.aop;resolution:=optional;version="[2.5,4.0)", + org.springframework.aop.framework;resolution:=optional;version="[2.5,4.0)", + org.springframework.context.weaving;resolution:=optional;version="[2.5,4.0)", + org.springframework.instrument.classloading;resolution:=optional;version="[2.5,4.0)", + org.springframework.orm;resolution:=optional;version="[2.5,4.0)", + org.springframework.orm.jpa;resolution:=optional;version="[2.5,4.0)", + org.springframework.orm.jpa.support;resolution:=optional;version="[2.5,4.0)", + org.springframework.orm.jpa.vendor;resolution:=optional;version="[2.5,4.0)", + org.springframework.stereotype;version=3.0, + org.springframework.transaction;resolution:=optional;version="[2.5,4.0)", + org.springframework.transaction.annotation;version=3.0, + org.springframework.transaction.aspectj;resolution:=optional;version="[2.5,4.0)", + org.springframework.transaction.jta;version=3.0, + org.springframework.transaction.support;resolution:=optional;version="[2.5,4.0)", + serp.util, + * + + + com.fusesource.examples.persistence.part2.dao, + com.fusesource.examples.persistence.part2.model + + + com.fusesource.examples.persistence.part2.dao.impl + + + + + + + + org.apache.camel + camel-jpa + ${camel-version} + compile + + + org.apache.geronimo.specs + geronimo-jpa_3.0_spec + + + + + org.apache.camel + camel-bindy + ${camel-version} + compile + + + + commons-lang + commons-lang + 2.6 + + + commons-logging + commons-logging + ${commons-logging-version} + + + + org.apache.openjpa + openjpa + ${openjpa-version} + compile + + + + org.springframework + org.springframework.transaction + ${spring-version} + + + + + + + + org.codehaus.mojo + openjpa-maven-plugin + ${openjpa-plugin-version} + + **/model/*.class + true + true + + + + enhancer + process-classes + + enhance + + + + + + org.apache.openjpa + openjpa + ${openjpa-version} + + + commons-logging + commons-logging + ${commons-logging-version} + + + + + + \ No newline at end of file diff --git a/dao-jta/src/main/java/com/fusesource/examples/persistence/part2/dao/IncidentDAO.java b/dao-jta/src/main/java/com/fusesource/examples/persistence/part2/dao/IncidentDAO.java new file mode 100644 index 0000000..df165d3 --- /dev/null +++ b/dao-jta/src/main/java/com/fusesource/examples/persistence/part2/dao/IncidentDAO.java @@ -0,0 +1,34 @@ +package com.fusesource.examples.persistence.part2.dao; + +/** + * Copyright 2011 FuseSource + * + * Licensed 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. + */ + +import com.fusesource.examples.persistence.part2.model.Incident; + +import java.util.List; + +public interface IncidentDAO { + + public abstract Incident getIncident(long paramLong); + + public abstract List findIncident(); + + public abstract List findIncident(String paramString); + + public abstract void saveIncident(Incident paramIncident); + + public abstract void removeIncident(long paramLong); +} diff --git a/dao-jta/src/main/java/com/fusesource/examples/persistence/part2/dao/impl/IncidentDAOImpl.java b/dao-jta/src/main/java/com/fusesource/examples/persistence/part2/dao/impl/IncidentDAOImpl.java new file mode 100644 index 0000000..7cf83b7 --- /dev/null +++ b/dao-jta/src/main/java/com/fusesource/examples/persistence/part2/dao/impl/IncidentDAOImpl.java @@ -0,0 +1,74 @@ +package com.fusesource.examples.persistence.part2.dao.impl; + +/** + * Copyright 2011 FuseSource + * + * Licensed 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. + */ + +import com.fusesource.examples.persistence.part2.dao.IncidentDAO; +import com.fusesource.examples.persistence.part2.model.Incident; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.Query; +import java.util.List; + +@Repository("daoReport") +public class IncidentDAOImpl implements IncidentDAO { + + private static final transient Log LOG = LogFactory.getLog(IncidentDAOImpl.class); + + @PersistenceContext + private EntityManager em; + private static final String findIncidentByReference = "select i from Incident as i where i.incidentRef = :ref"; + private static final String findIncident = "select i from Incident as i"; + + public List findIncident() { + Query q = this.em.createQuery("select i from Incident as i"); + + List list = q.getResultList(); + + return list; + } + + public List findIncident(String key) { + Query q = this.em.createQuery("select i from Incident as i where i.incidentRef = :ref"); + q.setParameter("ref", key); + List list = q.getResultList(); + + return list; + } + + public Incident getIncident(long id) { + return (Incident) this.em.find(Incident.class, Long.valueOf(id)); + } + + public void removeIncident(long id) { + Object record = this.em.find(Incident.class, Long.valueOf(id)); + this.em.remove(record); + this.em.flush(); + } + + @Transactional(propagation = Propagation.REQUIRED) + public void saveIncident(Incident incident) { + System.out.println(">>> Indident to be saved : " + incident); + this.em.persist(incident); + this.em.flush(); + } +} \ No newline at end of file diff --git a/dao-jta/src/main/java/com/fusesource/examples/persistence/part2/model/Abstract.java b/dao-jta/src/main/java/com/fusesource/examples/persistence/part2/model/Abstract.java new file mode 100644 index 0000000..515b5d4 --- /dev/null +++ b/dao-jta/src/main/java/com/fusesource/examples/persistence/part2/model/Abstract.java @@ -0,0 +1,34 @@ +package com.fusesource.examples.persistence.part2.model; + +/** + * Copyright 2011 FuseSource + * + * Licensed 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. + */ + +import org.apache.commons.lang.builder.ToStringBuilder; +import org.apache.commons.lang.builder.ToStringStyle; + +public abstract class Abstract { + + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE); + } + +} diff --git a/dao-jta/src/main/java/com/fusesource/examples/persistence/part2/model/Incident.java b/dao-jta/src/main/java/com/fusesource/examples/persistence/part2/model/Incident.java new file mode 100644 index 0000000..cc22379 --- /dev/null +++ b/dao-jta/src/main/java/com/fusesource/examples/persistence/part2/model/Incident.java @@ -0,0 +1,164 @@ +package com.fusesource.examples.persistence.part2.model; + +/** + * Copyright 2011 FuseSource + * + * Licensed 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. + */ + +import org.apache.camel.dataformat.bindy.annotation.CsvRecord; +import org.apache.camel.dataformat.bindy.annotation.DataField; + +import javax.persistence.*; +import java.io.Serializable; +import java.util.Date; + +@CsvRecord(separator = ",") +@Entity +@Table(name = "T_INCIDENT") +public class Incident extends Abstract implements Serializable { + + private static final long serialVersionUID = 1L; + + @Column(name = "INCIDENT_REF", length = 55) + @DataField(pos = 1) + private String incidentRef; + + @Column(name = "INCIDENT_DATE") + @DataField(pos = 2, pattern = "dd-mm-yyyy") + private Date incidentDate; + + @Column(name = "GIVEN_NAME", length = 35) + @DataField(pos = 3) + private String givenName; + + @Column(name = "FAMILY_NAME", length = 35) + @DataField(pos = 4) + private String familyName; + + @Column(name = "SUMMARY", length = 35) + @DataField(pos = 5) + private String summary; + + @Column(name = "DETAILS") + @DataField(pos = 6) + private String details; + + @Column(name = "EMAIL", length = 60) + @DataField(pos = 7) + private String email; + + @Column(name = "PHONE", length = 35) + @DataField(pos = 8) + private String phone; + + @Id + @GeneratedValue(strategy=GenerationType.AUTO) + @Column(name = "INCIDENT_ID") + private long incidentId; + + @Column(name = "CREATION_USER") + private String creationUser; + + @Column(name = "CREATION_DATE") + private Date creationDate; + + + public long getIncidentId() { + return incidentId; + } + + public void setIncidentId(long incidentId) { + this.incidentId = incidentId; + } + + public String getIncidentRef() { + return incidentRef; + } + + public void setIncidentRef(String incidentRef) { + this.incidentRef = incidentRef; + } + + public Date getIncidentDate() { + return incidentDate; + } + + public void setIncidentDate(Date incidentDate) { + this.incidentDate = incidentDate; + } + + public String getGivenName() { + return givenName; + } + + public void setGivenName(String givenName) { + this.givenName = givenName; + } + + public String getFamilyName() { + return familyName; + } + + public void setFamilyName(String familyName) { + this.familyName = familyName; + } + + public String getSummary() { + return summary; + } + + public void setSummary(String summary) { + this.summary = summary; + } + + public String getDetails() { + return details; + } + + public void setDetails(String details) { + this.details = details; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public String getCreationUser() { + return creationUser; + } + + public void setCreationUser(String creationUser) { + this.creationUser = creationUser; + } + + public Date getCreationDate() { + return creationDate; + } + + public void setCreationDate(Date creationDate) { + this.creationDate = creationDate; + } +} diff --git a/dao-jta/src/main/resources/META-INF/persistence.xml b/dao-jta/src/main/resources/META-INF/persistence.xml new file mode 100644 index 0000000..0d65182 --- /dev/null +++ b/dao-jta/src/main/resources/META-INF/persistence.xml @@ -0,0 +1,58 @@ + + + + + + + org.apache.openjpa.persistence.PersistenceProviderImpl + + + osgi:service/javax.sql.DataSource/(datasource=reportincidentdbXA) + + osgi:service/javax.sql.DataSource/(datasource=reportincidentdb) + + com.fusesource.examples.persistence.part2.model.Incident + true + + + + + + + + + + + + + + + + diff --git a/dao-jta/src/main/resources/META-INF/spring/springJPA.xml b/dao-jta/src/main/resources/META-INF/spring/springJPA.xml new file mode 100644 index 0000000..772c7e5 --- /dev/null +++ b/dao-jta/src/main/resources/META-INF/spring/springJPA.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/dao/pom.xml b/dao/pom.xml new file mode 100644 index 0000000..0141196 --- /dev/null +++ b/dao/pom.xml @@ -0,0 +1,162 @@ + + + + + 4.0.0 + + + com.fusesource.examples + camel-persistence-part2 + 1.0 + + + com.fusesource.examples.camel-persistence-part2 + dao + FuseSource :: Examples :: Fuse ESB & Persistence :: DAO + bundle + + + + org.h2;resolution:=optional, + javax.persistence;resolution:=optional;version="[1.1.0,2.1.0)", + javax.persistence.criteria;resolution:=optional;version="[1.1.0,2.1.0)", + javax.persistence.metamodel;resolution:=optional;version="[1.1.0,2.1.0)", + javax.persistence.spi;resolution:=optional;version="[1.1.0,2.1.0)", + javax.sql;resolution:=optional, + javax.transaction;resolution:=optional;version=1.1, + org.aopalliance.aop;resolution:=optional, + org.apache.camel.dataformat.bindy.annotation;version=2.6, + org.apache.commons.dbcp;resolution:=optional;version="[1.2,1.5)", + org.apache.commons.lang.builder;version="[2.4,3.0)", + org.apache.commons.logging, + org.apache.log4j, + org.apache.openjpa.conf;resolution:=optional;version="[2.0,3.0)", + org.apache.openjpa.enhance;version=2.1, + org.apache.openjpa.persistence;resolution:=optional;version="[2.0,3.0)", + org.apache.openjpa.persistence.criteria;resolution:=optional;version="[2.0,3.0)", + org.apache.openjpa.persistence.query;resolution:=optional;version="[2.0,3.0)", + org.apache.openjpa.util;version=2.1, + org.apache.xbean.spring.jndi, + org.aspectj.lang;resolution:=optional, + org.springframework.aop;resolution:=optional;version="[2.5,4.0)", + org.springframework.aop.framework;resolution:=optional;version="[2.5,4.0)", + org.springframework.context.weaving;resolution:=optional;version="[2.5,4.0)", + org.springframework.instrument.classloading;resolution:=optional;version="[2.5,4.0)", + org.springframework.orm;resolution:=optional;version="[2.5,4.0)", + org.springframework.orm.jpa;resolution:=optional;version="[2.5,4.0)", + org.springframework.orm.jpa.support;resolution:=optional;version="[2.5,4.0)", + org.springframework.orm.jpa.vendor;resolution:=optional;version="[2.5,4.0)", + org.springframework.stereotype;version=3.0, + org.springframework.transaction;resolution:=optional;version="[2.5,4.0)", + org.springframework.transaction.annotation;version=3.0, + org.springframework.transaction.aspectj;resolution:=optional;version="[2.5,4.0)", + org.springframework.transaction.jta;version=3.0, + org.springframework.transaction.support;resolution:=optional;version="[2.5,4.0)", + serp.util, + * + + + com.fusesource.examples.persistence.part2.dao, + com.fusesource.examples.persistence.part2.model + + + com.fusesource.examples.persistence.part2.dao.impl + + + + + + + + org.apache.camel + camel-jpa + ${camel-version} + compile + + + org.apache.geronimo.specs + geronimo-jpa_3.0_spec + + + + + org.apache.camel + camel-bindy + ${camel-version} + compile + + + + + commons-lang + commons-lang + 2.6 + + + commons-logging + commons-logging + ${commons-logging-version} + + + + + org.apache.openjpa + openjpa + ${openjpa-version} + compile + + + + + + + + org.codehaus.mojo + openjpa-maven-plugin + ${openjpa-plugin-version} + + **/model/*.class + true + true + + + + enhancer + process-classes + + enhance + + + + + + + org.apache.openjpa + openjpa + ${openjpa-version} + + + commons-logging + commons-logging + ${commons-logging-version} + + + + + + + \ No newline at end of file diff --git a/dao/src/main/java/com/fusesource/examples/persistence/part2/dao/IncidentDAO.java b/dao/src/main/java/com/fusesource/examples/persistence/part2/dao/IncidentDAO.java new file mode 100644 index 0000000..df165d3 --- /dev/null +++ b/dao/src/main/java/com/fusesource/examples/persistence/part2/dao/IncidentDAO.java @@ -0,0 +1,34 @@ +package com.fusesource.examples.persistence.part2.dao; + +/** + * Copyright 2011 FuseSource + * + * Licensed 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. + */ + +import com.fusesource.examples.persistence.part2.model.Incident; + +import java.util.List; + +public interface IncidentDAO { + + public abstract Incident getIncident(long paramLong); + + public abstract List findIncident(); + + public abstract List findIncident(String paramString); + + public abstract void saveIncident(Incident paramIncident); + + public abstract void removeIncident(long paramLong); +} diff --git a/dao/src/main/java/com/fusesource/examples/persistence/part2/dao/impl/IncidentDAOImpl.java b/dao/src/main/java/com/fusesource/examples/persistence/part2/dao/impl/IncidentDAOImpl.java new file mode 100644 index 0000000..e9956aa --- /dev/null +++ b/dao/src/main/java/com/fusesource/examples/persistence/part2/dao/impl/IncidentDAOImpl.java @@ -0,0 +1,73 @@ +package com.fusesource.examples.persistence.part2.dao.impl; + +/** + * Copyright 2011 FuseSource + * + * Licensed 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. + */ + +import com.fusesource.examples.persistence.part2.model.Incident; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import com.fusesource.examples.persistence.part2.dao.IncidentDAO; +import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.Query; +import java.util.List; + +@Repository("daoReport") +public class IncidentDAOImpl implements IncidentDAO { + private static final transient Log LOG = LogFactory.getLog(IncidentDAOImpl.class); + + @PersistenceContext + private EntityManager em; + private static final String findIncidentByReference = "select i from Incident as i where i.incidentRef = :ref"; + private static final String findIncident = "select i from Incident as i"; + + public List findIncident() { + Query q = this.em.createQuery("select i from Incident as i"); + + List list = q.getResultList(); + + return list; + } + + public List findIncident(String key) { + Query q = this.em.createQuery("select i from Incident as i where i.incidentRef = :ref"); + q.setParameter("ref", key); + List list = q.getResultList(); + + return list; + } + + public Incident getIncident(long id) { + return (Incident) this.em.find(Incident.class, Long.valueOf(id)); + } + + public void removeIncident(long id) { + Object record = this.em.find(Incident.class, Long.valueOf(id)); + this.em.remove(record); + this.em.flush(); + } + + @Transactional(propagation = Propagation.REQUIRED) + public void saveIncident(Incident incident) { + System.out.println(">>> Indident to be saved : " + incident); + this.em.persist(incident); + this.em.flush(); + } +} \ No newline at end of file diff --git a/dao/src/main/java/com/fusesource/examples/persistence/part2/model/Abstract.java b/dao/src/main/java/com/fusesource/examples/persistence/part2/model/Abstract.java new file mode 100644 index 0000000..6fea596 --- /dev/null +++ b/dao/src/main/java/com/fusesource/examples/persistence/part2/model/Abstract.java @@ -0,0 +1,34 @@ +package com.fusesource.examples.persistence.part2.model; + +/** + * Copyright 2011 FuseSource + * + * Licensed 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. + */ + +import org.apache.commons.lang.builder.ToStringBuilder; +import org.apache.commons.lang.builder.ToStringStyle; + +public abstract class Abstract { + + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE); + } + +} diff --git a/dao/src/main/java/com/fusesource/examples/persistence/part2/model/Incident.java b/dao/src/main/java/com/fusesource/examples/persistence/part2/model/Incident.java new file mode 100644 index 0000000..6fa1fa1 --- /dev/null +++ b/dao/src/main/java/com/fusesource/examples/persistence/part2/model/Incident.java @@ -0,0 +1,163 @@ +package com.fusesource.examples.persistence.part2.model; + +/** + * Copyright 2011 FuseSource + * + * Licensed 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. + */ + +import org.apache.camel.dataformat.bindy.annotation.CsvRecord; +import org.apache.camel.dataformat.bindy.annotation.DataField; + +import javax.persistence.*; +import java.io.Serializable; +import java.util.Date; + +@CsvRecord(separator = ",") +@Entity +@Table(name = "T_INCIDENT") +public class Incident extends Abstract implements Serializable { + + private static final long serialVersionUID = 1L; + + @Column(name = "INCIDENT_REF", length = 55) + @DataField(pos = 1) + private String incidentRef; + + @Column(name = "INCIDENT_DATE") + @DataField(pos = 2, pattern = "dd-mm-yyyy") + private Date incidentDate; + + @Column(name = "GIVEN_NAME", length = 35) + @DataField(pos = 3) + private String givenName; + + @Column(name = "FAMILY_NAME", length = 35) + @DataField(pos = 4) + private String familyName; + + @Column(name = "SUMMARY", length = 35) + @DataField(pos = 5) + private String summary; + + @Column(name = "DETAILS") + @DataField(pos = 6) + private String details; + + @Column(name = "EMAIL", length = 60) + @DataField(pos = 7) + private String email; + + @Column(name = "PHONE", length = 35) + @DataField(pos = 8) + private String phone; + + @Id + @GeneratedValue(strategy=GenerationType.AUTO) + @Column(name = "INCIDENT_ID") + private long incidentId; + + @Column(name = "CREATION_USER") + private String creationUser; + + @Column(name = "CREATION_DATE") + private Date creationDate; + + public long getIncidentId() { + return incidentId; + } + + public void setIncidentId(long incidentId) { + this.incidentId = incidentId; + } + + public String getIncidentRef() { + return incidentRef; + } + + public void setIncidentRef(String incidentRef) { + this.incidentRef = incidentRef; + } + + public Date getIncidentDate() { + return incidentDate; + } + + public void setIncidentDate(Date incidentDate) { + this.incidentDate = incidentDate; + } + + public String getGivenName() { + return givenName; + } + + public void setGivenName(String givenName) { + this.givenName = givenName; + } + + public String getFamilyName() { + return familyName; + } + + public void setFamilyName(String familyName) { + this.familyName = familyName; + } + + public String getSummary() { + return summary; + } + + public void setSummary(String summary) { + this.summary = summary; + } + + public String getDetails() { + return details; + } + + public void setDetails(String details) { + this.details = details; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public String getCreationUser() { + return creationUser; + } + + public void setCreationUser(String creationUser) { + this.creationUser = creationUser; + } + + public Date getCreationDate() { + return creationDate; + } + + public void setCreationDate(Date creationDate) { + this.creationDate = creationDate; + } +} diff --git a/dao/src/main/resources/META-INF/persistence.xml b/dao/src/main/resources/META-INF/persistence.xml new file mode 100644 index 0000000..e6a904b --- /dev/null +++ b/dao/src/main/resources/META-INF/persistence.xml @@ -0,0 +1,53 @@ + + + + + + com.fusesource.examples.persistence.part2.model.Incident + + true + + + + + + + + + + + + + diff --git a/dao/src/main/resources/META-INF/spring/springJPA.xml b/dao/src/main/resources/META-INF/spring/springJPA.xml new file mode 100644 index 0000000..c0b26d8 --- /dev/null +++ b/dao/src/main/resources/META-INF/spring/springJPA.xml @@ -0,0 +1,89 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/data/csv-one-record-allok.txt b/data/csv-one-record-allok.txt new file mode 100644 index 0000000..bb18e13 --- /dev/null +++ b/data/csv-one-record-allok.txt @@ -0,0 +1 @@ +666,22-03-2011,Claus,Ibsen,incident camel-666,this is a report incident for camel-666,cibsen@gmail.com,+111 10 20 300 \ No newline at end of file diff --git a/data/csv-one-record-failjms-dbok.txt b/data/csv-one-record-failjms-dbok.txt new file mode 100644 index 0000000..bb18e13 --- /dev/null +++ b/data/csv-one-record-failjms-dbok.txt @@ -0,0 +1 @@ +666,22-03-2011,Claus,Ibsen,incident camel-666,this is a report incident for camel-666,cibsen@gmail.com,+111 10 20 300 \ No newline at end of file diff --git a/data/csv-one-record-failjms-faildb.txt b/data/csv-one-record-failjms-faildb.txt new file mode 100644 index 0000000..bb18e13 --- /dev/null +++ b/data/csv-one-record-failjms-faildb.txt @@ -0,0 +1 @@ +666,22-03-2011,Claus,Ibsen,incident camel-666,this is a report incident for camel-666,cibsen@gmail.com,+111 10 20 300 \ No newline at end of file diff --git a/data/csv-one-record-jmsok-faildb.txt b/data/csv-one-record-jmsok-faildb.txt new file mode 100644 index 0000000..bb18e13 --- /dev/null +++ b/data/csv-one-record-jmsok-faildb.txt @@ -0,0 +1 @@ +666,22-03-2011,Claus,Ibsen,incident camel-666,this is a report incident for camel-666,cibsen@gmail.com,+111 10 20 300 \ No newline at end of file diff --git a/data/csv-one-record.txt b/data/csv-one-record.txt new file mode 100644 index 0000000..bb18e13 --- /dev/null +++ b/data/csv-one-record.txt @@ -0,0 +1 @@ +666,22-03-2011,Claus,Ibsen,incident camel-666,this is a report incident for camel-666,cibsen@gmail.com,+111 10 20 300 \ No newline at end of file diff --git a/data/csv-two-record.txt b/data/csv-two-record.txt new file mode 100644 index 0000000..79906ac --- /dev/null +++ b/data/csv-two-record.txt @@ -0,0 +1,2 @@ +001,22-03-2011,Claus,Ibsen,incident camel-001,this is a report incident for camel-001,cibsen@gmail.com,+111 10 20 300 +002,23-03-2011,Charles,Moulliard,incident smx-002,this is a report incident for smx-002,cmoulliard@gmail.com,+222 10 20 300 \ No newline at end of file diff --git a/data/csv.txt b/data/csv.txt new file mode 100644 index 0000000..866b3ee --- /dev/null +++ b/data/csv.txt @@ -0,0 +1,9 @@ +001,22-03-2011,Claus,Ibsen,incident camel-001,this is a report incident for camel-001,cibsen@gmail.com,+111 10 20 300 +002,23-03-2011,Charles,Moulliard,incident smx-002,this is a report incident for smx-002,cmoulliard@gmail.com,+222 10 20 300 +003,24-03-2011,Guillaume,Nodet,incident camel-123,this is a report incident for camel-123,gnodet@gmail.com,+333 10 20 300 +004,25-03-2011,Gert,Vanthienen,incident camel-454,this is a report incident for camel-454,gvanthienen@gmail.com,+444 10 20 300 +005,26-03-2011,Jonathan,Anstey,incident smx-023,this is a report incident for smx-023,janstey@gmail.com,+555 10 20 300 +007,27-03-2011,Willem,Jiang,incident smx-456,this is a report incident for smx-456,wjiang@gmail.com,+666 10 20 300 +008,28-03-2011,Matt,Raibble,incident appfuse-123,this is a report incident for appfuse-123,mraibble@gmail.com,+777 10 20 300 +009,29-03-2011,Jean-Baptiste,Onofre,incident smx3-088,this is a report incident for smx3-088,cjbonofre@gmail.com,+888 10 20 300 +010,30-03-2011,Hadrian,Zbarcea,incident camel-005,this is a report incident for camel-005,hzbarcea@gmail.com,+999 10 20 300 \ No newline at end of file diff --git a/datasource/pom.xml b/datasource/pom.xml new file mode 100644 index 0000000..b94d2ae --- /dev/null +++ b/datasource/pom.xml @@ -0,0 +1,55 @@ + + + + + 4.0.0 + + + com.fusesource.examples + camel-persistence-part2 + 1.0 + + + com.fusesource.examples.camel-persistence-part2 + datasource + FuseSource :: Examples :: Fuse ESB & Persistence :: Datasource + bundle + + + + * + + + + + + + + + + OSGI-INF/blueprint + false + ${basedir}/src/main/resources/OSGI-INF/blueprint + + *.xml + + + + + + diff --git a/datasource/src/main/resources/OSGI-INF/blueprint/datasource.xml b/datasource/src/main/resources/OSGI-INF/blueprint/datasource.xml new file mode 100644 index 0000000..55f66ae --- /dev/null +++ b/datasource/src/main/resources/OSGI-INF/blueprint/datasource.xml @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/features/pom.xml b/features/pom.xml new file mode 100644 index 0000000..95bb3d1 --- /dev/null +++ b/features/pom.xml @@ -0,0 +1,88 @@ + + + + + 4.0.0 + + + com.fusesource.examples + camel-persistence-part2 + 1.0 + + + com.fusesource.examples.camel-persistence-part2 + persistence + FuseSource :: Examples :: Fuse ESB & Persistence :: Features + jar + + + + + + + ${pom.basedir}/src/main/resources + true + + **/* + + + + + + + org.apache.maven.plugins + maven-resources-plugin + + + filter + generate-resources + + resources + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + ${build-helper-maven-plugin-version} + + + attach-artifacts + package + + attach-artifact + + + + + target/classes/reportincident.xml + xml + features + + + + + + + + + + + + \ No newline at end of file diff --git a/features/src/main/resources/reportincident.xml b/features/src/main/resources/reportincident.xml new file mode 100644 index 0000000..4f1eaff --- /dev/null +++ b/features/src/main/resources/reportincident.xml @@ -0,0 +1,76 @@ + + + + + camel-bindy + camel-jpa + camel-activemq + http + jdbc-driver-h2 + jndi + transaction + jpa + spring-persistence + openjpa + mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.aspectj/1.6.8_1 + mvn:com.fusesource.examples.camel-persistence-part2/datasource/${project.version} + mvn:com.fusesource.examples.camel-persistence-part2/dao/${project.version} + mvn:com.fusesource.examples.camel-persistence-part2/route-two-tx-manager/${project.version} + + + + camel-bindy + camel-jpa + camel-activemq + http + jdbc-driver-h2 + jndi + transaction + jpa + spring-persistence + openjpa + mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.aspectj/1.6.8_1 + mvn:com.fusesource.examples.camel-persistence-part2/datasource/${project.version} + mvn:com.fusesource.examples.camel-persistence-part2/dao-jta/${project.version} + mvn:com.fusesource.examples.camel-persistence-part2/route-one-tx-manager/${project.version} + + + + mvn:org.springframework/spring-orm/${spring-version} + mvn:org.springframework/spring-jdbc/${spring-version} + mvn:org.springframework/spring-aspects/${spring-version} + + + + mvn:commons-pool/commons-pool/1.5.5 + mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.commons-dbcp/1.4_1 + mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.hsqldb/1.8.0.10_1 + + + + mvn:commons-pool/commons-pool/1.5.5 + wrap:mvn:com.experlog/xapool/1.5.0 + mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.commons-dbcp/1.4_1 + mvn:com.h2database/h2/${h2-version} + + + + mvn:org.apache.geronimo.specs/geronimo-jpa_2.0_spec/1.1 + mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.commons-dbcp/1.4_1 + mvn:org.apache.openjpa/openjpa/${openjpa-version} + + \ No newline at end of file diff --git a/idempotent/datainsert/.camel/csv-one-record.txt b/idempotent/datainsert/.camel/csv-one-record.txt new file mode 100644 index 0000000..bb18e13 --- /dev/null +++ b/idempotent/datainsert/.camel/csv-one-record.txt @@ -0,0 +1 @@ +666,22-03-2011,Claus,Ibsen,incident camel-666,this is a report incident for camel-666,cibsen@gmail.com,+111 10 20 300 \ No newline at end of file diff --git a/idempotent/pom.xml b/idempotent/pom.xml new file mode 100644 index 0000000..115ee07 --- /dev/null +++ b/idempotent/pom.xml @@ -0,0 +1,92 @@ + + + + 4.0.0 + + + com.fusesource.examples + camel-persistence-part2 + 1.0 + + + com.fusesource.examples.camel-persistence-part2 + idempotent + FuseSource :: Examples :: Fuse ESB & Persistence :: Camel - Idempotent + + + + com.fusesource.examples.camel-persistence-part2 + dao + ${project.version} + + + + org.springframework + org.springframework.orm + ${spring-version} + + + com.h2database + h2 + ${h2-version} + + + commons-dbcp + commons-dbcp + 1.4 + + + + org.apache.openjpa + openjpa + 2.1.0 + compile + + + org.apache.camel + camel-core + ${camel-version} + + + org.apache.camel + camel-spring + ${camel-version} + + + org.apache.camel + camel-jpa + ${camel-version} + + + org.apache.camel + camel-bindy + ${camel-version} + + + + org.slf4j + slf4j-log4j12 + ${slf4j-version} + + + log4j + log4j + ${log4j-version} + + + + + + + org.apache.camel + camel-maven-plugin + ${camel-version} + + META-INF/spring/camelRoutes.xml + + + + + + \ No newline at end of file diff --git a/idempotent/src/main/resources/META-INF/persistence.xml b/idempotent/src/main/resources/META-INF/persistence.xml new file mode 100644 index 0000000..71c4727 --- /dev/null +++ b/idempotent/src/main/resources/META-INF/persistence.xml @@ -0,0 +1,36 @@ + + + + + + org.apache.camel.processor.idempotent.jpa.MessageProcessed + + + + + + + + + + + + + diff --git a/idempotent/src/main/resources/META-INF/spring/camelRoutes.xml b/idempotent/src/main/resources/META-INF/spring/camelRoutes.xml new file mode 100644 index 0000000..d6faf3d --- /dev/null +++ b/idempotent/src/main/resources/META-INF/spring/camelRoutes.xml @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
CamelFileName
+ + + ${body} + + +
+
+ +
+ + +
diff --git a/idempotent/src/main/resources/log4j.properties b/idempotent/src/main/resources/log4j.properties new file mode 100644 index 0000000..7febcf7 --- /dev/null +++ b/idempotent/src/main/resources/log4j.properties @@ -0,0 +1,21 @@ +# +# The logging properties used +# +log4j.rootLogger=INFO, out + +# uncomment the following line to turn on Camel debugging +#log4j.logger.org.apache.camel=DEBUG + +# uncomment the following line to turn on ActiveMQ debugging +#log4j.logger.org.apache.activemq=DEBUG + +log4j.logger.org.springframework=WARN + + +# CONSOLE appender not used by default +log4j.appender.out=org.apache.log4j.ConsoleAppender +log4j.appender.out.layout=org.apache.log4j.PatternLayout +log4j.appender.out.layout.ConversionPattern=[%30.30t] %-30.30c{1} %-5p %m%n +#log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n + +log4j.throwableRenderer=org.apache.log4j.EnhancedThrowableRenderer \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..ee4b7f5 --- /dev/null +++ b/pom.xml @@ -0,0 +1,170 @@ + + + + + 4.0.0 + + com.fusesource.examples + camel-persistence-part2 + 1.0 + FuseSource :: Examples :: Fuse ESB & Persistence + pom + + + datasource + dao + dao-jta + route-one-tx-manager + route-two-tx-manager + features + idempotent + aggregator + + + + 1.5 + 2.3.5 + 0.3.1 + 5.5.1-fuse-01-06 + 4.4.1-fuse-01-06 + 2.1.0 + 1.8.0.10 + 1.3.160 + 1.1.1 + 2.8.0-fuse-01-06 + 1.2 + 3.0.5.RELEASE + 1.6.1 + 1.2.12 + + * + + + + + + META-INF/persistence.xml + + + + + org.apache.camel + camel-core + ${camel-version} + + + org.apache.camel + camel-spring + ${camel-version} + + + + + + + + FuseSource Releases + FuseSource Maven Repository + http://repo.fusesource.com/nexus/content/repositories/releases + + false + + + true + + + + + + + + FuseSource Releases + FuseSource Maven Repository + http://repo.fusesource.com/nexus/content/repositories/releases + + false + + + true + + + + + Maven-repo + http://repo1.maven.org/maven2/ + + + + Spring-external-repo + http://repository.springsource.com/maven/bundles/external + + + + Spring-release-repo + http://repository.springsource.com/maven/bundles/release + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.6 + 1.6 + + + + + + org.apache.felix + maven-bundle-plugin + true + ${felix-plugin-version} + + + + ${persistence-file} + + ${pom.artifactId} + + ${osgi-import-pkg} + + + ${osgi-export-pkg} + + + ${osgi-private-pkg} + + + ${osgi-dynamic-pkg} + + <_failok>true + src/main/resources + ${require-bundle} + + + + + + + + \ No newline at end of file diff --git a/route-one-tx-manager/pom.xml b/route-one-tx-manager/pom.xml new file mode 100644 index 0000000..89735b4 --- /dev/null +++ b/route-one-tx-manager/pom.xml @@ -0,0 +1,76 @@ + + + + + + 4.0.0 + + + com.fusesource.examples + camel-persistence-part2 + 1.0 + + + com.fusesource.examples.camel-persistence-part2 + route-one-tx-manager + FuseSource :: Examples :: Fuse ESB & Persistence :: Camel - 1 Tx Manager + bundle + + + + com.fusesource.examples.camel-persistence-part2 + dao-jta + ${project.version} + + + org.apache.activemq + activemq-core + ${activemq-version} + + + org.apache.activemq + activemq-pool + ${activemq-version} + + + org.apache.activemq + activemq-camel + ${activemq-version} + + + com.h2database + h2 + ${h2-version} + + + + + + com.fusesource.examples.persistence.part2.dao, + com.fusesource.examples.persistence.part2.model, + org.apache.camel, + org.h2, + * + + + + com.fusesource.examples.persistence.part2 + + + + \ No newline at end of file diff --git a/route-one-tx-manager/src/main/java/com/fusesource/examples/persistence/part2/ProcessIncidents.java b/route-one-tx-manager/src/main/java/com/fusesource/examples/persistence/part2/ProcessIncidents.java new file mode 100644 index 0000000..ec04cdd --- /dev/null +++ b/route-one-tx-manager/src/main/java/com/fusesource/examples/persistence/part2/ProcessIncidents.java @@ -0,0 +1,82 @@ +package com.fusesource.examples.persistence.part2; + +/** + * Copyright 2011 FuseSource + * + * Licensed 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. + */ + +import com.fusesource.examples.persistence.part2.dao.IncidentDAO; +import com.fusesource.examples.persistence.part2.model.Incident; +import org.apache.camel.Body; +import org.apache.camel.Exchange; + +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Map; + +public class ProcessIncidents { + + private static int counter = 0; + private IncidentDAO incidentDao; + + public Incident extract(Exchange exchange) throws ParseException { + + Map model = (Map) exchange.getIn().getBody(); + String key = "com.fusesource.examples.persistence.part2.model.Incident"; + + DateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); + String currentDate = format.format(new Date()); + Date creationDate = format.parse(currentDate); + + Incident incident = (Incident) model.get(key); + incident.setCreationDate(creationDate); + incident.setCreationUser("file"); + + return incident; + + } + + public void saveReport(@Body Incident incident) { + incidentDao.saveIncident(incident); + } + + public void saveReportTransaction(@Body Incident incident) { + Incident transactionIncident = new Incident(); + transactionIncident.setCreationDate(incident.getCreationDate()); + transactionIncident.setCreationUser("TRANSACTION"); + transactionIncident.setDetails("TRANSACTION"); + transactionIncident.setEmail("TRANSACTION"); + transactionIncident.setFamilyName("TRANSACTION"); + transactionIncident.setPhone("TRANSACTION"); + + incidentDao.saveIncident(transactionIncident); + } + + public void generateError() throws Exception { + System.out.println("%%% ERROR GENERATED %%% - " + counter + " times."); + counter++; + throw new Exception("Cannot connect to Database ...."); + } + + public IncidentDAO getIncidentDao() { + return incidentDao; + } + + public void setIncidentDao(IncidentDAO incidentDao) { + this.incidentDao = incidentDao; + } + +} diff --git a/route-one-tx-manager/src/main/resources/META-INF/spring/camelContext.xml b/route-one-tx-manager/src/main/resources/META-INF/spring/camelContext.xml new file mode 100644 index 0000000..f5cf20b --- /dev/null +++ b/route-one-tx-manager/src/main/resources/META-INF/spring/camelContext.xml @@ -0,0 +1,130 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ${body} + + + + ${file:onlyname} contains 'faildb' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Registering ${exchangeId} + + + + ${file:onlyname} contains 'failjms' + + + + + + + + diff --git a/route-one-tx-manager/src/main/resources/META-INF/spring/springConfig.xml b/route-one-tx-manager/src/main/resources/META-INF/spring/springConfig.xml new file mode 100644 index 0000000..6fc5cfc --- /dev/null +++ b/route-one-tx-manager/src/main/resources/META-INF/spring/springConfig.xml @@ -0,0 +1,97 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/route-two-tx-manager/data/csv.txt b/route-two-tx-manager/data/csv.txt new file mode 100644 index 0000000..866b3ee --- /dev/null +++ b/route-two-tx-manager/data/csv.txt @@ -0,0 +1,9 @@ +001,22-03-2011,Claus,Ibsen,incident camel-001,this is a report incident for camel-001,cibsen@gmail.com,+111 10 20 300 +002,23-03-2011,Charles,Moulliard,incident smx-002,this is a report incident for smx-002,cmoulliard@gmail.com,+222 10 20 300 +003,24-03-2011,Guillaume,Nodet,incident camel-123,this is a report incident for camel-123,gnodet@gmail.com,+333 10 20 300 +004,25-03-2011,Gert,Vanthienen,incident camel-454,this is a report incident for camel-454,gvanthienen@gmail.com,+444 10 20 300 +005,26-03-2011,Jonathan,Anstey,incident smx-023,this is a report incident for smx-023,janstey@gmail.com,+555 10 20 300 +007,27-03-2011,Willem,Jiang,incident smx-456,this is a report incident for smx-456,wjiang@gmail.com,+666 10 20 300 +008,28-03-2011,Matt,Raibble,incident appfuse-123,this is a report incident for appfuse-123,mraibble@gmail.com,+777 10 20 300 +009,29-03-2011,Jean-Baptiste,Onofre,incident smx3-088,this is a report incident for smx3-088,cjbonofre@gmail.com,+888 10 20 300 +010,30-03-2011,Hadrian,Zbarcea,incident camel-005,this is a report incident for camel-005,hzbarcea@gmail.com,+999 10 20 300 \ No newline at end of file diff --git a/route-two-tx-manager/data/csv2.txt b/route-two-tx-manager/data/csv2.txt new file mode 100644 index 0000000..2adff4b --- /dev/null +++ b/route-two-tx-manager/data/csv2.txt @@ -0,0 +1 @@ +001,22-03-2011,Claus,Ibsen,incident camel-001,this is a report incident for camel-001,cibsen@gmail.com,+111 10 20 300 \ No newline at end of file diff --git a/route-two-tx-manager/pom.xml b/route-two-tx-manager/pom.xml new file mode 100644 index 0000000..e2a1525 --- /dev/null +++ b/route-two-tx-manager/pom.xml @@ -0,0 +1,78 @@ + + + + + + 4.0.0 + + + com.fusesource.examples + camel-persistence-part2 + 1.0 + + + com.fusesource.examples.camel-persistence-part2 + route-two-tx-manager + FuseSource :: Examples :: Fuse ESB & Persistence :: Camel - 2 Tx Manager + bundle + + + + com.fusesource.examples.camel-persistence-part2 + dao + 1.0 + provided + + + + org.springframework + org.springframework.jms + ${spring-version} + + + org.apache.activemq + activemq-all + ${activemq-version} + + + com.h2database + h2 + ${h2-version} + + + org.apache.camel + camel-jms + ${camel-version} + + + + + + org.springframework.transaction, + org.apache.activemq, + org.h2, + * + + + + com.fusesource.examples.persistence.part2 + + + + + \ No newline at end of file diff --git a/route-two-tx-manager/src/main/java/com/fusesource/examples/persistence/part2/ProcessIncidents.java b/route-two-tx-manager/src/main/java/com/fusesource/examples/persistence/part2/ProcessIncidents.java new file mode 100644 index 0000000..c9ce2b4 --- /dev/null +++ b/route-two-tx-manager/src/main/java/com/fusesource/examples/persistence/part2/ProcessIncidents.java @@ -0,0 +1,71 @@ +package com.fusesource.examples.persistence.part2; + +/** + * Copyright 2011 FuseSource + * + * Licensed 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. + */ + +import com.fusesource.examples.persistence.part2.model.Incident; +import org.apache.camel.Body; +import org.apache.camel.Exchange; +import com.fusesource.examples.persistence.part2.dao.IncidentDAO; + +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Map; + +public class ProcessIncidents { + + private IncidentDAO incidentDao; + + public Incident extract(Exchange exchange) throws ParseException { + + Map model = (Map) exchange.getIn().getBody(); + String key = "com.fusesource.examples.persistence.part2.model.Incident"; + + DateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); + String currentDate = format.format(new Date()); + Date creationDate = format.parse(currentDate); + + Incident incident = (Incident) model.get(key); + incident.setCreationDate(creationDate); + incident.setCreationUser("file"); + + return incident; + + } + + public void saveReport(@Body Incident incident) { + incidentDao.saveIncident(incident); + } + + public void generateError() throws Exception { + Thread.sleep(2000); + // and now generate an exception to rollback TX + throw new Exception("%%% Database has crashed ...."); + + } + + public IncidentDAO getIncidentDao() { + return incidentDao; + } + + public void setIncidentDao(IncidentDAO incidentDao) { + this.incidentDao = incidentDao; + } + + +} diff --git a/route-two-tx-manager/src/main/resources/META-INF/spring/camelContext.xml b/route-two-tx-manager/src/main/resources/META-INF/spring/camelContext.xml new file mode 100644 index 0000000..e7f17e8 --- /dev/null +++ b/route-two-tx-manager/src/main/resources/META-INF/spring/camelContext.xml @@ -0,0 +1,192 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ${body} + + + + ${file:onlyname} contains 'faildb' + + + + + + + + + + + + + + + + + + java.lang.Exception + + + + + + + + + + + + + + + + + + + + + + + + + + + + + java.lang.Exception + + + + + + + + + + + + + + + + + + + + + + + + + + + + Registering ${exchangeId} + + + + ${file:onlyname} contains 'failjms' + + + + + + + +