From 509a58a9e57b0b88d97c807c75872838ca58e5ed Mon Sep 17 00:00:00 2001 From: Wim Verreydt Date: Tue, 9 Apr 2013 10:40:36 +0200 Subject: [PATCH] SM-2189: Add camel-sql example and update maven bundle plugin version --- .../src/main/filtered-resources/features.xml | 22 ++ examples/camel/camel-sql/README.txt | 274 ++++++++++++++++++ .../camel-sql-datasource-derby/pom.xml | 59 ++++ .../examples/camel/sql/DatabaseBeanDerby.java | 51 ++++ .../OSGI-INF/blueprint/blueprint.xml | 54 ++++ .../camel-sql/camel-sql-datasource-h2/pom.xml | 59 ++++ .../examples/camel/sql/DatabaseBeanH2.java | 51 ++++ .../OSGI-INF/blueprint/blueprint.xml | 56 ++++ .../camel-sql-datasource-pgsql/pom.xml | 66 +++++ .../examples/camel/sql/DatabaseBeanPgSQL.java | 49 ++++ .../OSGI-INF/blueprint/blueprint.xml | 55 ++++ .../camel/camel-sql/camel-sql-orders/pom.xml | 59 ++++ .../examples/camel/sql/ListenerBean.java | 34 +++ .../examples/camel/sql/OrderBean.java | 66 +++++ .../OSGI-INF/blueprint/blueprint.xml | 60 ++++ .../src/main/resources/sql.properties | 29 ++ examples/camel/camel-sql/pom.xml | 39 +++ examples/camel/pom.xml | 1 + pom.xml | 6 +- 19 files changed, 1089 insertions(+), 1 deletion(-) create mode 100644 examples/camel/camel-sql/README.txt create mode 100644 examples/camel/camel-sql/camel-sql-datasource-derby/pom.xml create mode 100644 examples/camel/camel-sql/camel-sql-datasource-derby/src/main/java/org/apache/servicemix/examples/camel/sql/DatabaseBeanDerby.java create mode 100644 examples/camel/camel-sql/camel-sql-datasource-derby/src/main/resources/OSGI-INF/blueprint/blueprint.xml create mode 100644 examples/camel/camel-sql/camel-sql-datasource-h2/pom.xml create mode 100644 examples/camel/camel-sql/camel-sql-datasource-h2/src/main/java/org/apache/servicemix/examples/camel/sql/DatabaseBeanH2.java create mode 100644 examples/camel/camel-sql/camel-sql-datasource-h2/src/main/resources/OSGI-INF/blueprint/blueprint.xml create mode 100644 examples/camel/camel-sql/camel-sql-datasource-pgsql/pom.xml create mode 100644 examples/camel/camel-sql/camel-sql-datasource-pgsql/src/main/java/org/apache/servicemix/examples/camel/sql/DatabaseBeanPgSQL.java create mode 100644 examples/camel/camel-sql/camel-sql-datasource-pgsql/src/main/resources/OSGI-INF/blueprint/blueprint.xml create mode 100644 examples/camel/camel-sql/camel-sql-orders/pom.xml create mode 100644 examples/camel/camel-sql/camel-sql-orders/src/main/java/org/apache/servicemix/examples/camel/sql/ListenerBean.java create mode 100644 examples/camel/camel-sql/camel-sql-orders/src/main/java/org/apache/servicemix/examples/camel/sql/OrderBean.java create mode 100644 examples/camel/camel-sql/camel-sql-orders/src/main/resources/OSGI-INF/blueprint/blueprint.xml create mode 100644 examples/camel/camel-sql/camel-sql-orders/src/main/resources/sql.properties create mode 100644 examples/camel/camel-sql/pom.xml diff --git a/assemblies/apache-servicemix/src/main/filtered-resources/features.xml b/assemblies/apache-servicemix/src/main/filtered-resources/features.xml index f02f5fd..428ee24 100644 --- a/assemblies/apache-servicemix/src/main/filtered-resources/features.xml +++ b/assemblies/apache-servicemix/src/main/filtered-resources/features.xml @@ -72,6 +72,28 @@ mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.commons-httpclient/${commons-httpclient.bundle.version} mvn:org.apache.servicemix.examples/cxf-jaxws-blueprint/${version} + + camel-sql + mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.commons-dbcp/${commons-dbcp.bundle.version} + mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.derby/${derby.bundle.version} + mvn:org.apache.servicemix.examples/camel-sql-datasource-derby/${version} + mvn:org.apache.servicemix.examples/camel-sql-orders/${version} + + + camel-sql + mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.commons-dbcp/${commons-dbcp.bundle.version} + wrap:mvn:postgresql/postgresql/${postgresql.version}.jdbc4 + mvn:org.apache.servicemix.examples/camel-sql-datasource-pgsql/${version} + mvn:org.apache.servicemix.examples/camel-sql-orders/${version} + + + camel-sql + mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.commons-dbcp/${commons-dbcp.bundle.version} + mvn:org.osgi/org.osgi.compendium/${osgi.version} + mvn:com.h2database/h2/${h2.version} + mvn:org.apache.servicemix.examples/camel-sql-datasource-h2/${version} + mvn:org.apache.servicemix.examples/camel-sql-orders/${version} + camel mvn:org.apache.servicemix.examples/camel-osgi/${version} diff --git a/examples/camel/camel-sql/README.txt b/examples/camel/camel-sql/README.txt new file mode 100644 index 0000000..9055055 --- /dev/null +++ b/examples/camel/camel-sql/README.txt @@ -0,0 +1,274 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +CAMEL SQL EXAMPLE +================= + +Purpose +------- +Deploys a Camel EIP route that uses a database to store messages after +receiving. A second route illustrates how to read messages from the database +in order to process them. + + +Explanation +----------- +The example exists of several modules: + +- camel-sql-Orders + + The Orders module has two Camel routes defined in a Blueprint XML + file. Both routes use the camel-sql feature and some predefined queries + which are located in the sql.properties file. The datasource is referenced + from the service we exposed in the first module. + + The first route periodically creates a random order using the OrderBean + and submits it to the database. The route also logs every oder to the + Servicemix log. It displays the item-name from the order, for example: + + | Inserted new order of Gummi bears + + The second route consumes the unconsumed orders from the database + and processes them using the OrderBean. The result is logged to the + Servicemix log. For example: + + | {ID=10, ITEM=Gummi bears, AMOUNT=46, CONSUMED=false, + description=The red ones are the cutest [PROCESSED], processed=true} + +- camel-sql-datasource-derby + + This module creates an in-memory Derby database utilizing a + DatabaseBeanDerby bean. The Database bean takes care of the table + creation and the graceful shutdown of the database connection. + + The datasource is exposed as a OSGI service so it can be referenced + in other OSGI bundles. + + - camel-sql-datasource-pgsql + + This module creates an Postgre SQL table utilizing a + DatabaseBeanPgSQL bean. The Database bean takes care of the table + creation and the graceful shutdown of the database connection. + + The datasource is exposed as a OSGI service so it can be referenced + in other OSGI bundles. + + - camel-sql-datasource-h2 + + This module creates an in-memory h2 database utilizing a + DatabaseBeanH2 bean. The Database bean takes care of the table + creation and the graceful shutdown of the database connection. + + The datasource is exposed as a OSGI service so it can be referenced + in other OSGI bundles. + + +All modules are deployed in an OSGi bundle. + + +Prerequisites for Running the Example +------------------------------------- +1. You must have the following installed on your machine: + + - JDK 1.6 or higher + + - Maven 2.2.1 or higher (for building) + + For more information, see the README in the top-level examples + directory. + +2. This example requires some additional configuration to allow + the JVM to use more PermGen memory: + + export JAVA_MAX_PERM_MEM=128m (on UNIX) + set JAVA_MAX_PERM_MEM=128m (on Windows) + +3. Start ServiceMix by running the following command: + + /bin/servicemix (on UNIX) + \bin\servicemix (on Windows) + + +Preparing the databases +----------------------- + +According to the example you would like to run, you have to +prepare the Derby, H2 or PgSQL database. + +- Derby + You can find a downloadable bin-distribution of Derby for + your OS on http://db.apache.org/derby/derby_downloads.html + + Extract the downloaded package and run the network server + + /bin/startNetworkServer (on UNIX) + \bin\startNetworkServer.bat (on Windows) + +- H2 + You can find a downloadable distribution of H2 for + your OS on http://www.h2database.com/html/download.html + + To install the H2 database server, run the installer or + extract the package. Now start the database server: + + /bin/h2.sh (on UNIX) + \bin\h2.bat (on Windows) + +- PgSQL + You can find a downloadable distribution of pgSQL for + your OS on http://www.postgresql.org/download/ + + Follow the installation and execution instructions for + your OS on the download website. + + To prepare the database server you can use the command line tool + psql or the GUI tool PgAdmin (http://pgadmin.org/). + + - Create a new database orderdb + + - Execute the following SQL code: + + CREATE ROLE camelsql LOGIN + ENCRYPTED PASSWORD 'md5fcac28063087cf28e72241706e98c001' + NOSUPERUSER INHERIT NOCREATEDB NOCREATEROLE NOREPLICATION; + + ALTER DATABASE orderdb OWNER TO camelsql; + + +Running the Example +------------------- +You can run the example in two ways: + +- A. Using a Prebuilt Deployment Bundle: Quick and Easy + This option is useful if you want to see the example up and + running quickly. + +- B. Building the Example Bundle Yourself + This option is useful if you want to change the example in any way. + It tells you how to build and deploy the example. This option might + be slower than option A because, if you do not already have the + required bundles in your local Maven repository, Maven will have to + download the bundles it needs. + + +A. Using a Prebuilt Deployment Bundle: Quick and Easy +----------------------------------------------------- +To install and run a prebuilt version of this example, enter the +following command in the ServiceMix console: + + features:install examples-camel-sql-derby +or + features:install examples-camel-sql-h2 +or + features:install examples-camel-sql-pgsql + +This command makes use of the ServiceMix features facility. For more +information about the features facility, see the README.txt file in the +examples parent directory. + +Once the example is running, periodic events are routed to the +generateOrder-route which crates routes en sends them to the database. +The processOrder-route picks those orders from the database and +processes them. You should see a similar log output: + + | Inserted a new order of Cookies + | {ID=8, ITEM=Cookies, AMOUNT=35, CONSUMED=false, + description=Grandma's recipe and fresh from the bakery! [PROCESSED], processed=true} + + +B. Building the Example Bundle Yourself +--------------------------------------- +To install and run the example where you build the example bundle +yourself, complete the following steps: + +1. If you have already run the example using the prebuilt version as + described above, you must first uninstall the examples feature + by entering the following command in the ServiceMix console: + + features:uninstall examples-camel-sql-derby + or + features:uninstall examples-camel-sql-h2 + or + features:uninstall examples-camel-sql-pgsql + +2. Build the example by opening a command prompt, changing directory to + examples/camel/camel-sql (this example) and entering the following Maven + command: + + mvn install + + If all of the required OSGi bundles are available in your local Maven + repository, the example will build very quickly. Otherwise it may + take some time for Maven to download everything it needs. + + The mvn install command builds the example deployment bundle and + copies it to your local Maven repository and to the target directory + of this example. + +3. Install the example by entering the following command in + the ServiceMix console: + + features:install examples-camel-sql-derby + or + features:install examples-camel-sql-h2 + or + features:install examples-camel-sql-pgsql + + It makes use of the ServiceMix features facility. For more information + about the features facility, see the README.txt file in the examples + parent directory. + +Once the example is running, periodic events are routed to the +generateOrder-route which crates routes en sends them to the database. +The processOrder-route picks those orders from the database and +processes them. You should see a similar log output: + + | Inserted a new order of Cookies + | {ID=8, ITEM=Cookies, AMOUNT=35, CONSUMED=false, + description=Grandma's recipe and fresh from the bakery! [PROCESSED], processed=true} + + +Stopping and Uninstalling the Example +------------------------------------- +To stop the example, enter the following command in the ServiceMix +console: + + osgi:stop + +For information on how to find the bundle_id assigned to the example, +see step 3 in the "Updating and Redeploying the Properties File +from the Console" section above. + +To uninstall the example, enter one of the following commands in +the ServiceMix console: + + features:uninstall examples-camel-sql-derby +or + features:uninstall examples-camel-sql-h2 +or + features:uninstall examples-camel-sql-pgsql +or + osgi:uninstall + + +Viewing the Log Entries +----------------------- +You can view the entries in the log file in the data/log +directory of your ServiceMix installation, or by typing +the following command in the ServiceMix console: + + log:display diff --git a/examples/camel/camel-sql/camel-sql-datasource-derby/pom.xml b/examples/camel/camel-sql/camel-sql-datasource-derby/pom.xml new file mode 100644 index 0000000..7d4cb95 --- /dev/null +++ b/examples/camel/camel-sql/camel-sql-datasource-derby/pom.xml @@ -0,0 +1,59 @@ + + + + + + + camel-sql + org.apache.servicemix.examples + 5.0.0-SNAPSHOT + + 4.0.0 + + camel-sql-datasource-derby + bundle + Apache ServiceMix :: Examples :: Camel Sql :: Datasource Derby + Camel Example using sql + + + + + org.apache.felix + maven-bundle-plugin + + + ${project.artifactId} + ${project.description} + * + org.apache.servicemix.examples.camel.sql + + + + + + + + org.slf4j + slf4j-api + ${slf4j.version} + + + + + \ No newline at end of file diff --git a/examples/camel/camel-sql/camel-sql-datasource-derby/src/main/java/org/apache/servicemix/examples/camel/sql/DatabaseBeanDerby.java b/examples/camel/camel-sql/camel-sql-datasource-derby/src/main/java/org/apache/servicemix/examples/camel/sql/DatabaseBeanDerby.java new file mode 100644 index 0000000..e486877 --- /dev/null +++ b/examples/camel/camel-sql/camel-sql-datasource-derby/src/main/java/org/apache/servicemix/examples/camel/sql/DatabaseBeanDerby.java @@ -0,0 +1,51 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.servicemix.examples.camel.sql; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import javax.sql.DataSource; +import java.sql.SQLException; +import java.sql.Statement; + +public class DatabaseBeanDerby { + + private DataSource dataSource; + private static final Logger LOGGER = LoggerFactory.getLogger(DatabaseBeanDerby.class); + + public DatabaseBeanDerby(){} + + public void setDataSource(DataSource dataSource) { + this.dataSource = dataSource; + } + + public void create() throws SQLException{ + Statement sta = dataSource.getConnection().createStatement(); + try { + sta.executeUpdate( + "CREATE TABLE orders (id INT generated by default as identity, item VARCHAR(50), amount INT, description VARCHAR(300), processed BOOLEAN, consumed BOOLEAN)"); + } catch (SQLException e) { + LOGGER.info("Table orders already exists"); + } + } + + public void destroy() throws SQLException { + dataSource.getConnection().close(); + } + + +} diff --git a/examples/camel/camel-sql/camel-sql-datasource-derby/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/examples/camel/camel-sql/camel-sql-datasource-derby/src/main/resources/OSGI-INF/blueprint/blueprint.xml new file mode 100644 index 0000000..f3193ce --- /dev/null +++ b/examples/camel/camel-sql/camel-sql-datasource-derby/src/main/resources/OSGI-INF/blueprint/blueprint.xml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/camel/camel-sql/camel-sql-datasource-h2/pom.xml b/examples/camel/camel-sql/camel-sql-datasource-h2/pom.xml new file mode 100644 index 0000000..49bbe53 --- /dev/null +++ b/examples/camel/camel-sql/camel-sql-datasource-h2/pom.xml @@ -0,0 +1,59 @@ + + + + + + + camel-sql + org.apache.servicemix.examples + 5.0.0-SNAPSHOT + + 4.0.0 + + camel-sql-datasource-h2 + bundle + Apache ServiceMix :: Examples :: Camel Sql :: Datasource H2 + Camel Example using sql + + + + + org.apache.felix + maven-bundle-plugin + + + ${project.artifactId} + ${project.description} + * + org.apache.servicemix.examples.camel.sql + + + + + + + + org.slf4j + slf4j-api + ${slf4j.version} + + + + + \ No newline at end of file diff --git a/examples/camel/camel-sql/camel-sql-datasource-h2/src/main/java/org/apache/servicemix/examples/camel/sql/DatabaseBeanH2.java b/examples/camel/camel-sql/camel-sql-datasource-h2/src/main/java/org/apache/servicemix/examples/camel/sql/DatabaseBeanH2.java new file mode 100644 index 0000000..03a46fb --- /dev/null +++ b/examples/camel/camel-sql/camel-sql-datasource-h2/src/main/java/org/apache/servicemix/examples/camel/sql/DatabaseBeanH2.java @@ -0,0 +1,51 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.servicemix.examples.camel.sql; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.sql.DataSource; +import java.sql.SQLException; +import java.sql.Statement; + +public class DatabaseBeanH2 { + + private DataSource dataSource; + private static final Logger LOGGER = LoggerFactory.getLogger(DatabaseBeanH2.class); + + public DatabaseBeanH2(){} + + public void setDataSource(DataSource dataSource) { + this.dataSource = dataSource; + } + + public void create() throws SQLException{ + Statement sta = dataSource.getConnection().createStatement(); + try { + sta.executeUpdate("CREATE TABLE orders ( id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, item VARCHAR(50), amount INT, description VARCHAR(300), processed BOOLEAN, consumed BOOLEAN);"); + } catch (SQLException e) { + LOGGER.info("Table orders already exists"); + } + } + + public void destroy() throws SQLException { + dataSource.getConnection().close(); + } + + +} diff --git a/examples/camel/camel-sql/camel-sql-datasource-h2/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/examples/camel/camel-sql/camel-sql-datasource-h2/src/main/resources/OSGI-INF/blueprint/blueprint.xml new file mode 100644 index 0000000..7a6843f --- /dev/null +++ b/examples/camel/camel-sql/camel-sql-datasource-h2/src/main/resources/OSGI-INF/blueprint/blueprint.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/camel/camel-sql/camel-sql-datasource-pgsql/pom.xml b/examples/camel/camel-sql/camel-sql-datasource-pgsql/pom.xml new file mode 100644 index 0000000..ac38dd3 --- /dev/null +++ b/examples/camel/camel-sql/camel-sql-datasource-pgsql/pom.xml @@ -0,0 +1,66 @@ + + + + + + + camel-sql + org.apache.servicemix.examples + 5.0.0-SNAPSHOT + + 4.0.0 + + camel-sql-datasource-pgsql + bundle + Apache ServiceMix :: Examples :: Camel Sql :: Datasource PgSql + Camel Example using sql + + + + + org.apache.felix + maven-bundle-plugin + + + ${project.artifactId} + ${project.description} + org.postgresql.jdbc4,* + org.apache.servicemix.examples.camel.sql + + + + + + + + org.slf4j + slf4j-api + ${slf4j.version} + + + + + + diff --git a/examples/camel/camel-sql/camel-sql-datasource-pgsql/src/main/java/org/apache/servicemix/examples/camel/sql/DatabaseBeanPgSQL.java b/examples/camel/camel-sql/camel-sql-datasource-pgsql/src/main/java/org/apache/servicemix/examples/camel/sql/DatabaseBeanPgSQL.java new file mode 100644 index 0000000..82593f3 --- /dev/null +++ b/examples/camel/camel-sql/camel-sql-datasource-pgsql/src/main/java/org/apache/servicemix/examples/camel/sql/DatabaseBeanPgSQL.java @@ -0,0 +1,49 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.servicemix.examples.camel.sql; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.sql.DataSource; +import java.sql.SQLException; +import java.sql.Statement; + +public class DatabaseBeanPgSQL { + private DataSource dataSource; + private static final Logger LOGGER = LoggerFactory.getLogger(DatabaseBeanPgSQL.class); + + public DatabaseBeanPgSQL(){} + + public void setDataSource(DataSource dataSource) { + this.dataSource = dataSource; + } + + public void create() throws SQLException { + Statement sta = dataSource.getConnection().createStatement(); + try { + sta.executeUpdate("CREATE SEQUENCE order_id_seq;"); + sta.executeUpdate("CREATE TABLE orders ( id INT NOT NULL PRIMARY KEY DEFAULT nextval('order_id_seq'), item VARCHAR(50), amount INT, description VARCHAR(300), processed BOOLEAN, consumed BOOLEAN);"); + } catch (SQLException e) { + LOGGER.info("Table orders already exists"); + } + } + + public void destroy() throws SQLException { + dataSource.getConnection().close(); + } +} diff --git a/examples/camel/camel-sql/camel-sql-datasource-pgsql/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/examples/camel/camel-sql/camel-sql-datasource-pgsql/src/main/resources/OSGI-INF/blueprint/blueprint.xml new file mode 100644 index 0000000..5356deb --- /dev/null +++ b/examples/camel/camel-sql/camel-sql-datasource-pgsql/src/main/resources/OSGI-INF/blueprint/blueprint.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/camel/camel-sql/camel-sql-orders/pom.xml b/examples/camel/camel-sql/camel-sql-orders/pom.xml new file mode 100644 index 0000000..76f1803 --- /dev/null +++ b/examples/camel/camel-sql/camel-sql-orders/pom.xml @@ -0,0 +1,59 @@ + + + + + + + camel-sql + org.apache.servicemix.examples + 5.0.0-SNAPSHOT + + 4.0.0 + + camel-sql-orders + bundle + Apache ServiceMix :: Examples :: Camel Sql :: Orders + Camel Example using sql + + + + org.slf4j + slf4j-api + ${slf4j.version} + + + + + + + org.apache.felix + maven-bundle-plugin + + + ${project.artifactId} + ${project.description} + * + org.apache.servicemix.examples.camel.sql + + + + + + + \ No newline at end of file diff --git a/examples/camel/camel-sql/camel-sql-orders/src/main/java/org/apache/servicemix/examples/camel/sql/ListenerBean.java b/examples/camel/camel-sql/camel-sql-orders/src/main/java/org/apache/servicemix/examples/camel/sql/ListenerBean.java new file mode 100644 index 0000000..c3fc7f3 --- /dev/null +++ b/examples/camel/camel-sql/camel-sql-orders/src/main/java/org/apache/servicemix/examples/camel/sql/ListenerBean.java @@ -0,0 +1,34 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.servicemix.examples.camel.sql; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import java.util.Map; + +public class ListenerBean { + private static final Logger LOGGER = LoggerFactory.getLogger(ListenerBean.class); + + public void onBind(Object service, Map properties){ + LOGGER.info("Binding to "+ properties.get("datasource.type")); + + + } + public void onUnbind(Object service, Map properties){ + LOGGER.info("Unbinding from "+ properties.get("datasource.type")); + } +} diff --git a/examples/camel/camel-sql/camel-sql-orders/src/main/java/org/apache/servicemix/examples/camel/sql/OrderBean.java b/examples/camel/camel-sql/camel-sql-orders/src/main/java/org/apache/servicemix/examples/camel/sql/OrderBean.java new file mode 100644 index 0000000..558aebe --- /dev/null +++ b/examples/camel/camel-sql/camel-sql-orders/src/main/java/org/apache/servicemix/examples/camel/sql/OrderBean.java @@ -0,0 +1,66 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.servicemix.examples.camel.sql; + +import java.util.*; + +public class OrderBean { + + private Random random; + private static int itemnumber = 0; + private List> orders; + + + public OrderBean() { + random = new Random(); + } + + + public Map generateRandomOrder(){ + return orders.get(random.nextInt(orders.size()-1)); + } + + private static int getNextItemNumber(){ + return OrderBean.itemnumber++; + } + + public void processOrder(Map order){ + order.put("description",order.get("description")+" [PROCESSED]"); + order.put("processed",true); + + } + + + public void init(){ + orders = new ArrayList>(); + orders.add(createOrder("Cookies","Grandma's recipe and fresh from the bakery!",random.nextInt(50))); + orders.add(createOrder("Lollipops","Mix of different colors and flavours",random.nextInt(10))); + orders.add(createOrder("Gummi bears","The red ones are the cutest",random.nextInt(100))); + orders.add(createOrder("Skittles","Everybody loves rainbows",random.nextInt(800))); + } + + private Map createOrder(String item, String description, int amount){ + Map order = new HashMap(); + order.put("item",item); + order.put("description",description); + order.put("amount",amount); + return order; + } + + + +} diff --git a/examples/camel/camel-sql/camel-sql-orders/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/examples/camel/camel-sql/camel-sql-orders/src/main/resources/OSGI-INF/blueprint/blueprint.xml new file mode 100644 index 0000000..8e1474f --- /dev/null +++ b/examples/camel/camel-sql/camel-sql-orders/src/main/resources/OSGI-INF/blueprint/blueprint.xml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/camel/camel-sql/camel-sql-orders/src/main/resources/sql.properties b/examples/camel/camel-sql/camel-sql-orders/src/main/resources/sql.properties new file mode 100644 index 0000000..43fa0aa --- /dev/null +++ b/examples/camel/camel-sql/camel-sql-orders/src/main/resources/sql.properties @@ -0,0 +1,29 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# +# See the License for the specific language governing permissions and +# limitations under the License. +# +# + +## notice we use named parameters in the queries, eg :#name. A named query parameter must start with :# +## sql that insert new orders +sql.insertOrder=insert into orders (item, amount, description, processed, consumed) values (:#item, :#amount, :#description, false, false) + +## sql that select all unprocessed orders +sql.selectOrder=select * from orders where consumed = false + +## sql that update the order as being processed +sql.markOrder=update orders set consumed = true where id = :#id \ No newline at end of file diff --git a/examples/camel/camel-sql/pom.xml b/examples/camel/camel-sql/pom.xml new file mode 100644 index 0000000..5a918b9 --- /dev/null +++ b/examples/camel/camel-sql/pom.xml @@ -0,0 +1,39 @@ + + + + + + + camel-examples + org.apache.servicemix.examples + 5.0.0-SNAPSHOT + + 4.0.0 + + camel-sql + pom + + camel-sql-datasource-derby + camel-sql-orders + camel-sql-datasource-pgsql + camel-sql-datasource-h2 + + + + \ No newline at end of file diff --git a/examples/camel/pom.xml b/examples/camel/pom.xml index f2d5dee..0f1ec8d 100644 --- a/examples/camel/pom.xml +++ b/examples/camel/pom.xml @@ -36,6 +36,7 @@ camel-blueprint camel-osgi camel-drools + camel-sql diff --git a/pom.xml b/pom.xml index 4de2b81..636699c 100644 --- a/pom.xml +++ b/pom.xml @@ -158,12 +158,14 @@ 5.2_3 1.8.2_1 1.4 + 1.4_3 3.1_6 2.4_4 2.2 1.6 2.4 1.0_5 + 10.9.1.0_1 1.6.1_5 ${drools.version}_1 1.2.7_3 @@ -177,6 +179,7 @@ 2.4.1_1 1.5.2_2 2.2.4_4 + 4.3.1 2.7.0_4 2.0.8_4 1.3_4 @@ -203,7 +206,7 @@ 1.2 1.6 2.2.1 - 2.1.0 + 2.3.7 1.2.12 @@ -230,6 +233,7 @@ 3.1.1 1.0.0 0.2.1 + 9.1-901 1.9.1 1.1 1.6.6