You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2021/04/08 08:55:23 UTC
[camel] branch master updated: camel-sql - Expose template. options
on sql-stored. Fixed using the correct jdbc template. Polished docs. Added
unit test.
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new cdb8d34 camel-sql - Expose template. options on sql-stored. Fixed using the correct jdbc template. Polished docs. Added unit test.
cdb8d34 is described below
commit cdb8d34220cf69d6eb532d98b06a0ab91a083c3c
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Apr 8 10:54:48 2021 +0200
camel-sql - Expose template. options on sql-stored. Fixed using the correct jdbc template. Polished docs. Added unit test.
---
.../camel/catalog/docs/sql-stored-component.adoc | 15 +++++-
.../sql/stored/SqlStoredEndpointConfigurer.java | 15 ++++++
.../sql/stored/SqlStoredEndpointUriFactory.java | 3 +-
.../camel/component/sql/stored/sql-stored.json | 3 +-
.../src/main/docs/sql-stored-component.adoc | 13 ++++-
.../apache/camel/component/sql/SqlComponent.java | 1 +
.../component/sql/stored/SqlStoredComponent.java | 1 +
.../component/sql/stored/SqlStoredEndpoint.java | 14 +++++-
.../sql/stored/TemplateStoredProcedure.java | 4 +-
.../sql/stored/ProducerQueryTimeoutTest.java | 38 +++++++++++++++
.../dsl/SqlStoredEndpointBuilderFactory.java | 56 +++++++++++++++++++++-
.../modules/ROOT/pages/sql-stored-component.adoc | 15 +++++-
12 files changed, 167 insertions(+), 11 deletions(-)
diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/sql-stored-component.adoc b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/sql-stored-component.adoc
index c0c7de1..ffde682 100644
--- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/sql-stored-component.adoc
+++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/sql-stored-component.adoc
@@ -109,7 +109,7 @@ with the following path and query parameters:
|===
-=== Query Parameters (7 parameters):
+=== Query Parameters (8 parameters):
[width="100%",cols="2,5,^1,2",options="header"]
@@ -122,6 +122,7 @@ with the following path and query parameters:
| *noop* (producer) | If set, will ignore the results of the template and use the existing IN message as the OUT message for the continuation of processing | false | boolean
| *outputHeader* (producer) | 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. | | String
| *useMessageBodyForTemplate* (producer) | 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. | false | boolean
+| *templateOptions* (advanced) | Configures the Spring JdbcTemplate with the key/values from the Map | | Map
|===
// endpoint options: END
@@ -227,6 +228,18 @@ parameter's "name" defines both the SQL parameter name, as well as the result he
Actual call will be done using org.springframework.jdbc.core.SqlInOutParameter.
+=== Query Timeout
+
+You can configure query timeout (via `template.queryTimeout`) on statements used for query processing as shown:
+
+[source,xml]
+----
+<to uri="sql-stored:MYFUNC(INOUT DECIMAL(10) ${headers.inheader} outheader)?template.queryTimeout=5000"/>
+----
+
+This will be overridden by the remaining transaction timeout when executing within a transaction that has a timeout specified at the transaction level.
+
+
== Camel SQL Starter
A starter module is available to spring-boot users. When using the starter,
diff --git a/components/camel-sql/src/generated/java/org/apache/camel/component/sql/stored/SqlStoredEndpointConfigurer.java b/components/camel-sql/src/generated/java/org/apache/camel/component/sql/stored/SqlStoredEndpointConfigurer.java
index 16ce804..9382429 100644
--- a/components/camel-sql/src/generated/java/org/apache/camel/component/sql/stored/SqlStoredEndpointConfigurer.java
+++ b/components/camel-sql/src/generated/java/org/apache/camel/component/sql/stored/SqlStoredEndpointConfigurer.java
@@ -30,6 +30,8 @@ public class SqlStoredEndpointConfigurer extends PropertyConfigurerSupport imple
case "noop": target.setNoop(property(camelContext, boolean.class, value)); return true;
case "outputheader":
case "outputHeader": target.setOutputHeader(property(camelContext, java.lang.String.class, value)); return true;
+ case "templateoptions":
+ case "templateOptions": target.setTemplateOptions(property(camelContext, java.util.Map.class, value)); return true;
case "usemessagebodyfortemplate":
case "useMessageBodyForTemplate": target.setUseMessageBodyForTemplate(property(camelContext, boolean.class, value)); return true;
default: return false;
@@ -48,6 +50,8 @@ public class SqlStoredEndpointConfigurer extends PropertyConfigurerSupport imple
case "noop": return boolean.class;
case "outputheader":
case "outputHeader": return java.lang.String.class;
+ case "templateoptions":
+ case "templateOptions": return java.util.Map.class;
case "usemessagebodyfortemplate":
case "useMessageBodyForTemplate": return boolean.class;
default: return null;
@@ -67,10 +71,21 @@ public class SqlStoredEndpointConfigurer extends PropertyConfigurerSupport imple
case "noop": return target.isNoop();
case "outputheader":
case "outputHeader": return target.getOutputHeader();
+ case "templateoptions":
+ case "templateOptions": return target.getTemplateOptions();
case "usemessagebodyfortemplate":
case "useMessageBodyForTemplate": return target.isUseMessageBodyForTemplate();
default: return null;
}
}
+
+ @Override
+ public Object getCollectionValueType(Object target, String name, boolean ignoreCase) {
+ switch (ignoreCase ? name.toLowerCase() : name) {
+ case "templateoptions":
+ case "templateOptions": return java.lang.Object.class;
+ default: return null;
+ }
+ }
}
diff --git a/components/camel-sql/src/generated/java/org/apache/camel/component/sql/stored/SqlStoredEndpointUriFactory.java b/components/camel-sql/src/generated/java/org/apache/camel/component/sql/stored/SqlStoredEndpointUriFactory.java
index cae2d95..78ad32f 100644
--- a/components/camel-sql/src/generated/java/org/apache/camel/component/sql/stored/SqlStoredEndpointUriFactory.java
+++ b/components/camel-sql/src/generated/java/org/apache/camel/component/sql/stored/SqlStoredEndpointUriFactory.java
@@ -20,11 +20,12 @@ public class SqlStoredEndpointUriFactory extends org.apache.camel.support.compon
private static final Set<String> PROPERTY_NAMES;
private static final Set<String> SECRET_PROPERTY_NAMES;
static {
- Set<String> props = new HashSet<>(8);
+ Set<String> props = new HashSet<>(9);
props.add("template");
props.add("noop");
props.add("lazyStartProducer");
props.add("useMessageBodyForTemplate");
+ props.add("templateOptions");
props.add("outputHeader");
props.add("function");
props.add("batch");
diff --git a/components/camel-sql/src/generated/resources/org/apache/camel/component/sql/stored/sql-stored.json b/components/camel-sql/src/generated/resources/org/apache/camel/component/sql/stored/sql-stored.json
index c38c661..1c8fd71 100644
--- a/components/camel-sql/src/generated/resources/org/apache/camel/component/sql/stored/sql-stored.json
+++ b/components/camel-sql/src/generated/resources/org/apache/camel/component/sql/stored/sql-stored.json
@@ -34,6 +34,7 @@
"lazyStartProducer": { "kind": "parameter", "displayName": "Lazy Start Producer", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during sta [...]
"noop": { "kind": "parameter", "displayName": "Noop", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "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" },
"outputHeader": { "kind": "parameter", "displayName": "Output Header", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "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 va [...]
- "useMessageBodyForTemplate": { "kind": "parameter", "displayName": "Use Message Body For Template", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "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." }
+ "useMessageBodyForTemplate": { "kind": "parameter", "displayName": "Use Message Body For Template", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "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." },
+ "templateOptions": { "kind": "parameter", "displayName": "Template Options", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "java.util.Map<java.lang.String, java.lang.Object>", "prefix": "template.", "multiValue": true, "deprecated": false, "autowired": false, "secret": false, "description": "Configures the Spring JdbcTemplate with the key\/values from the Map" }
}
}
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 7dd12d2..ffde682 100644
--- a/components/camel-sql/src/main/docs/sql-stored-component.adoc
+++ b/components/camel-sql/src/main/docs/sql-stored-component.adoc
@@ -109,7 +109,7 @@ with the following path and query parameters:
|===
-=== Query Parameters (7 parameters):
+=== Query Parameters (8 parameters):
[width="100%",cols="2,5,^1,2",options="header"]
@@ -122,6 +122,7 @@ with the following path and query parameters:
| *noop* (producer) | If set, will ignore the results of the template and use the existing IN message as the OUT message for the continuation of processing | false | boolean
| *outputHeader* (producer) | 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. | | String
| *useMessageBodyForTemplate* (producer) | 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. | false | boolean
+| *templateOptions* (advanced) | Configures the Spring JdbcTemplate with the key/values from the Map | | Map
|===
// endpoint options: END
@@ -228,7 +229,15 @@ parameter's "name" defines both the SQL parameter name, as well as the result he
Actual call will be done using org.springframework.jdbc.core.SqlInOutParameter.
=== Query Timeout
-Sets the query timeout property on statements used for query processing. This will be overridden by the remaining transaction timeout when executing within a transaction that has a timeout specified at the transaction level.
+
+You can configure query timeout (via `template.queryTimeout`) on statements used for query processing as shown:
+
+[source,xml]
+----
+<to uri="sql-stored:MYFUNC(INOUT DECIMAL(10) ${headers.inheader} outheader)?template.queryTimeout=5000"/>
+----
+
+This will be overridden by the remaining transaction timeout when executing within a transaction that has a timeout specified at the transaction level.
== Camel SQL Starter
diff --git a/components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlComponent.java b/components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlComponent.java
index b5b1bd5..d974ce6 100644
--- a/components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlComponent.java
+++ b/components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlComponent.java
@@ -135,6 +135,7 @@ public class SqlComponent extends DefaultComponent {
endpoint.setDataSource(ds);
endpoint.setDataSourceRef(dataSourceRef);
endpoint.setTemplateOptions(templateOptions);
+ setProperties(endpoint, parameters);
return endpoint;
}
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 97f4cfd..73f5a4e 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
@@ -69,6 +69,7 @@ public class SqlStoredComponent extends DefaultComponent {
SqlStoredEndpoint endpoint = new SqlStoredEndpoint(uri, this, jdbcTemplate);
endpoint.setTemplate(template);
+ setProperties(endpoint, parameters);
return endpoint;
}
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 185387b..9de682c 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
@@ -16,6 +16,8 @@
*/
package org.apache.camel.component.sql.stored;
+import java.util.Map;
+
import javax.sql.DataSource;
import org.apache.camel.Consumer;
@@ -58,6 +60,9 @@ public class SqlStoredEndpoint extends DefaultEndpoint {
private String outputHeader;
@UriParam(description = "Whether this call is for a function.")
private boolean function;
+ @UriParam(label = "advanced", prefix = "template.", multiValue = true,
+ description = "Configures the Spring JdbcTemplate with the key/values from the Map")
+ private Map<String, Object> templateOptions;
public SqlStoredEndpoint(String uri, SqlStoredComponent component, JdbcTemplate jdbcTemplate) {
super(uri, component);
@@ -162,5 +167,12 @@ public class SqlStoredEndpoint extends DefaultEndpoint {
public void setFunction(boolean function) {
this.function = function;
}
-
+
+ public Map<String, Object> getTemplateOptions() {
+ return templateOptions;
+ }
+
+ public void setTemplateOptions(Map<String, Object> templateOptions) {
+ this.templateOptions = templateOptions;
+ }
}
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 61c7253..e9637d9 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
@@ -44,11 +44,9 @@ public class TemplateStoredProcedure extends StoredProcedure {
private List<InOutParameter> inOutParameterList = new ArrayList<>();
public TemplateStoredProcedure(JdbcTemplate jdbcTemplate, Template template, boolean function) {
+ setJdbcTemplate(jdbcTemplate);
this.template = template;
setFunction(function);
- setDataSource(jdbcTemplate.getDataSource());
-
- setQueryTimeout(jdbcTemplate.getQueryTimeout());
setSql(template.getProcedureName());
for (Object parameter : template.getParameterList()) {
diff --git a/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/ProducerQueryTimeoutTest.java b/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/ProducerQueryTimeoutTest.java
new file mode 100644
index 0000000..c7c899f
--- /dev/null
+++ b/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/ProducerQueryTimeoutTest.java
@@ -0,0 +1,38 @@
+/*
+ * 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.stored;
+
+import org.apache.camel.builder.RouteBuilder;
+
+public class ProducerQueryTimeoutTest extends ProducerTest {
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ // required for the sql component
+ getContext().getComponent("sql-stored", SqlStoredComponent.class).setDataSource(db);
+
+ from("direct:query").to("sql-stored:SUBNUMBERS(INTEGER ${headers.num1},INTEGER ${headers"
+ + ".num2},OUT INTEGER resultofsub)?template.queryTimeout=5000")
+ .to("mock:query");
+ }
+ };
+ }
+
+}
diff --git a/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/SqlStoredEndpointBuilderFactory.java b/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/SqlStoredEndpointBuilderFactory.java
index 59344c9..74b7a3d 100644
--- a/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/SqlStoredEndpointBuilderFactory.java
+++ b/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/SqlStoredEndpointBuilderFactory.java
@@ -16,6 +16,7 @@
*/
package org.apache.camel.builder.endpoint.dsl;
+import java.util.Map;
import javax.annotation.Generated;
import org.apache.camel.builder.EndpointConsumerBuilder;
import org.apache.camel.builder.EndpointProducerBuilder;
@@ -34,6 +35,9 @@ public interface SqlStoredEndpointBuilderFactory {
* Builder for endpoint for the SQL Stored Procedure component.
*/
public interface SqlStoredEndpointBuilder extends EndpointProducerBuilder {
+ default AdvancedSqlStoredEndpointBuilder advanced() {
+ return (AdvancedSqlStoredEndpointBuilder) this;
+ }
/**
* Enables or disables batch mode.
*
@@ -265,6 +269,56 @@ public interface SqlStoredEndpointBuilderFactory {
}
}
+ /**
+ * Advanced builder for endpoint for the SQL Stored Procedure component.
+ */
+ public interface AdvancedSqlStoredEndpointBuilder
+ extends
+ EndpointProducerBuilder {
+ default SqlStoredEndpointBuilder basic() {
+ return (SqlStoredEndpointBuilder) this;
+ }
+ /**
+ * Configures the Spring JdbcTemplate with the key/values from the Map.
+ *
+ * The option is a: <code>java.util.Map&lt;java.lang.String,
+ * java.lang.Object&gt;</code> type.
+ * The option is multivalued, and you can use the
+ * templateOptions(String, Object) method to add a value (call the
+ * method multiple times to set more values).
+ *
+ * Group: advanced
+ *
+ * @param key the option key
+ * @param value the option value
+ * @return the dsl builder
+ */
+ default AdvancedSqlStoredEndpointBuilder templateOptions(
+ String key,
+ Object value) {
+ doSetMultiValueProperty("templateOptions", "template." + key, value);
+ return this;
+ }
+ /**
+ * Configures the Spring JdbcTemplate with the key/values from the Map.
+ *
+ * The option is a: <code>java.util.Map&lt;java.lang.String,
+ * java.lang.Object&gt;</code> type.
+ * The option is multivalued, and you can use the
+ * templateOptions(String, Object) method to add a value (call the
+ * method multiple times to set more values).
+ *
+ * Group: advanced
+ *
+ * @param values the values
+ * @return the dsl builder
+ */
+ default AdvancedSqlStoredEndpointBuilder templateOptions(Map values) {
+ doSetMultiValueProperties("templateOptions", "template.", values);
+ return this;
+ }
+ }
+
public interface SqlStoredBuilders {
/**
* SQL Stored Procedure (camel-sql)
@@ -312,7 +366,7 @@ public interface SqlStoredEndpointBuilderFactory {
static SqlStoredEndpointBuilder endpointBuilder(
String componentName,
String path) {
- class SqlStoredEndpointBuilderImpl extends AbstractEndpointBuilder implements SqlStoredEndpointBuilder {
+ class SqlStoredEndpointBuilderImpl extends AbstractEndpointBuilder implements SqlStoredEndpointBuilder, AdvancedSqlStoredEndpointBuilder {
public SqlStoredEndpointBuilderImpl(String path) {
super(componentName, path);
}
diff --git a/docs/components/modules/ROOT/pages/sql-stored-component.adoc b/docs/components/modules/ROOT/pages/sql-stored-component.adoc
index 2c24ca7..69cd782 100644
--- a/docs/components/modules/ROOT/pages/sql-stored-component.adoc
+++ b/docs/components/modules/ROOT/pages/sql-stored-component.adoc
@@ -111,7 +111,7 @@ with the following path and query parameters:
|===
-=== Query Parameters (7 parameters):
+=== Query Parameters (8 parameters):
[width="100%",cols="2,5,^1,2",options="header"]
@@ -124,6 +124,7 @@ with the following path and query parameters:
| *noop* (producer) | If set, will ignore the results of the template and use the existing IN message as the OUT message for the continuation of processing | false | boolean
| *outputHeader* (producer) | 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. | | String
| *useMessageBodyForTemplate* (producer) | 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. | false | boolean
+| *templateOptions* (advanced) | Configures the Spring JdbcTemplate with the key/values from the Map | | Map
|===
// endpoint options: END
@@ -229,6 +230,18 @@ parameter's "name" defines both the SQL parameter name, as well as the result he
Actual call will be done using org.springframework.jdbc.core.SqlInOutParameter.
+=== Query Timeout
+
+You can configure query timeout (via `template.queryTimeout`) on statements used for query processing as shown:
+
+[source,xml]
+----
+<to uri="sql-stored:MYFUNC(INOUT DECIMAL(10) ${headers.inheader} outheader)?template.queryTimeout=5000"/>
+----
+
+This will be overridden by the remaining transaction timeout when executing within a transaction that has a timeout specified at the transaction level.
+
+
== Camel SQL Starter
A starter module is available to spring-boot users. When using the starter,