CAMEL-10618: documentation

Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/0548f87d
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/0548f87d
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/0548f87d

Branch: refs/heads/master
Commit: 0548f87de23a38b31620b439ab2530a7bc2138f6
Parents: ec3f9e7
Author: Nicola Ferraro <ni.ferr...@gmail.com>
Authored: Mon Feb 13 17:32:07 2017 +0100
Committer: Nicola Ferraro <ni.ferr...@gmail.com>
Committed: Mon Feb 13 17:32:07 2017 +0100

----------------------------------------------------------------------
 .../camel-sql/src/main/docs/sql-component.adoc  | 34 +++++++++++++++++++-
 .../src/main/docs/sql-stored-component.adoc     | 33 +++++++++++++++++++
 .../sql/stored/SqlStoredComponent.java          | 10 ++++++
 .../sql/DataSourceAutoConfigurationTest.java    | 27 +++++++++++++++-
 .../component/sql/support/DummyJDBCDriver.java  | 16 +++++++++
 5 files changed, 118 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/0548f87d/components/camel-sql/src/main/docs/sql-component.adoc
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/main/docs/sql-component.adoc 
b/components/camel-sql/src/main/docs/sql-component.adoc
index 7d217fa..fcc273c 100644
--- a/components/camel-sql/src/main/docs/sql-component.adoc
+++ b/components/camel-sql/src/main/docs/sql-component.adoc
@@ -725,7 +725,39 @@ 
class="org.apache.camel.processor.aggregate.jdbc.DefaultJdbcOptimisticLockingExc
 <value>com.foo.sql.MyOtherViolationExceptoion</value> </util:set>
 </property> </bean>
 -------------------------------------------------------------------------------
- 
+
+### Camel Sql Starter
+
+A starter module is available to spring-boot users. When using the starter,
+the `DataSource` can be directly configured using spring-boot properties.
+
+[source]
+------------------------------------------------------
+# Example for a mysql datasource
+spring.datasource.url=jdbc:mysql://localhost/test
+spring.datasource.username=dbuser
+spring.datasource.password=dbpass
+spring.datasource.driver-class-name=com.mysql.jdbc.Driver
+------------------------------------------------------
+
+To use this feature, add the following dependencies to your spring boot 
pom.xml file:
+
+[source,xml]
+------------------------------------------------------
+<dependency>
+    <groupId>org.apache.camel</groupId>
+    <artifactId>camel-sql-starter</artifactId>
+    <version>${camel.version}</version> <!-- use the same version as your 
Camel core version -->
+</dependency>
+
+<dependency>
+    <groupId>org.springframework.boot</groupId>
+    <artifactId>spring-boot-starter-jdbc</artifactId>
+    <version>${spring-boot-version}</version>
+</dependency>
+------------------------------------------------------
+
+You should also include the specific database driver, if needed.
 
 ### See Also
 

http://git-wip-us.apache.org/repos/asf/camel/blob/0548f87d/components/camel-sql/src/main/docs/sql-stored-component.adoc
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/main/docs/sql-stored-component.adoc 
b/components/camel-sql/src/main/docs/sql-stored-component.adoc
index 079ead1..ce7bffa 100644
--- a/components/camel-sql/src/main/docs/sql-stored-component.adoc
+++ b/components/camel-sql/src/main/docs/sql-stored-component.adoc
@@ -121,6 +121,39 @@ In SQL term the stored procedure could be declared as:
 CREATE PROCEDURE SUBNUMBERS(VALUE1 INTEGER, VALUE2 INTEGER,OUT RESULT INTEGER)
 ------------------------------------------------------------------------------
 
+### Camel Sql Starter
+
+A starter module is available to spring-boot users. When using the starter,
+the `DataSource` can be directly configured using spring-boot properties.
+
+[source]
+------------------------------------------------------
+# Example for a mysql datasource
+spring.datasource.url=jdbc:mysql://localhost/test
+spring.datasource.username=dbuser
+spring.datasource.password=dbpass
+spring.datasource.driver-class-name=com.mysql.jdbc.Driver
+------------------------------------------------------
+
+To use this feature, add the following dependencies to your spring boot 
pom.xml file:
+
+[source,xml]
+------------------------------------------------------
+<dependency>
+    <groupId>org.apache.camel</groupId>
+    <artifactId>camel-sql-starter</artifactId>
+    <version>${camel.version}</version> <!-- use the same version as your 
Camel core version -->
+</dependency>
+
+<dependency>
+    <groupId>org.springframework.boot</groupId>
+    <artifactId>spring-boot-starter-jdbc</artifactId>
+    <version>${spring-boot-version}</version>
+</dependency>
+------------------------------------------------------
+
+You should also include the specific database driver, if needed.
+
 ### See Also
 
 * link:configuring-camel.html[Configuring Camel]

