You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2017/06/28 08:02:51 UTC

[1/2] camel git commit: CAMEL-11319: sql-stored - Add support for function

Repository: camel
Updated Branches:
  refs/heads/camel-2.18.x c25149322 -> 53164066b


CAMEL-11319: sql-stored - Add support for function

CAMEL-11463 (cherry picked from commit 239c7438a47ad8b93f75ba2de62e0580799aed69)


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

Branch: refs/heads/camel-2.18.x
Commit: 7691cbd8bc81035de6234d53a30d700ea0250bc9
Parents: c251493
Author: Claus Ibsen <da...@apache.org>
Authored: Wed May 24 14:12:57 2017 +0200
Committer: Andrea Tarocchi <at...@redhat.com>
Committed: Tue Jun 27 17:34:49 2017 +0200

----------------------------------------------------------------------
 .../src/main/docs/sql-stored-component.adoc     |  2 +-
 .../stored/CallableStatementWrapperFactory.java | 10 +++----
 .../component/sql/stored/SqlStoredEndpoint.java | 31 +++++++++++++++-----
 .../sql/stored/TemplateStoredProcedure.java     |  3 +-
 .../stored/CallableStatementWrapperTest.java    |  4 +--
 .../component/sql/stored/TemplateCacheTest.java |  2 +-
 6 files changed, 32 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/7691cbd8/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 1deff34..b49bcc3 100644
--- a/components/camel-sql/src/main/docs/sql-stored-component.adoc
+++ b/components/camel-sql/src/main/docs/sql-stored-component.adoc
@@ -95,6 +95,7 @@ The SQL StoredProcedure component supports 7 endpoint options which are listed b
 | template | producer |  | String | *Required* Sets the StoredProcedure template to perform
 | batch | producer | false | boolean | Enables or disables batch mode
 | dataSource | producer |  | DataSource | Sets the DataSource to use to communicate with the database.
+| function | producer | false | boolean | *Available as of Camel 2.18* Whether this call is for a function.
 | noop | producer | false | boolean | If set will ignore the results of the template and use the existing IN message as the OUT message for the continuation of processing
 | outputHeader | producer |  | String | Store the template result in a header instead of the message body. By default outputHeader == null and the template result is stored in the message body any existing content in the message body is discarded. If outputHeader is set the value is used as the name of the header to store the template result and the original message body is preserved.
 | useMessageBodyForTemplate | producer | false | boolean | Whether to use the message body as the template and then headers for parameters. If this option is enabled then the template in the uri is not used.
@@ -139,4 +140,3 @@ See Also
 * link:getting-started.html[Getting Started]
 
 * link:sql-component.html[SQL Component]
-

