Skip to content

Commit 42a497e

Browse files
committed
Refresh sql-spring and create sql-blueprint examples
1 parent 4eba124 commit 42a497e

File tree

14 files changed

+414
-92
lines changed

14 files changed

+414
-92
lines changed

README.md

+48-15
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ It covers the different demos made during the talk and is organised like that:
66
* `database`: directory containing the scripts to create the database for H2, HSQLDB and PostgreSQL RDBMSes
77
* `jdbc-spring`: Maven project using camel-jdbc component and Spring XML DSL
88
* `jdbc-blueprint`: Maven project using camel-jdbc component and Blueprint XML DSL
9+
* `sql-spring`: Maven project using camel-sql component and Spring XML DSL
10+
* `sql-blueprint`: Maven project using camel-sql component and Blueprint XML DSL
911

1012
# Initial setup
1113

@@ -37,25 +39,25 @@ You can use any of available methods to access PostgreSQL server (e.g., by mappi
3739

3840
3. Initialize database `reportdb` by creating schema, table and populating the table with data.
3941

40-
$ cd $PROJECT_HOME/database
41-
$ docker cp src/config/postgresql/reportdb-postgresql-script.sql fuse-postgresql-server:/tmp
42-
$ docker exec -ti fuse-postgresql-server /bin/bash
43-
$ root@58b0d9de9c5b:/# psql -U fuse -d reportdb -f /tmp/reportdb-postgresql-script.sql
44-
...
45-
DROP SCHEMA
46-
CREATE SCHEMA
47-
CREATE TABLE
48-
INSERT 0 1
49-
INSERT 0 1
50-
INSERT 0 1
51-
INSERT 0 1
42+
$ cd $PROJECT_HOME/database
43+
$ docker cp src/config/postgresql/reportdb-postgresql-script.sql fuse-postgresql-server:/tmp
44+
$ docker exec -ti fuse-postgresql-server /bin/bash
45+
$ root@58b0d9de9c5b:/# psql -U fuse -d reportdb -f /tmp/reportdb-postgresql-script.sql
46+
...
47+
DROP SCHEMA
48+
CREATE SCHEMA
49+
CREATE TABLE
50+
INSERT 0 1
51+
INSERT 0 1
52+
INSERT 0 1
53+
INSERT 0 1
5254

5355
# Running examples
5456

5557
## `jdbc-spring` and `jdbc-blueprint`
5658

5759
These examples can be run using camel-test-spring and camel-test-blueprint respectively. Examples will run outside
58-
of Fuse server and require only running database server.
60+
of JBoss Fuse server and require only running database server.
5961

6062
For `jdbc-spring` example, run:
6163

@@ -79,9 +81,40 @@ We can also run 2nd Camel context using:
7981
For `jdbc-blueprint` we use Blueprint XML DSL and because of more _discovery_ nature of `camel-test-blueprint`, we
8082
use only `camelContext1.xml` example. We can run this example using:
8183

82-
$ cd $PROJECT_HOME/jdbc-spring
84+
$ cd $PROJECT_HOME/jdbc-blueprint
8385
$ mvn clean package camel:run
8486

8587
The invocation is slightly different - `package` goal has to be invoked, so we have proper OSGi bundle - or rather
8688
proper OSGi bundle `MANIFEST.MF` file generated in `target/classes/META-INF` directory. This allows `camel-test-blueprint`
87-
to _pick up_ `target/classes` directory as correct OSGi bundle.
89+
to _pick up_ `target/classes` directory as correct OSGi bundle.
90+
91+
## `sql-spring` and `sql-blueprint`
92+
93+
These examples also can be run outside JBoss Fuse server using camel-test-spring and camel-test-blueprint respectively.
94+
This time we can also create new records in database by sending content of files through Camel route to the database
95+
using `camel-spring` component.
96+
97+
For `sql-spring` example, run:
98+
99+
$ cd $PROJECT_HOME/sql-spring
100+
$ mvn clean compile camel:run
101+
102+
This will start the route and print the content of `t_incident` table every 20 seconds. We can create new incidents
103+
in two ways:
104+
105+
1. by invoking `insert-from-file-using-bean` route that prepares new record in bean method:
106+
107+
$ cd $PROJECT_HOME/sql-spring
108+
$ cp data/key.txt target/datainsert
109+
110+
2. by invoking `insert-from-file-using-split` route that prepares new record simply by splitting comma-separated values
111+
from given file
112+
113+
$ cd $PROJECT_HOME/sql-spring
114+
$ cp data/keyParams.txt target/datainsertparams
115+
116+
For `sql-blueprint` the examples are run almost like the ones in `sql-spring`, except that `package` phase has
117+
to be invoked.
118+
119+
$ cd $PROJECT_HOME/sql-blueprint
120+
$ mvn clean package camel:run

jdbc-blueprint/pom.xml

+7-7
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@
5151
<artifactId>camel-jdbc</artifactId>
5252
</dependency>
5353

54+
<!-- Spring -->
55+
56+
<dependency>
57+
<groupId>org.springframework</groupId>
58+
<artifactId>spring-jdbc</artifactId>
59+
</dependency>
60+
5461
<!-- OSGi -->
5562

5663
<dependency>
@@ -62,13 +69,6 @@
6269
<artifactId>osgi.core</artifactId>
6370
</dependency>
6471

65-
<!-- Spring -->
66-
67-
<dependency>
68-
<groupId>org.springframework</groupId>
69-
<artifactId>spring-jdbc</artifactId>
70-
</dependency>
71-
7272
<!-- Database drivers -->
7373

7474
<dependency>

jdbc-spring/pom.xml

-6
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,6 @@
5858
<groupId>org.postgresql</groupId>
5959
<artifactId>postgresql</artifactId>
6060
</dependency>
61-
<dependency>
62-
<groupId>org.apache.camel</groupId>
63-
<artifactId>camel-maven-plugin</artifactId>
64-
<version>${version.org.apache.camel}</version>
65-
<scope>provided</scope>
66-
</dependency>
6761

6862
</dependencies>
6963

pom.xml

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
<properties>
3131
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
32+
3233
<fuse.build>284</fuse.build>
3334

3435
<version.org.apache.camel>2.17.0.redhat-630${fuse.build}</version.org.apache.camel>
@@ -53,8 +54,9 @@
5354
<modules>
5455
<module>jdbc-spring</module>
5556
<module>jdbc-blueprint</module>
57+
<module>sql-spring</module>
58+
<module>sql-blueprint</module>
5659
<!--<module>jpa</module>-->
57-
<!--<module>sql-spring</module>-->
5860
</modules>
5961

6062
<dependencyManagement>

sql-blueprint/data/key.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
888

sql-blueprint/data/keyParams.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
999,This is a report incident for webinar-999

sql-blueprint/pom.xml

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Copyright 2005-2017 Red Hat, Inc.
5+
6+
Red Hat licenses this file to you under the Apache License, version
7+
2.0 (the "License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15+
implied. See the License for the specific language governing
16+
permissions and limitations under the License.
17+
18+
-->
19+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
21+
22+
<modelVersion>4.0.0</modelVersion>
23+
24+
<parent>
25+
<groupId>com.fusesource.examples</groupId>
26+
<artifactId>camel-persistence-part1</artifactId>
27+
<version>1.0</version>
28+
<relativePath>../pom.xml</relativePath>
29+
</parent>
30+
31+
<groupId>com.fusesource.examples.camel-persistence-part1</groupId>
32+
<artifactId>sql-blueprint</artifactId>
33+
<packaging>bundle</packaging>
34+
<name>FuseSource :: Examples :: Camel Persistence :: SQL Blueprint</name>
35+
36+
<dependencies>
37+
38+
<!-- Camel -->
39+
40+
<dependency>
41+
<groupId>org.apache.camel</groupId>
42+
<artifactId>camel-blueprint</artifactId>
43+
</dependency>
44+
<dependency>
45+
<groupId>org.apache.camel</groupId>
46+
<artifactId>camel-test-blueprint</artifactId>
47+
<scope>test</scope>
48+
</dependency>
49+
<dependency>
50+
<groupId>org.apache.camel</groupId>
51+
<artifactId>camel-sql</artifactId>
52+
</dependency>
53+
54+
<!-- OSGi -->
55+
56+
<dependency>
57+
<groupId>org.osgi</groupId>
58+
<artifactId>osgi.enterprise</artifactId>
59+
</dependency>
60+
<dependency>
61+
<groupId>org.osgi</groupId>
62+
<artifactId>osgi.core</artifactId>
63+
</dependency>
64+
65+
<!-- Database drivers -->
66+
67+
<dependency>
68+
<groupId>org.postgresql</groupId>
69+
<artifactId>postgresql</artifactId>
70+
</dependency>
71+
72+
</dependencies>
73+
74+
<build>
75+
<plugins>
76+
<plugin>
77+
<groupId>org.apache.felix</groupId>
78+
<artifactId>maven-bundle-plugin</artifactId>
79+
<extensions>true</extensions>
80+
<configuration>
81+
<instructions>
82+
<Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
83+
</instructions>
84+
</configuration>
85+
</plugin>
86+
<plugin>
87+
<groupId>org.apache.camel</groupId>
88+
<artifactId>camel-maven-plugin</artifactId>
89+
<configuration>
90+
<useBlueprint>true</useBlueprint>
91+
</configuration>
92+
</plugin>
93+
</plugins>
94+
</build>
95+
96+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* Copyright 2005-2017 Red Hat, Inc.
3+
*
4+
* Red Hat licenses this file to you under the Apache License, version
5+
* 2.0 (the "License"); you may not use this file except in compliance
6+
* with the License. You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13+
* implied. See the License for the specific language governing
14+
* permissions and limitations under the License.
15+
*/
16+
package com.fusesource.examples.persistence.part1;
17+
18+
import org.apache.camel.Body;
19+
import org.apache.camel.EndpointInject;
20+
import org.apache.camel.Exchange;
21+
import org.apache.camel.ProducerTemplate;
22+
import org.apache.camel.component.sql.SqlEndpoint;
23+
24+
public class SqlSpringReportIncident {
25+
26+
private ProducerTemplate template;
27+
28+
@EndpointInject(ref="sqlEndpoint")
29+
protected SqlEndpoint endpoint;
30+
31+
public void insertRecord(@Body String ref) {
32+
33+
StringBuilder queryBuilder = new StringBuilder();
34+
35+
queryBuilder.append(
36+
"INSERT INTO REPORT.T_INCIDENT (INCIDENT_REF,INCIDENT_DATE," +
37+
"GIVEN_NAME,FAMILY_NAME,SUMMARY,DETAILS,EMAIL,PHONE) VALUES (");
38+
queryBuilder.append("'" + ref + "',");
39+
queryBuilder.append("'2017-03-22','Charles','Moulliard','Incident Webinar'," +
40+
"'This is a report incident for webinar-" + ref + "'," +
41+
"'[email protected]','+111 10 20 300')");
42+
43+
String query = queryBuilder.toString();
44+
System.out.println(">>> Query created : " + query );
45+
46+
endpoint.setQuery(query);
47+
template.send(endpoint,(Exchange) null) ;
48+
49+
50+
}
51+
52+
public void setTemplate(ProducerTemplate template) {
53+
this.template = template;
54+
}
55+
56+
public Object[] convertStringIntoArray(@Body String params) {
57+
return params.split(",");
58+
}
59+
60+
}

0 commit comments

Comments
 (0)