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
commit 9aec62f55b2c2e62016aed40f40f13564e68b456 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Wed Aug 12 13:57:11 2020 +0200 CAMEL-15400: fixed camel-jpa parameters should have prefix for multivalued endpoint-dsl --- .../org/apache/camel/component/jpa/jpa.json | 2 +- .../apache/camel/component/jpa/JpaComponent.java | 6 +++++ .../apache/camel/component/jpa/JpaEndpoint.java | 2 +- ...WithNamedQueryAndParametersMultivaluedTest.java | 27 ++++++++++++++++++++++ .../endpoint/dsl/JpaEndpointBuilderFactory.java | 4 ++-- 5 files changed, 37 insertions(+), 4 deletions(-) diff --git a/components/camel-jpa/src/generated/resources/org/apache/camel/component/jpa/jpa.json b/components/camel-jpa/src/generated/resources/org/apache/camel/component/jpa/jpa.json index fd532ca..2a4994a 100644 --- a/components/camel-jpa/src/generated/resources/org/apache/camel/component/jpa/jpa.json +++ b/components/camel-jpa/src/generated/resources/org/apache/camel/component/jpa/jpa.json @@ -50,7 +50,7 @@ "transacted": { "kind": "parameter", "displayName": "Transacted", "group": "consumer", "label": "consumer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "Whether to run the consumer in transacted mode, by which all messages will either commit or rollback, when the entire batch has been processed. The default behavior (false) is to commit all the previously successfully processed messages, and [...] "exceptionHandler": { "kind": "parameter", "displayName": "Exception Handler", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "object", "javaType": "org.apache.camel.spi.ExceptionHandler", "optionalPrefix": "consumer.", "deprecated": false, "secret": false, "description": "To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with [...] "exchangePattern": { "kind": "parameter", "displayName": "Exchange Pattern", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "object", "javaType": "org.apache.camel.ExchangePattern", "enum": [ "InOnly", "InOut", "InOptionalOut" ], "deprecated": false, "secret": false, "description": "Sets the exchange pattern when the consumer creates an exchange." }, - "parameters": { "kind": "parameter", "displayName": "Parameters", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "object", "javaType": "java.util.Map<java.lang.String, java.lang.Object>", "multiValue": true, "deprecated": false, "secret": false, "description": "This key\/value mapping is used for building the query parameters. It is expected to be of the generic type java.util.Map where the keys are the named parameters of a given JPA query a [...] + "parameters": { "kind": "parameter", "displayName": "Parameters", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "object", "javaType": "java.util.Map<java.lang.String, java.lang.Object>", "prefix": "parameters.", "multiValue": true, "deprecated": false, "secret": false, "description": "This key\/value mapping is used for building the query parameters. It is expected to be of the generic type java.util.Map where the keys are the named paramete [...] "pollStrategy": { "kind": "parameter", "displayName": "Poll Strategy", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "object", "javaType": "org.apache.camel.spi.PollingConsumerPollStrategy", "deprecated": false, "secret": false, "description": "A pluggable org.apache.camel.PollingConsumerPollingStrategy allowing you to provide your custom implementation to control error handling usually occurred during the poll operation before an Exchange h [...] "findEntity": { "kind": "parameter", "displayName": "Find Entity", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "If enabled then the producer will find a single entity by using the message body as key and entityType as the class type. This can be used instead of a query to find a single entity." }, "flushOnSend": { "kind": "parameter", "displayName": "Flush On Send", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": "true", "description": "Flushes the EntityManager after the entity bean has been persisted." }, diff --git a/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaComponent.java b/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaComponent.java index 9bec929..7883c72 100644 --- a/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaComponent.java +++ b/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaComponent.java @@ -26,6 +26,7 @@ import org.apache.camel.spi.Metadata; import org.apache.camel.spi.annotations.Component; import org.apache.camel.support.DefaultComponent; import org.apache.camel.util.ObjectHelper; +import org.apache.camel.util.PropertiesHelper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.transaction.PlatformTransactionManager; @@ -120,6 +121,11 @@ public class JpaComponent extends DefaultComponent { endpoint.setJoinTransaction(isJoinTransaction()); endpoint.setSharedEntityManager(isSharedEntityManager()); + Map<String, Object> params = PropertiesHelper.extractProperties(options, "parameters.", true); + if (!params.isEmpty()) { + endpoint.setParameters(params); + } + // lets interpret the next string as a class if (ObjectHelper.isNotEmpty(path)) { // provide the class loader of this component to work in OSGi environments as camel-jpa must be able diff --git a/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaEndpoint.java b/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaEndpoint.java index 3854411..37af064 100644 --- a/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaEndpoint.java +++ b/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaEndpoint.java @@ -82,7 +82,7 @@ public class JpaEndpoint extends ScheduledPollEndpoint { private String nativeQuery; @UriParam(label = "consumer", defaultValue = "PESSIMISTIC_WRITE") private LockModeType lockModeType = LockModeType.PESSIMISTIC_WRITE; - @UriParam(label = "consumer,advanced", multiValue = true) + @UriParam(label = "consumer,advanced", multiValue = true, prefix = "parameters.") private Map<String, Object> parameters; @UriParam private Class<?> resultClass; diff --git a/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaWithNamedQueryAndParametersMultivaluedTest.java b/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaWithNamedQueryAndParametersMultivaluedTest.java new file mode 100644 index 0000000..c5b91be --- /dev/null +++ b/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaWithNamedQueryAndParametersMultivaluedTest.java @@ -0,0 +1,27 @@ +/* + * 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.jpa; + +import org.apache.camel.examples.Customer; + +public class JpaWithNamedQueryAndParametersMultivaluedTest extends JpaWithNamedQueryAndParametersTest { + + protected String getEndpointUri() { + return "jpa://" + Customer.class.getName() + "?namedQuery=findAllCustomersWithName¶meters.custName=Willem"; + } + +} diff --git a/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/JpaEndpointBuilderFactory.java b/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/JpaEndpointBuilderFactory.java index 330f45e..247e9fe 100644 --- a/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/JpaEndpointBuilderFactory.java +++ b/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/JpaEndpointBuilderFactory.java @@ -932,7 +932,7 @@ public interface JpaEndpointBuilderFactory { default AdvancedJpaEndpointConsumerBuilder parameters( String key, Object value) { - doSetMultiValueProperty("parameters", "null" + key, value); + doSetMultiValueProperty("parameters", "parameters." + key, value); return this; } /** @@ -953,7 +953,7 @@ public interface JpaEndpointBuilderFactory { * Group: consumer (advanced) */ default AdvancedJpaEndpointConsumerBuilder parameters(Map values) { - doSetMultiValueProperties("parameters", "null", values); + doSetMultiValueProperties("parameters", "parameters.", values); return this; } /**