http://git-wip-us.apache.org/repos/asf/camel/blob/0548f87d/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/SqlStoredComponent.java
----------------------------------------------------------------------
diff --git 
a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/SqlStoredComponent.java
 
b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/SqlStoredComponent.java
index 0cefe31..ab8a9f0 100644
--- 
a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/SqlStoredComponent.java
+++ 
b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/SqlStoredComponent.java
@@ -17,6 +17,7 @@
 package org.apache.camel.component.sql.stored;
 
 import java.util.Map;
+import java.util.Set;
 import javax.sql.DataSource;
 
 import org.apache.camel.CamelContext;
@@ -57,6 +58,15 @@ public class SqlStoredComponent extends UriEndpointComponent 
{
             target = dataSource;
         }
         if (target == null) {
+            // check if the registry contains a single instance of DataSource
+            Set<DataSource> dataSources = 
getCamelContext().getRegistry().findByType(DataSource.class);
+            if (dataSources.size() > 1) {
+                throw new IllegalArgumentException("Multiple DataSources found 
in the registry and no explicit configuration provided");
+            } else if (dataSources.size() == 1) {
+                target = dataSources.stream().findFirst().orElse(null);
+            }
+        }
+        if (target == null) {
             throw new IllegalArgumentException("DataSource must be 
configured");
         }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/0548f87d/platforms/spring-boot/components-starter/camel-sql-starter/src/test/java/org/apache/camel/component/sql/DataSourceAutoConfigurationTest.java
----------------------------------------------------------------------
diff --git 
a/platforms/spring-boot/components-starter/camel-sql-starter/src/test/java/org/apache/camel/component/sql/DataSourceAutoConfigurationTest.java
 
b/platforms/spring-boot/components-starter/camel-sql-starter/src/test/java/org/apache/camel/component/sql/DataSourceAutoConfigurationTest.java
index 0528e04..797f747 100644
--- 
a/platforms/spring-boot/components-starter/camel-sql-starter/src/test/java/org/apache/camel/component/sql/DataSourceAutoConfigurationTest.java
+++ 
b/platforms/spring-boot/components-starter/camel-sql-starter/src/test/java/org/apache/camel/component/sql/DataSourceAutoConfigurationTest.java
@@ -1,8 +1,26 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 package org.apache.camel.component.sql;
 
 import javax.sql.DataSource;
 
 import org.apache.camel.CamelContext;
+import org.apache.camel.component.sql.stored.SqlStoredComponent;
+import org.apache.camel.component.sql.stored.SqlStoredEndpoint;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -39,10 +57,17 @@ public class DataSourceAutoConfigurationTest {
     }
 
     @Test
-    public void testCamelUsesTheConfiguredDatasource() throws Exception {
+    public void testSqlComponentUsesTheConfiguredDatasource() throws Exception 
{
         SqlComponent component = (SqlComponent) context.getComponent("sql");
         SqlEndpoint endpoint = (SqlEndpoint) 
component.createEndpoint("sql:select * from table where id=#");
         assertEquals(datasource, endpoint.getJdbcTemplate().getDataSource());
     }
 
+    @Test
+    public void testSqlStoredComponentUsesTheConfiguredDatasource() throws 
Exception {
+        SqlStoredComponent component = (SqlStoredComponent) 
context.getComponent("sql-stored");
+        SqlStoredEndpoint endpoint = (SqlStoredEndpoint) 
component.createEndpoint("sql:select * from table where id=#");
+        assertEquals(datasource, endpoint.getJdbcTemplate().getDataSource());
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/0548f87d/platforms/spring-boot/components-starter/camel-sql-starter/src/test/java/org/apache/camel/component/sql/support/DummyJDBCDriver.java
----------------------------------------------------------------------
diff --git 
a/platforms/spring-boot/components-starter/camel-sql-starter/src/test/java/org/apache/camel/component/sql/support/DummyJDBCDriver.java
 
b/platforms/spring-boot/components-starter/camel-sql-starter/src/test/java/org/apache/camel/component/sql/support/DummyJDBCDriver.java
index 7615014..a6cf27d 100644
--- 
a/platforms/spring-boot/components-starter/camel-sql-starter/src/test/java/org/apache/camel/component/sql/support/DummyJDBCDriver.java
+++ 
b/platforms/spring-boot/components-starter/camel-sql-starter/src/test/java/org/apache/camel/component/sql/support/DummyJDBCDriver.java
@@ -1,3 +1,19 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 package org.apache.camel.component.sql.support;
 
 import java.sql.Connection;

Reply via email to