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 2019/04/22 12:11:36 UTC

[camel] branch master updated: CAMEL-13260: Polished

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 8ddd1c2  CAMEL-13260: Polished
8ddd1c2 is described below

commit 8ddd1c2d560d72e7051950d041f65ab0ed42152e
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Apr 22 14:11:02 2019 +0200

    CAMEL-13260: Polished
---
 .../camel-jooq/src/main/docs/jooq-component.adoc   |  8 +++---
 .../apache/camel/component/jooq/JooqComponent.java |  4 +++
 .../camel/component/jooq/JooqConfiguration.java    | 12 ++++-----
 .../apache/camel/component/jooq/JooqConsumer.java  | 19 ++++----------
 .../apache/camel/component/jooq/JooqEndpoint.java  | 20 ++++++++-------
 .../apache/camel/component/jooq/JooqOperation.java | 29 +++-------------------
 .../apache/camel/component/jooq/JooqProducer.java  |  2 +-
 .../camel/component/jooq/JooqComponentTest.java    |  3 ++-
 .../springboot/JooqComponentConfiguration.java     | 20 ++++++++++++---
 9 files changed, 52 insertions(+), 65 deletions(-)

diff --git a/components/camel-jooq/src/main/docs/jooq-component.adoc b/components/camel-jooq/src/main/docs/jooq-component.adoc
index 7656f8b..6f2c964 100644
--- a/components/camel-jooq/src/main/docs/jooq-component.adoc
+++ b/components/camel-jooq/src/main/docs/jooq-component.adoc
@@ -68,8 +68,8 @@ with the following path and query parameters:
 [width="100%",cols="2,5,^1,2",options="header"]
 |===
 | Name | Description | Default | Type
-| *entityType* | JOOQ entity class. |  | Class
-| *operation* | Type of operation to execute on query: execute, fetch, etc. |  | JooqOperation
+| *entityType* | JOOQ entity class |  | Class
+| *operation* | Type of operation to execute on query | NONE | JooqOperation
 |===
 
 
@@ -79,13 +79,13 @@ with the following path and query parameters:
 [width="100%",cols="2,5,^1,2",options="header"]
 |===
 | Name | Description | Default | Type
-| *query* (common) | SQL query. |  | String
 | *bridgeErrorHandler* (consumer) | Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean
-| *consumeDelete* (consumer) | Delete entity after it is consumed. | true | boolean
+| *consumeDelete* (consumer) | Delete entity after it is consumed | true | boolean
 | *sendEmptyMessageWhenIdle* (consumer) | If the polling consumer did not poll any files, you can enable this option to send an empty message (no body) instead. | false | boolean
 | *exceptionHandler* (consumer) | 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 exceptions, that will be logged at WARN or ERROR level and ignored. |  | ExceptionHandler
 | *exchangePattern* (consumer) | Sets the exchange pattern when the consumer creates an exchange. |  | ExchangePattern
 | *pollStrategy* (consumer) | 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 have been created and being routed in Camel. |  | PollingConsumerPoll Strategy
