Permalink
Browse files

Initial upload

  • Loading branch information...
0 parents commit 1d88fdd01868d74a262cba12a5c9d14c2010a3aa @cmoulliard cmoulliard committed Nov 24, 2011
Showing with 1,334 additions and 0 deletions.
  1. +108 −0 README.txt
  2. +17 −0 database/db/idempotentdb.properties
  3. +17 −0 database/db/reportdb.properties
  4. +4 −0 database/server.properties
  5. +1 −0 jdbc/data/keys.txt
  6. +61 −0 jdbc/pom.xml
  7. +78 −0 jdbc/src/main/resources/META-INF/spring/camelContext.xml
  8. +68 −0 jdbc/src/main/resources/META-INF/spring/camelContext2.xml
  9. +2 −0 jdbc/src/main/resources/com/fusesource/examples/persistence/part1/query.properties
  10. +21 −0 jdbc/src/main/resources/log4j.properties
  11. +1 −0 jpa/data/csv-notinserted.txt
  12. +1 −0 jpa/data/csv-one-record.txt
  13. +9 −0 jpa/data/csv.txt
  14. +9 −0 jpa/data/csv2.txt
  15. +118 −0 jpa/pom.xml
  16. +54 −0 jpa/src/main/java/com/fusesource/examples/persistence/part1/camel/ProcessIncidents.java
  17. +34 −0 jpa/src/main/java/com/fusesource/examples/persistence/part1/model/Abstract.java
  18. +165 −0 jpa/src/main/java/com/fusesource/examples/persistence/part1/model/Incident.java
  19. +39 −0 jpa/src/main/resources/META-INF/persistence.xml
  20. +92 −0 jpa/src/main/resources/META-INF/spring/camelContext.xml
  21. +56 −0 jpa/src/main/resources/META-INF/spring/springJPA.xml
  22. +21 −0 jpa/src/main/resources/log4j.properties
  23. +125 −0 pom.xml
  24. +1 −0 sql-spring/data/key.txt
  25. +1 −0 sql-spring/data/keyParams.txt
  26. +54 −0 sql-spring/pom.xml
  27. +60 −0 sql-spring/src/main/java/com/fusesource/examples/persistence/part1/SqlSpringReportIncident.java
  28. +96 −0 sql-spring/src/main/resources/META-INF/spring/camelContext.xml
  29. +21 −0 sql-spring/src/main/resources/log4j.properties