http://git-wip-us.apache.org/repos/asf/camel/blob/7691cbd8/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/CallableStatementWrapperFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/CallableStatementWrapperFactory.java b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/CallableStatementWrapperFactory.java
index 541192d..9e98449 100644
--- a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/CallableStatementWrapperFactory.java
+++ b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/CallableStatementWrapperFactory.java
@@ -29,21 +29,19 @@ import org.springframework.jdbc.core.JdbcTemplate;
 public class CallableStatementWrapperFactory extends ServiceSupport {
 
     public static final int TEMPLATE_CACHE_DEFAULT_SIZE = 200;
-
     public static final int BATCH_TEMPLATE_CACHE_DEFAULT_SIZE = 200;
 
     final JdbcTemplate jdbcTemplate;
-
     final TemplateParser templateParser;
+    boolean function;
 
     private final LRUCache<String, TemplateStoredProcedure> templateCache = new LRUCache<>(TEMPLATE_CACHE_DEFAULT_SIZE);
-
     private final LRUCache<String, BatchCallableStatementCreatorFactory> batchTemplateCache = new LRUCache<>(BATCH_TEMPLATE_CACHE_DEFAULT_SIZE);
 
-    public CallableStatementWrapperFactory(JdbcTemplate jdbcTemplate, TemplateParser
-            templateParser) {
+    public CallableStatementWrapperFactory(JdbcTemplate jdbcTemplate, TemplateParser templateParser, boolean function) {
         this.jdbcTemplate = jdbcTemplate;
         this.templateParser = templateParser;
+        this.function = function;
     }
 
     public StatementWrapper create(String sql) throws SQLException {
@@ -68,7 +66,7 @@ public class CallableStatementWrapperFactory extends ServiceSupport {
             return templateStoredProcedure;
         }
 
-        templateStoredProcedure = new TemplateStoredProcedure(jdbcTemplate, templateParser.parseTemplate(sql));
+        templateStoredProcedure = new TemplateStoredProcedure(jdbcTemplate, templateParser.parseTemplate(sql), function);
 
         this.templateCache.put(sql, templateStoredProcedure);
 

http://git-wip-us.apache.org/repos/asf/camel/blob/7691cbd8/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/SqlStoredEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/SqlStoredEndpoint.java b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/SqlStoredEndpoint.java
index 221ee85..374a8f5 100644
--- a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/SqlStoredEndpoint.java
+++ b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/SqlStoredEndpoint.java
@@ -34,7 +34,7 @@ import org.springframework.jdbc.core.JdbcTemplate;
 @UriEndpoint(scheme = "sql-stored", title = "SQL StoredProcedure", syntax = "sql-stored:template", producerOnly = true, label = "database,sql")
 public class SqlStoredEndpoint extends DefaultPollingEndpoint {
 
-    private final CallableStatementWrapperFactory wrapperFactory;
+    private CallableStatementWrapperFactory wrapperFactory;
     private JdbcTemplate jdbcTemplate;
 
     @UriParam(description = "Sets the DataSource to use to communicate with the database.")
@@ -43,28 +43,28 @@ public class SqlStoredEndpoint extends DefaultPollingEndpoint {
     @UriPath(description = "Sets the StoredProcedure template to perform")
     @Metadata(required = "true")
     private String template;
-    @UriParam(label = "producer", description = "Enables or disables batch mode")
+    @UriParam(description = "Enables or disables batch mode")
     private boolean batch;
-    @UriParam(label = "producer", description = "Whether to use the message body as the template and then headers for parameters. If this option is enabled then the template in the uri is not used.")
+    @UriParam(description = "Whether to use the message body as the template and then headers for parameters. If this option is enabled then the template in the uri is not used.")
     private boolean useMessageBodyForTemplate;
-    @UriParam(label = "producer", description = "If set, will ignore the results of the template and use the existing IN message as the OUT message for the continuation of processing")
+    @UriParam(description = "If set, will ignore the results of the template and use the existing IN message as the OUT message for the continuation of processing")
     private boolean noop;
     @UriParam(description = "Store the template result in a header instead of the message body. By default, outputHeader == null and the template result is stored"
             + " in the message body, any existing content in the message body is discarded. If outputHeader is set, the value is used as the name of the header"
             + " to store the template result and the original message body is preserved.")
     private String outputHeader;
+    @UriParam(description = "Whether this call is for a function.")
+    private boolean function;
 
     public SqlStoredEndpoint(String uri, SqlStoredComponent component, JdbcTemplate jdbcTemplate) {
         super(uri, component);
         setJdbcTemplate(jdbcTemplate);
-        wrapperFactory = new CallableStatementWrapperFactory(jdbcTemplate, new TemplateParser());
     }
 
     public Producer createProducer() throws Exception {
         return new SqlStoredProducer(this);
     }
 
-
     @Override
     protected String createEndpointUri() {
         // Make sure it's properly encoded
@@ -72,10 +72,17 @@ public class SqlStoredEndpoint extends DefaultPollingEndpoint {
     }
 
     @Override
+    protected void doStart() throws Exception {
+        this.wrapperFactory = new CallableStatementWrapperFactory(jdbcTemplate, new TemplateParser(), isFunction());
+        super.doStart();
+    }
+
+    @Override
     protected void doStop() throws Exception {
         super.doStop();
-        this.wrapperFactory.shutdown();
-
+        if (this.wrapperFactory != null) {
+            this.wrapperFactory.shutdown();
+        }
     }
 
     public JdbcTemplate getJdbcTemplate() {
@@ -134,6 +141,14 @@ public class SqlStoredEndpoint extends DefaultPollingEndpoint {
         this.dataSource = dataSource;
     }
 
+    public boolean isFunction() {
+        return function;
+    }
+
+    public void setFunction(boolean function) {
+        this.function = function;
+    }
+
     @Override
     public boolean isSingleton() {
         return false;

http://git-wip-us.apache.org/repos/asf/camel/blob/7691cbd8/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/TemplateStoredProcedure.java
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/TemplateStoredProcedure.java b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/TemplateStoredProcedure.java
index a71ec9b..c1bec3c 100644
--- a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/TemplateStoredProcedure.java
+++ b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/TemplateStoredProcedure.java
@@ -40,8 +40,9 @@ public class TemplateStoredProcedure extends StoredProcedure {
 
     private List<InputParameter> inputParameterList = new ArrayList<>();
 
-    public TemplateStoredProcedure(JdbcTemplate jdbcTemplate, Template template) {
+    public TemplateStoredProcedure(JdbcTemplate jdbcTemplate, Template template, boolean function) {
         this.template = template;
+        setFunction(function);
         setDataSource(jdbcTemplate.getDataSource());
 
         setSql(template.getProcedureName());

http://git-wip-us.apache.org/repos/asf/camel/blob/7691cbd8/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/CallableStatementWrapperTest.java
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/CallableStatementWrapperTest.java b/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/CallableStatementWrapperTest.java
index 09ccbe9..27996e8 100644
--- a/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/CallableStatementWrapperTest.java
+++ b/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/CallableStatementWrapperTest.java
@@ -45,14 +45,13 @@ public class CallableStatementWrapperTest extends CamelTestSupport {
                 .setType(EmbeddedDatabaseType.DERBY).addScript("sql/storedProcedureTest.sql").build();
         jdbcTemplate = new JdbcTemplate(db);
         templateParser = new TemplateParser();
-        this.factory = new CallableStatementWrapperFactory(jdbcTemplate, templateParser);
+        this.factory = new CallableStatementWrapperFactory(jdbcTemplate, templateParser, false);
         super.setUp();
     }
 
 
     @Test
     public void shouldExecuteStoredProcedure() throws Exception {
-
         CallableStatementWrapper wrapper = new CallableStatementWrapper("SUBNUMBERS"
                 + "(INTEGER ${header.v1},INTEGER ${header.v2},OUT INTEGER resultofsub)", factory);
 
@@ -75,7 +74,6 @@ public class CallableStatementWrapperTest extends CamelTestSupport {
     public void shouldExecuteNilacidProcedure() throws Exception {
         CallableStatementWrapper wrapper = new CallableStatementWrapper("NILADIC()", factory);
 
-
         wrapper.call(new WrapperExecuteCallback() {
             @Override
             public void execute(StatementWrapper statementWrapper) throws SQLException, DataAccessException {

http://git-wip-us.apache.org/repos/asf/camel/blob/7691cbd8/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/TemplateCacheTest.java
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/TemplateCacheTest.java b/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/TemplateCacheTest.java
index 4aee75c..2c43b16 100644
--- a/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/TemplateCacheTest.java
+++ b/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/TemplateCacheTest.java
@@ -46,7 +46,7 @@ public class TemplateCacheTest extends CamelTestSupport {
     @Test
     public void shouldCacheTemplateFunctions() throws InterruptedException {
         JdbcTemplate jdbcTemplate = new JdbcTemplate(db);
-        CallableStatementWrapperFactory fac = new CallableStatementWrapperFactory(jdbcTemplate, new TemplateParser());
+        CallableStatementWrapperFactory fac = new CallableStatementWrapperFactory(jdbcTemplate, new TemplateParser(), false);
 
         BatchCallableStatementCreatorFactory batchFactory1 = fac.getTemplateForBatch("FOO()");
         BatchCallableStatementCreatorFactory batchFactory2 = fac.getTemplateForBatch("FOO()");


[2/2] camel git commit: Regen

Posted by ac...@apache.org.
Regen


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

Branch: refs/heads/camel-2.18.x
Commit: 53164066b7e52772f83ee91fbda3b8aa1c642d2a
Parents: 7691cbd
Author: Andrea Cosentino <an...@gmail.com>
Authored: Wed Jun 28 10:02:14 2017 +0200
Committer: Andrea Cosentino <an...@gmail.com>
Committed: Wed Jun 28 10:02:14 2017 +0200

----------------------------------------------------------------------
 components/camel-sql/src/main/docs/sql-stored-component.adoc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/53164066/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 b49bcc3..94785bc 100644
--- a/components/camel-sql/src/main/docs/sql-stored-component.adoc
+++ b/components/camel-sql/src/main/docs/sql-stored-component.adoc
@@ -86,7 +86,7 @@ The SQL StoredProcedure component supports 1 options which are listed below.
 
 
 // endpoint options: START
-The SQL StoredProcedure component supports 7 endpoint options which are listed below:
+The SQL StoredProcedure component supports 8 endpoint options which are listed below:
 
 {% raw %}
 [width="100%",cols="2,1,1m,1m,5",options="header"]
@@ -95,7 +95,7 @@ The SQL StoredProcedure component supports 7 endpoint options which are listed b
 | template | producer |  | String | *Required* Sets the StoredProcedure template to perform
 | batch | producer | false | boolean | Enables or disables batch mode
 | dataSource | producer |  | DataSource | Sets the DataSource to use to communicate with the database.
-| function | producer | false | boolean | *Available as of Camel 2.18* Whether this call is for a function.
+| function | producer | false | boolean | Whether this call is for a function.
 | noop | producer | false | boolean | If set will ignore the results of the template and use the existing IN message as the OUT message for the continuation of processing
 | outputHeader | producer |  | String | Store the template result in a header instead of the message body. By default outputHeader == null and the template result is stored in the message body any existing content in the message body is discarded. If outputHeader is set the value is used as the name of the header to store the template result and the original message body is preserved.
 | useMessageBodyForTemplate | producer | false | boolean | Whether to use the message body as the template and then headers for parameters. If this option is enabled then the template in the uri is not used.