+| *query* (producer) | To execute plain SQL query |  | String
 | *synchronous* (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean
 | *backoffErrorThreshold* (scheduler) | The number of subsequent error polls (failed due some error) that should happen before the backoffMultipler should kick-in. |  | int
 | *backoffIdleThreshold* (scheduler) | The number of subsequent idle polls that should happen before the backoffMultipler should kick-in. |  | int
diff --git a/components/camel-jooq/src/main/java/org/apache/camel/component/jooq/JooqComponent.java b/components/camel-jooq/src/main/java/org/apache/camel/component/jooq/JooqComponent.java
index a6459ca..52a3df6 100644
--- a/components/camel-jooq/src/main/java/org/apache/camel/component/jooq/JooqComponent.java
+++ b/components/camel-jooq/src/main/java/org/apache/camel/component/jooq/JooqComponent.java
@@ -46,6 +46,10 @@ public class JooqComponent extends DefaultComponent {
         return endpoint;
     }
 
+    public JooqConfiguration getConfiguration() {
+        return configuration;
+    }
+
     public void setConfiguration(JooqConfiguration jooqConfiguration) {
         this.configuration = jooqConfiguration;
     }
diff --git a/components/camel-jooq/src/main/java/org/apache/camel/component/jooq/JooqConfiguration.java b/components/camel-jooq/src/main/java/org/apache/camel/component/jooq/JooqConfiguration.java
index e60cdf3..8e0cda8 100644
--- a/components/camel-jooq/src/main/java/org/apache/camel/component/jooq/JooqConfiguration.java
+++ b/components/camel-jooq/src/main/java/org/apache/camel/component/jooq/JooqConfiguration.java
@@ -25,16 +25,16 @@ import org.jooq.Configuration;
 @UriParams
 public class JooqConfiguration implements Cloneable {
 
-    @UriPath(description = "Type of operation to execute on query: execute, fetch, etc.", label = "Operation", name = "operation", displayName = "Operation")
-    private JooqOperation operation = JooqOperation.NONE;
-
-    @UriPath(name = "entityType", description = "JOOQ entity class.", label = "Entity type", displayName = "Entity type")
+    @UriPath(label = "common", description = "JOOQ entity class")
     private Class<?> entityType;
 
-    @UriParam(label = "consumer", defaultValue = "true", description = "Delete entity after it is consumed.")
+    @UriParam(label = "consumer", defaultValue = "true", description = "Delete entity after it is consumed")
     private boolean consumeDelete = true;
 
-    @UriParam(description = "SQL query.")
+    @UriPath(label = "producer", description = "Type of operation to execute on query", defaultValue = "NONE")
+    private JooqOperation operation = JooqOperation.NONE;
+
+    @UriParam(label = "producer", description = "To execute plain SQL query")
     private String query;
 
     private Configuration databaseConfiguration;
diff --git a/components/camel-jooq/src/main/java/org/apache/camel/component/jooq/JooqConsumer.java b/components/camel-jooq/src/main/java/org/apache/camel/component/jooq/JooqConsumer.java
index 2708dd1..a4b0ff1 100644
--- a/components/camel-jooq/src/main/java/org/apache/camel/component/jooq/JooqConsumer.java
+++ b/components/camel-jooq/src/main/java/org/apache/camel/component/jooq/JooqConsumer.java
@@ -19,7 +19,6 @@ package org.apache.camel.component.jooq;
 import java.util.LinkedList;
 import java.util.Queue;
 
-import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.support.ObjectHelper;
@@ -33,6 +32,7 @@ import org.jooq.UpdatableRecord;
 import org.jooq.impl.DSL;
 
 public class JooqConsumer extends ScheduledBatchPollingConsumer {
+
     private static final class DataHolder {
         private Exchange exchange;
         private Object result;
@@ -40,28 +40,19 @@ public class JooqConsumer extends ScheduledBatchPollingConsumer {
         }
     }
 
-    private final Processor processor;
-    private final JooqEndpoint endpoint;
-
     public JooqConsumer(JooqEndpoint endpoint, Processor processor) {
         super(endpoint, processor);
-        this.endpoint = endpoint;
-        this.processor = processor;
-    }
-
-    @Override
-    public Processor getProcessor() {
-        return processor;
     }
 
     @Override
-    public Endpoint getEndpoint() {
-        return endpoint;
+    public JooqEndpoint getEndpoint() {
+        return (JooqEndpoint) super.getEndpoint();
     }
 
     @Override
+    @SuppressWarnings("unchecked")
     protected int poll() throws Exception {
-        JooqConfiguration configuration = endpoint.getConfiguration();
+        JooqConfiguration configuration = getEndpoint().getConfiguration();
         Configuration dbConfig = configuration.getDatabaseConfiguration();
         Class<?> entityType = configuration.getEntityType();
         DSLContext context = DSL.using(dbConfig);
diff --git a/components/camel-jooq/src/main/java/org/apache/camel/component/jooq/JooqEndpoint.java b/components/camel-jooq/src/main/java/org/apache/camel/component/jooq/JooqEndpoint.java
index 50f1d58..d3bd0ef 100644
--- a/components/camel-jooq/src/main/java/org/apache/camel/component/jooq/JooqEndpoint.java
+++ b/components/camel-jooq/src/main/java/org/apache/camel/component/jooq/JooqEndpoint.java
@@ -26,11 +26,10 @@ import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.spi.UriEndpoint;
 import org.apache.camel.spi.UriParam;
 import org.apache.camel.support.ScheduledPollEndpoint;
-import org.apache.camel.util.ObjectHelper;
 import org.jooq.Query;
 import org.jooq.ResultQuery;
 
-@UriEndpoint(firstVersion = "3.0.0", scheme = "jooq", syntax = "jooq:entityType/operation", title = "JOOQ", label = "jooq")
+@UriEndpoint(firstVersion = "3.0.0", scheme = "jooq", syntax = "jooq:entityType/operation", title = "JOOQ", label = "database")
 public class JooqEndpoint extends ScheduledPollEndpoint {
 
     private Expression producerExpression;
@@ -55,17 +54,19 @@ public class JooqEndpoint extends ScheduledPollEndpoint {
             throw new IllegalArgumentException("Unexpected URI format. Expected ... , found '" + remaining + "'");
         }
 
-        Class<?> type = ObjectHelper.loadClass(parts[0]);
+        String className = parts[0];
+        Class<?> type = getCamelContext().getClassResolver().resolveClass(className);
         if (type != null) {
             configuration.setEntityType(type);
         }
 
         if (parts.length > 1) {
-            JooqOperation operation = JooqOperation.getByValue(parts[1]);
+            String op = parts[1];
+            JooqOperation operation = getCamelContext().getTypeConverter().convertTo(JooqOperation.class, op);
             if (operation != null) {
                 configuration.setOperation(operation);
             } else {
-                throw new IllegalArgumentException("Wrong operation: " + parts[1]);
+                throw new IllegalArgumentException("Wrong operation: " + op);
             }
         }
     }
@@ -79,6 +80,10 @@ public class JooqEndpoint extends ScheduledPollEndpoint {
         return configuration;
     }
 
+    public void setConfiguration(JooqConfiguration configuration) {
+        this.configuration = configuration;
+    }
+
     public Expression getProducerExpression() {
         if (producerExpression == null) {
             producerExpression = createProducerExpression();
@@ -126,10 +131,7 @@ public class JooqEndpoint extends ScheduledPollEndpoint {
 
     @Override
     public boolean isSingleton() {
-        return false;
+        return true;
     }
 
-    public void setConfiguration(JooqConfiguration configuration) {
-        this.configuration = configuration;
-    }
 }
diff --git a/components/camel-jooq/src/main/java/org/apache/camel/component/jooq/JooqOperation.java b/components/camel-jooq/src/main/java/org/apache/camel/component/jooq/JooqOperation.java
index 92038d4..32a6520 100644
--- a/components/camel-jooq/src/main/java/org/apache/camel/component/jooq/JooqOperation.java
+++ b/components/camel-jooq/src/main/java/org/apache/camel/component/jooq/JooqOperation.java
@@ -16,32 +16,9 @@
  */
 package org.apache.camel.component.jooq;
 
-import java.util.HashMap;
-import java.util.Map;
-
 public enum JooqOperation {
-    EXECUTE("execute"),
-    FETCH("fetch"),
-    NONE("");
-
-    private static final Map<String, JooqOperation> MAP = new HashMap<>();
-    static {
-        for (JooqOperation myEnum : values()) {
-            MAP.put(myEnum.getValue(), myEnum);
-        }
-    }
-
-    private String value;
-
-    JooqOperation(String value) {
-        this.value = value;
-    }
-
-    public static JooqOperation getByValue(String value) {
-        return MAP.get(value);
-    }
+    EXECUTE,
+    FETCH,
+    NONE;
 
-    public String getValue() {
-        return value;
-    }
 }
\ No newline at end of file
diff --git a/components/camel-jooq/src/main/java/org/apache/camel/component/jooq/JooqProducer.java b/components/camel-jooq/src/main/java/org/apache/camel/component/jooq/JooqProducer.java
index af5906e..1ec7938 100644
--- a/components/camel-jooq/src/main/java/org/apache/camel/component/jooq/JooqProducer.java
+++ b/components/camel-jooq/src/main/java/org/apache/camel/component/jooq/JooqProducer.java
@@ -80,7 +80,7 @@ public class JooqProducer extends DefaultProducer {
             context.batchStore(entity).execute();
             break;
         default:
-            throw new IllegalArgumentException("Wrong operation: " + operation.getValue());
+            throw new IllegalArgumentException("Wrong operation: " + operation);
         }
     }
 }
diff --git a/components/camel-jooq/src/test/java/org/apache/camel/component/jooq/JooqComponentTest.java b/components/camel-jooq/src/test/java/org/apache/camel/component/jooq/JooqComponentTest.java
index deac56f..2dfbba4 100644
--- a/components/camel-jooq/src/test/java/org/apache/camel/component/jooq/JooqComponentTest.java
+++ b/components/camel-jooq/src/test/java/org/apache/camel/component/jooq/JooqComponentTest.java
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.component.jooq;
 
+import org.apache.camel.TypeConversionException;
 import org.apache.camel.component.jooq.db.tables.records.BookStoreRecord;
 import org.junit.Test;
 
@@ -37,7 +38,7 @@ public class JooqComponentTest extends BaseJooqTest {
         assertEquals(BookStoreRecord.class, ep3.getConfiguration().getEntityType());
     }
 
-    @Test(expected = IllegalArgumentException.class)
+    @Test(expected = TypeConversionException.class)
     public void testNonDefaultConfig() throws Exception {
         JooqComponent component = (JooqComponent) context().getComponent("jooq");
         component.createEndpoint("jooq://org.apache.camel.component.jooq.db.tables.records.BookStoreRecord/unexpectedOperation");
diff --git a/platforms/spring-boot/components-starter/camel-jooq-starter/src/main/java/org/apache/camel/component/jooq/springboot/JooqComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-jooq-starter/src/main/java/org/apache/camel/component/jooq/springboot/JooqComponentConfiguration.java
index 2807ae2..4394bdd 100644
--- a/platforms/spring-boot/components-starter/camel-jooq-starter/src/main/java/org/apache/camel/component/jooq/springboot/JooqComponentConfiguration.java
+++ b/platforms/spring-boot/components-starter/camel-jooq-starter/src/main/java/org/apache/camel/component/jooq/springboot/JooqComponentConfiguration.java
@@ -71,18 +71,22 @@ public class JooqComponentConfiguration
     public static class JooqConfigurationNestedConfiguration {
         public static final Class CAMEL_NESTED_CLASS = org.apache.camel.component.jooq.JooqConfiguration.class;
         /**
-         * Type of operation to execute on query: execute, fetch, etc.
+         * Type of operation to execute on query
          */
-        private JooqOperation operation;
+        private JooqOperation operation = JooqOperation.NONE;
         private Configuration databaseConfiguration;
         /**
-         * JOOQ entity class.
+         * JOOQ entity class
          */
         private Class entityType;
         /**
-         * Delete entity after it is consumed.
+         * Delete entity after it is consumed
          */
         private Boolean consumeDelete = true;
+        /**
+         * To execute plain SQL query
+         */
+        private String query;
 
         public JooqOperation getOperation() {
             return operation;
@@ -115,5 +119,13 @@ public class JooqComponentConfiguration
         public void setConsumeDelete(Boolean consumeDelete) {
             this.consumeDelete = consumeDelete;
         }
+
+        public String getQuery() {
+            return query;
+        }
+
+        public void setQuery(String query) {
+            this.query = query;
+        }
     }
 }
\ No newline at end of file