108 README.txt
@@ -0,0 +1,108 @@
+<!--
+ ~ 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.
+ -->
+
+DESCRIPTION
+===========
+
+This is the material accompanying the presentation of part I - Database persistence with Camel from simple to more elaborated.
+It covers the different demo made during the talk and is organised like that :
+
+database = project containing the scripts to create the database in HSQLDB and the jar file of the HSQLDB server
+jdbc = maven project for camel-jdbc demo
+sql = idem but for camel-sql component
+jpa = mavemn project containing camel routes for JPA persistence
+sql-spring-persistence = maven projetc with additional examples (not covered during the webinars) but could be used to test transaction with SQL component
+
+
+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://192.168.1.2: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 persistence/database/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;
+
+
+HSQL DATABASE
+=============
+
+ 1) Start HSQLDB Server using the command and lib jar provided in database directory
+
+ java -cp lib/hsqldb-1.8.0.10.jar org.hsqldb.Server -database.0 file:db/reportdb -dbname.0 reportdb
+
+ 2) In a separate DOS/UNIX console, start the Swing DataBase Manager console using the following command
+
+ java -cp lib/hsqldb-1.8.0.10.jar org.hsqldb.util.DatabaseManagerSwing --user sa --url jdbc:hsqldb:hsql://localhost/reportdb
+
+ 3) Create Schema and Tables using the script located in the file persistence/database/src/config/hsqldb/reportdb-scripts.sql
+
+ Execute the scripts 1), 2) and 3) defined in this file
+
+MAVEN
+=====
+
+Except for the database directory, the other directories are maven projects. The webinar
+part1 can be build using the command
+
+mvn clean install
+
+in the camel-persistence-part1 directory.
+
+To launch each project individually, simply execute the following command in a DOS/UNIX console
+
+mvn camel:run
+
+Depending in which project you are (jdbc, sql-spring or jpa), you will have to copy files
+to allow the file:// endpoint of the camel routes to read the corresponding file (key.txt, keys.txt or csv.txtx) and insert data
+into the database
+
+
+1) jdbc folder
+cd camel-persistence-part1/jdbc
+cp data/keys.txt target/data/
+
+2) sql-spring folder
+cd camel-persistence-part1/sql-spring
+cp data/key.txt target/datainsert/
+cp data/keyParams.txt target/datainsertparams/
+
+3) jpa folder
+cd camel-persistence-part1/jpa
+cp data/csv.txt target/datainsert/
+cp data/csv-one-record.txt target/datainsert/
+cp data/csv-notinserted.txt target/datainsertrollback/
+more target/datainsertrollback/failed/csv-notinserted.txt
+
+
17 database/db/idempotentdb.properties
@@ -0,0 +1,17 @@
+#HSQL Database Engine 1.8.0.10
+#Wed Apr 13 15:03:18 CEST 2011
+hsqldb.script_format=0
+runtime.gc_interval=0
+sql.enforce_strict_size=false
+hsqldb.cache_size_scale=8
+readonly=false
+hsqldb.nio_data_file=true
+hsqldb.cache_scale=14
+version=1.8.0
+hsqldb.default_table_type=memory
+hsqldb.cache_file_scale=1
+hsqldb.log_size=200
+modified=yes
+hsqldb.cache_version=1.7.0
+hsqldb.original_version=1.8.0
+hsqldb.compatible_version=1.8.0
17 database/db/reportdb.properties
@@ -0,0 +1,17 @@
+#HSQL Database Engine 1.8.0.10
+#Wed Apr 13 15:03:18 CEST 2011
+hsqldb.script_format=0
+runtime.gc_interval=0
+sql.enforce_strict_size=false
+hsqldb.cache_size_scale=8
+readonly=false
+hsqldb.nio_data_file=true
+hsqldb.cache_scale=14
+version=1.8.0
+hsqldb.default_table_type=memory
+hsqldb.cache_file_scale=1
+hsqldb.log_size=200
+modified=yes
+hsqldb.cache_version=1.7.0
+hsqldb.original_version=1.8.0
+hsqldb.compatible_version=1.8.0
4 database/server.properties
@@ -0,0 +1,4 @@
+server.database.0=file:db/reportdb
+server.dbname.0=reportdb
+server.database.1=file:db/idempotentdb
+server.dbname.1=idempotentdb
1 jdbc/data/keys.txt
@@ -0,0 +1 @@
+001,003
61 jdbc/pom.xml
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>com.fusesource.examples</groupId>
+ <artifactId>camel-persistence-part1</artifactId>
+ <version>1.0</version>
+ </parent>
+
+ <groupId>com.fusesource.examples.camel-persistence-part1</groupId>
+ <artifactId>jdbc</artifactId>
+ <name>FuseSource :: Examples :: Camel Persistence :: JDBC</name>
+
+ <dependencies>
+ <!-- Camel -->
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-jdbc</artifactId>
+ <version>${camel-version}</version>
+ </dependency>
+
+ <!-- Spring JDBC -->
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>org.springframework.jdbc</artifactId>
+ <version>${spring-version}</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-maven-plugin</artifactId>
+ <version>${camel-version}</version>
+ <configuration>
+ <applicationContextUri>META-INF/spring/camelContext.xml</applicationContextUri>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
78 jdbc/src/main/resources/META-INF/spring/camelContext.xml
@@ -0,0 +1,78 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+-->
+
+<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.xsd
+ http://camel.apache.org/schema/spring
+ http://camel.apache.org/schema/spring/camel-spring.xsd
+ ">
+
+
+ <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
+
+ <!-- Route which will execute the select query every 20s and display result in the log-->
+ <route id="trigger-database">
+ <from uri="timer://webinar?delay=20000&amp;period=20000"/>
+ <setBody>
+ <constant>SELECT * FROM REPORT.T_INCIDENT</constant>
+ </setBody>
+ <to uri="jdbc:reportdb"/>
+ <split>
+ <simple>${body}</simple>
+ <log message="*** Select all : ${body}"/>
+ </split>
+ </route>
+
+ <!-- Route which will execute the select query when a file will be poll from
+ data directory. this file contains the keys of the incidents to be find
+ and display result in the log -->
+ <route id="key-from-file">
+ <from uri="file://target/data"/>
+ <split>
+ <tokenize token=","/>
+ <setBody>
+ <simple>SELECT * FROM REPORT.T_INCIDENT WHERE INCIDENT_REF = '${body}' </simple>
+ </setBody>
+ <log message=">>> SQL Query : ${body}"/>
+ <to uri="jdbc:reportdb"/>
+ <log message=">>> Select using key : ${body}"/>
+ </split>
+ </route>
+
+ </camelContext>
+
+ <!-- HSQL DB
+ <bean id="reportdb" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
+ <property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
+ <property name="url" value="jdbc:hsqldb:hsql://localhost/reportdb"/>
+ <property name="username" value="sa"/>
+ <property name="password" value=""/>
+ </bean>
+ -->
+
+ <!-- H2 DB -->
+ <bean id="reportdb" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
+ <property name="driverClassName" value="org.h2.Driver"/>
+ <property name="url" value="jdbc:h2:tcp://localhost/~/reportdb"/>
+ <property name="username" value="sa"/>
+ <property name="password" value=""/>
+ </bean>
+
+</beans>
68 jdbc/src/main/resources/META-INF/spring/camelContext2.xml
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+-->
+
+<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.xsd
+ http://camel.apache.org/schema/spring
+ http://camel.apache.org/schema/spring/camel-spring.xsd
+ ">
+
+
+ <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
+
+ <propertyPlaceholder id="properties" location="com/fusesource/examples/persistence/part1/query.properties"/>
+
+ <!-- Route which will execute the select query every 10s and display result in the log
+ The query is defined in the file query.properties that Camel will retrieve using
+ the property place holder -->
+ <route id="trigger-database">
+ <from uri="timer://webinar?{{timerParams}}"/>
+ <setBody>
+ <simple>${properties:selectReportWithIds}</simple>
+ </setBody>
+ <!-- <log message=">> SQL query = {{selectReportWithIds}}"/> -->
+ <to uri="jdbc:reportdb"/>
+ <split>
+ <simple>${body}</simple>
+ <log message=">>> Select all but using properties to define query : ${body}"/>
+ </split>
+ </route>
+
+
+ </camelContext>
+
+ <!-- HSQL DB
+ <bean id="reportdb" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
+ <property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
+ <property name="url" value="jdbc:hsqldb:hsql://localhost/reportdb"/>
+ <property name="username" value="sa"/>
+ <property name="password" value=""/>
+ </bean>
+ -->
+
+ <!-- H2 DB -->
+ <bean id="reportdb" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
+ <property name="driverClassName" value="org.h2.Driver"/>
+ <property name="url" value="jdbc:h2:tcp://localhost/~/reportdb"/>
+ <property name="username" value="sa"/>
+ <property name="password" value=""/>
+ </bean>
+
+</beans>
2 jdbc/src/main/resources/com/fusesource/examples/persistence/part1/query.properties
@@ -0,0 +1,2 @@
+selectReportWithIds=SELECT * FROM REPORT.T_INCIDENT WHERE INCIDENT_REF = '001' OR INCIDENT_REF = '002'
+timerParams=delay=1000&period=10000
21 jdbc/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
1 jpa/data/csv-notinserted.txt
@@ -0,0 +1 @@
+099,31-12-2011,Rob,Davies,incident camel-005,this is a report incident for camel-005,hzbarcea@gmail.com,+999 10 20 300
1 jpa/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
9 jpa/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
9 jpa/data/csv2.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
118 jpa/pom.xml
@@ -0,0 +1,118 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>com.fusesource.examples</groupId>
+ <artifactId>camel-persistence-part1</artifactId>
+ <version>1.0</version>
+ </parent>
+
+ <groupId>com.fusesource.examples.camel-persistence-part1</groupId>
+ <artifactId>jpa</artifactId>
+ <name>FuseSource :: Examples :: Camel Persistence :: JPA</name>
+
+ <dependencies>
+ <!-- Camel -->
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-jpa</artifactId>
+ <version>${camel-version}</version>
+ <scope>compile</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-jpa_3.0_spec</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-bindy</artifactId>
+ <version>${camel-version}</version>
+ <scope>compile</scope>
+ </dependency>
+ <!-- Commons -->
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <version>2.6</version>
+ </dependency>
+ <!-- OpenJPA -->
+ <dependency>
+ <groupId>org.apache.openjpa</groupId>
+ <artifactId>openjpa</artifactId>
+ <version>2.1.0</version>
+ <scope>compile</scope>
+ </dependency>
+ <!-- Spring -->
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>org.springframework.orm</artifactId>
+ <version>3.0.5.RELEASE</version>
+ <scope>compile</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-maven-plugin</artifactId>
+ <version>${camel-version}</version>
+ <configuration>
+ <applicationContextUri>META-INF/spring/*.xml</applicationContextUri>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>openjpa-maven-plugin</artifactId>
+ <version>1.2</version>
+ <configuration>
+ <includes>**/model/*.class</includes>
+ <addDefaultConstructor>true</addDefaultConstructor>
+ <enforcePropertyRestrictions>true</enforcePropertyRestrictions>
+ </configuration>
+ <executions>
+ <execution>
+ <id>enhancer</id>
+ <phase>process-classes</phase>
+ <goals>
+ <goal>enhance</goal>
+ </goals>
+ </execution>
+ </executions>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.openjpa</groupId>
+ <artifactId>openjpa</artifactId>
+ <version>2.0.1</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <version>1.1.1</version>
+ </dependency>
+ </dependencies>
+ </plugin>
+ </plugins>
+ </build>
+</project>
54 jpa/src/main/java/com/fusesource/examples/persistence/part1/camel/ProcessIncidents.java
@@ -0,0 +1,54 @@
+package com.fusesource.examples.persistence.part1.camel;
+
+/**
+ * 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.part1.model.Incident;
+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 {
+
+ public static int count = 0;
+
+ public Incident extract(Exchange exchange) throws ParseException {
+
+ Map<String, Object> model = (Map<String, Object>) exchange.getIn().getBody();
+ String key = "com.fusesource.examples.persistence.part1.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 generateError() throws Exception {
+ System.out.println("+++++ We will generate an exception +++++, " + count + " redelivery !");
+ count++;
+ throw new Exception("Cannot connect to Database ....");
+ }
+}
34 jpa/src/main/java/com/fusesource/examples/persistence/part1/model/Abstract.java
@@ -0,0 +1,34 @@
+package com.fusesource.examples.persistence.part1.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);
+ }
+
+}
165 jpa/src/main/java/com/fusesource/examples/persistence/part1/model/Incident.java
@@ -0,0 +1,165 @@
+package com.fusesource.examples.persistence.part1.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 java.io.Serializable;
+import java.util.Date;
+import javax.persistence.*;
+
+@CsvRecord(separator = ",")
+@Entity
+@Table(schema = "REPORT", name = "T_INCIDENT")
+@NamedQuery(name = "reportSummaryQuery",
+ query = "SELECT rep.incidentRef, rep.familyName, rep.summary FROM Incident rep")
+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;
+ }
+}
39 jpa/src/main/resources/META-INF/persistence.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<persistence xmlns="http://java.sun.com/xml/ns/persistence"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
+ http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
+ version="2.0">
+
+ <persistence-unit name="reportincident" transaction-type="RESOURCE_LOCAL">
+ <class>com.fusesource.examples.persistence.part1.model.Incident</class>
+
+ <exclude-unlisted-classes>true</exclude-unlisted-classes>
+
+ <!-- hsql
+ <properties>
+ <property name="openjpa.jdbc.SynchronizeMappings"
+ value="buildSchema(SchemaAction='add,deleteTableContents')"/>
+ <property name="openjpa.Log"
+ value="commons" />
+ <property name="openjpa.jdbc.DBDictionary"
+ value="hsql(useSchemaName=true)"/>
+ <property name="openjpa.jdbc.Schema"
+ value="REPORT" />
+ </properties>
+ -->
+
+ <properties>
+ <property name="openjpa.jdbc.SynchronizeMappings"
+ value="buildSchema(SchemaAction='add,deleteTableContents')"/>
+ <property name="openjpa.Log"
+ value="commons"/>
+ <property name="openjpa.jdbc.DBDictionary"
+ value="h2(useSchemaName=true)"/>
+ <property name="openjpa.jdbc.Schema"
+ value="REPORT"/>
+ </properties>
+
+ </persistence-unit>
+</persistence>
+
92 jpa/src/main/resources/META-INF/spring/camelContext.xml
@@ -0,0 +1,92 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+-->
+
+<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.xsd
+ http://camel.apache.org/schema/spring
+ http://camel.apache.org/schema/spring/camel-spring.xsd
+ ">
+
+ <bean id="jpa" class="org.apache.camel.component.jpa.JpaComponent"/>
+ <bean id="processIncident" class="com.fusesource.examples.persistence.part1.camel.ProcessIncidents"/>
+
+ <bean id="txErrorHandler" class="org.apache.camel.spring.spi.TransactionErrorHandlerBuilder">
+ <property name="redeliveryPolicy" ref="redeliveryPolicy"/>
+ </bean>
+
+ <bean id="redeliveryPolicy" class="org.apache.camel.processor.RedeliveryPolicy">
+ <property name="maximumRedeliveries" value="2"/>
+ </bean>
+
+ <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
+
+ <dataFormats>
+ <bindy type="Csv" packages="com.fusesource.examples.persistence.part1.model" id="csvReport"/>
+ </dataFormats>
+
+ <!-- Route which will poll the DB and so perform select query -->
+ <route id="trigger-database">
+ <from uri="jpa://com.fusesource.examples.persistence.part1.model.Incident?consumeDelete=false&amp;consumer.delay=10000"/>
+ <log message=">>> Result : ${body}"/>
+ </route>
+
+ <!-- Route which will poll the DB and so perform select query using here a namedQuery -->
+ <route id="trigger-database-named-query">
+ <from uri="jpa://com.fusesource.examples.persistence.part1.model.Incident?consumeDelete=false&amp;consumer.delay=20000&amp;consumer.initialDelay=10000&amp;consumer.namedQuery=reportSummaryQuery"/>
+ <!-- JPA does not return an Incident but an Object[] -->
+ <split>
+ <simple>${body}</simple>
+ <log message=">>> Result with named query : ${body}"/>
+ </split>
+ </route>
+
+ <!-- Route which will insert a record in the DB. Info about the
+ incident to be created is defined in a CSV file, extract and
+ map to an Incident class using camel-bindy -->
+ <route id="create-incident">
+ <from uri="file://target/datainsert?moveFailed=failed"/>
+ <unmarshal ref="csvReport"/>
+ <split>
+ <simple>${body}</simple>
+ <bean ref="processIncident" method="extract"/>
+ <to uri="jpa://Incident"/>
+ <log message=">>> Record inserted : ${body}"/>
+ </split>
+ </route>
+
+ <!-- This route generates an error to rollback the record from the DB. The file
+ is not deleted but moved in the failed directory and Camel redelivers 2 times the
+ exchange by calling the last processor where the error occurs -->
+ <route id="rollback-incident" errorHandlerRef="txErrorHandler">
+ <from uri="file://target/datainsertrollback?moveFailed=failed"/>
+ <transacted/>
+ <unmarshal ref="csvReport"/>
+ <split>
+ <simple>${body}</simple>
+ <bean ref="processIncident"/>
+ <to uri="jpa://Incident"/>
+ <bean ref="processIncident" method="generateError"/>
+ <log message=">>> Record not inserted : ${body}"/>
+ </split>
+ </route>
+
+ </camelContext>
+
+</beans>
56 jpa/src/main/resources/META-INF/spring/springJPA.xml
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+-->
+<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.xsd">
+
+ <bean class="org.springframework.orm.jpa.JpaTransactionManager">
+ <property name="entityManagerFactory" ref="entityManagerFactory" />
+ </bean>
+
+ <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
+ <property name="persistenceUnitName" value="reportincident"/>
+ <property name="dataSource" ref="reportdb"/>
+ <property name="jpaVendorAdapter">
+ <bean id="jpaAdapter" class="org.springframework.orm.jpa.vendor.OpenJpaVendorAdapter">
+ <property name="databasePlatform" value="org.apache.openjpa.jdbc.sql.H2Dictionary"/>
+ <property name="showSql" value="true"/>
+ <property name="database" value="H2"/>
+ </bean>
+ </property>
+ </bean>
+
+ <!-- HSQL DB
+ <bean id="reportdb" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
+ <property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
+ <property name="url" value="jdbc:hsqldb:hsql://localhost/reportdb"/>
+ <property name="username" value="sa"/>
+ <property name="password" value=""/>
+ </bean>
+ -->
+
+ <!-- H2 DB -->
+ <bean id="reportdb" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
+ <property name="driverClassName" value="org.h2.Driver"/>
+ <property name="url" value="jdbc:h2:tcp://localhost/~/reportdb"/>
+ <property name="username" value="sa"/>
+ <property name="password" value=""/>
+ </bean>
+
+
+</beans>
21 jpa/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
125 pom.xml
@@ -0,0 +1,125 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+~ 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>com.fusesource.examples</groupId>
+ <artifactId>camel-persistence-part1</artifactId>
+ <version>1.0</version>
+ <name>FuseSource :: Examples :: Camel Persistence</name>
+ <packaging>pom</packaging>
+
+ <properties>
+ <camel-version>2.8.0-fuse-00-08</camel-version>
+ <hsqldb-version>1.8.0.10</hsqldb-version>
+ <h2-version>1.3.160</h2-version>
+ <spring-version>3.0.5.RELEASE</spring-version>
+ <slf4j-version>1.6.1</slf4j-version>
+ <log4j-version>1.2.12</log4j-version>
+ </properties>
+
+ <modules>
+ <module>jdbc</module>
+ <module>jpa</module>
+ <module>sql-spring</module>
+ <!-- <module>sql-spring-persistence</module> -->
+ </modules>
+
+ <dependencies>
+ <!-- Camel -->
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core</artifactId>
+ <version>${camel-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-spring</artifactId>
+ <version>${camel-version}</version>
+ </dependency>
+
+ <!-- HSQL DB -->
+ <dependency>
+ <groupId>hsqldb</groupId>
+ <artifactId>hsqldb</artifactId>
+ <version>${hsqldb-version}</version>
+ </dependency>
+
+ <!-- H2 Database -->
+ <dependency>
+ <groupId>com.h2database</groupId>
+ <artifactId>h2</artifactId>
+ <version>${h2-version}</version>
+ </dependency>
+
+ <!-- Logging -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>${slf4j-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>${log4j-version}</version>
+ </dependency>
+
+ </dependencies>
+
+
+ <!-- Add FUSE repositories for snaphots and releases -->
+ <pluginRepositories>
+ <pluginRepository>
+ <id>fusesource.com</id>
+ <name>FuseSource Maven Repository</name>
+ <url>http://repo.fusesource.com/maven2/</url>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ <releases>
+ <enabled>true</enabled>
+ </releases>
+ </pluginRepository>
+ </pluginRepositories>
+ <repositories>
+ <repository>
+ <id>fusesource.com</id>
+ <name>FuseSource Maven Repository</name>
+ <url>http://repo.fusesource.com/maven2/</url>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ <releases>
+ <enabled>true</enabled>
+ </releases>
+ </repository>
+ <repository>
+ <id>Maven-repo</id>
+ <url>http://repo1.maven.org/maven2/</url>
+ </repository>
+ <repository>
+ <id>Spring-external-repo</id>
+ <url>http://repository.springsource.com/maven/bundles/external</url>
+ </repository>
+ <repository>
+ <id>Spring-release-repo</id>
+ <url>http://repository.springsource.com/maven/bundles/release</url>
+ </repository>
+ </repositories>
+</project>
1 sql-spring/data/key.txt
@@ -0,0 +1 @@
+888
1 sql-spring/data/keyParams.txt
@@ -0,0 +1 @@
+999,This is a report incident for webinar-999
54 sql-spring/pom.xml
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>com.fusesource.examples</groupId>
+ <artifactId>camel-persistence-part1</artifactId>
+ <version>1.0</version>
+ </parent>
+
+ <groupId>com.fusesource.examples.camel-persistence-part1</groupId>
+ <artifactId>sql-spring</artifactId>
+ <name>FuseSource :: Examples :: Camel Persistence :: SQL - Spring</name>
+
+ <dependencies>
+ <!-- Camel SQL -->
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-sql</artifactId>
+ <version>${camel-version}</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-maven-plugin</artifactId>
+ <version>${camel-version}</version>
+ <configuration>
+ <applicationContextUri>META-INF/spring/*.xml</applicationContextUri>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
60 ...ring/src/main/java/com/fusesource/examples/persistence/part1/SqlSpringReportIncident.java
@@ -0,0 +1,60 @@
+/**
+ * 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.
+ */
+package com.fusesource.examples.persistence.part1;
+
+import org.apache.camel.Body;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Exchange;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.sql.SqlEndpoint;
+
+public class SqlSpringReportIncident {
+
+ private ProducerTemplate template;
+
+ @EndpointInject(ref="sqlEndpoint")
+ protected SqlEndpoint endpoint;
+
+ public void insertRecord(@Body String ref) {
+
+ StringBuilder queryBuilder = new StringBuilder();
+
+ queryBuilder.append(
+ "INSERT INTO REPORT.T_INCIDENT (INCIDENT_REF,INCIDENT_DATE," +
+ "GIVEN_NAME,FAMILY_NAME,SUMMARY,DETAILS,EMAIL,PHONE) VALUES (");
+ queryBuilder.append("'" + ref + "',");
+ queryBuilder.append("'2011-03-22','Charles','Moulliard','Incident Webinar'," +
+ "'This is a report incident for webinar-" + ref + "'," +
+ "'cmoulliard@fusesource.com','+111 10 20 300')");
+
+ String query = queryBuilder.toString();
+ System.out.println(">>> Query created : " + query );
+
+ endpoint.setQuery(query);
+ template.send(endpoint,(Exchange) null) ;
+
+
+ }
+
+ public void setTemplate(ProducerTemplate template) {
+ this.template = template;
+ }
+
+ public Object[] convertStringIntoArray(@Body String params) {
+ return params.split(",");
+ }
+
+}
96 sql-spring/src/main/resources/META-INF/spring/camelContext.xml
@@ -0,0 +1,96 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+-->
+
+<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.xsd
+ http://camel.apache.org/schema/spring
+ http://camel.apache.org/schema/spring/camel-spring.xsd
+ ">
+
+ <bean id="jdbcReportIncident" class="com.fusesource.examples.persistence.part1.SqlSpringReportIncident">
+ <property name="template" ref="template"/>
+ </bean>
+
+
+ <bean id="sql" class="org.apache.camel.component.sql.SqlComponent">
+ <property name="dataSource" ref="reportdb"/>
+ </bean>
+
+ <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
+
+ <template id="template"/>
+ <endpoint id="sqlEndpoint" uri="sql:xxx"/>
+
+ <!-- Route which will insert a record in the DB when a file will be poll from
+ datainsertparams directory. This file contains the params to be replaced
+ in the query with # symbol. -->
+ <route id="insert-from-file-using-split">
+ <from uri="file://target/datainsertparams?moveFailed=failed"/>
+ <convertBodyTo type="String"/>
+ <bean ref="jdbcReportIncident" method="convertStringIntoArray"/>
+ <to uri ="sql:INSERT INTO REPORT.T_INCIDENT
+ (INCIDENT_REF,INCIDENT_DATE,GIVEN_NAME,FAMILY_NAME,SUMMARY,DETAILS,EMAIL,PHONE)
+ VALUES
+ (#,'2011-03-22','Charles','Moulliard','Incident Webinar',#,'cmoulliard@fusesource.com','+111 10 20 300')"/>
+ <log message=">>> Result using params : ${body}"/>
+ </route>
+
+ <!-- Route which will insert a record in the DB when a file will be poll from
+ datainsert directory. This file contains the reference of the incident
+ to be created. The query is created within the method insertRecord and
+ endpoint sql:xxx is overrided -->
+ <route id="insert-from-file-using-bean">
+ <from uri="file://target/datainsert?moveFailed=failed"/>
+ <convertBodyTo type="String"/>
+ <bean ref="jdbcReportIncident" method="insertRecord"/>
+ <log message=">>> Result : ${body}"/>
+ </route>
+
+ <!-- Route which will execute the select query every 20s and display result in the log -->
+ <route id="trigger-database">
+ <from uri="timer://webinar?delay=20000&amp;period=20000"/>
+ <to uri="sql:SELECT * FROM REPORT.T_INCIDENT"/>
+ <split>
+ <simple>${body}</simple>
+ <log message=">>> Select all : ${body}"/>
+ </split>
+ </route>
+
+
+ </camelContext>
+
+ <!-- HSQL DB
+ <bean id="reportdb" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
+ <property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
+ <property name="url" value="jdbc:hsqldb:hsql://localhost/reportdb"/>
+ <property name="username" value="sa"/>
+ <property name="password" value=""/>
+ </bean>
+ -->
+
+ <!-- H2 DB -->
+ <bean id="reportdb" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
+ <property name="driverClassName" value="org.h2.Driver"/>
+ <property name="url" value="jdbc:h2:tcp://localhost/~/reportdb"/>
+ <property name="username" value="sa"/>
+ <property name="password" value=""/>
+ </bean>
+
+</beans>
21 sql-spring/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

0 comments on commit 1d88fdd

Please sign in to comment.