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/12/12 12:41:29 UTC

[camel] 01/02: CAMEL-14284: Configuring endpoint should set properties on endpoint and not configuration object - jooq

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 08f28a568a737aeb160ff118865f7bfa3af4eab1
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Dec 12 13:13:37 2019 +0100

    CAMEL-14284: Configuring endpoint should set properties on endpoint and not configuration object - jooq
---
 .../apache/camel/component/jooq/JooqComponent.java | 40 +++++++++++++++++-----
 .../apache/camel/component/jooq/JooqEndpoint.java  | 29 ----------------
 2 files changed, 31 insertions(+), 38 deletions(-)

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 52a3df6..9486e45 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
@@ -18,6 +18,7 @@ package org.apache.camel.component.jooq;
 
 import java.util.Map;
 
+import org.apache.camel.CamelContext;
 import org.apache.camel.Endpoint;
 import org.apache.camel.spi.Metadata;
 import org.apache.camel.spi.annotations.Component;
@@ -29,20 +30,13 @@ public class JooqComponent extends DefaultComponent {
     @Metadata(description = "Component configuration (database connection, database entity type, etc.)")
     private JooqConfiguration configuration;
 
-    public JooqComponent() {
-    }
-
-    @Override
-    protected void doStart() throws Exception {
-        super.doStart();
-    }
-
     @Override
     protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
         JooqConfiguration conf = configuration != null ? configuration.copy() : new JooqConfiguration();
-        setProperties(conf, parameters);
 
         JooqEndpoint endpoint = new JooqEndpoint(uri, remaining, this, conf);
+        setProperties(endpoint, parameters);
+        initConfiguration(getCamelContext(), conf, remaining);
         return endpoint;
     }
 
@@ -53,4 +47,32 @@ public class JooqComponent extends DefaultComponent {
     public void setConfiguration(JooqConfiguration jooqConfiguration) {
         this.configuration = jooqConfiguration;
     }
+
+    private static void initConfiguration(CamelContext camelContext, JooqConfiguration configuration, String remaining) {
+        if (remaining == null) {
+            return;
+        }
+
+        String[] parts = remaining.split("/");
+        if (parts.length == 0 || parts.length > 2) {
+            throw new IllegalArgumentException("Unexpected URI format. Expected ... , found '" + remaining + "'");
+        }
+
+        String className = parts[0];
+        Class<?> type = camelContext.getClassResolver().resolveClass(className);
+        if (type != null) {
+            configuration.setEntityType(type);
+        }
+
+        if (parts.length > 1) {
+            String op = parts[1];
+            JooqOperation operation = camelContext.getTypeConverter().convertTo(JooqOperation.class, op);
+            if (operation != null) {
+                configuration.setOperation(operation);
+            } else {
+                throw new IllegalArgumentException("Wrong operation: " + op);
+            }
+        }
+    }
+
 }
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 1cfe595..95b2451 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
@@ -40,35 +40,6 @@ public class JooqEndpoint extends ScheduledPollEndpoint {
     public JooqEndpoint(String uri, String remaining, JooqComponent component, JooqConfiguration configuration) {
         super(uri, component);
         this.configuration = configuration;
-
-        initConfiguration(remaining);
-    }
-
-    private void initConfiguration(String remaining) {
-        if (remaining == null) {
-            return;
-        }
-
-        String[] parts = remaining.split("/");
-        if (parts.length == 0 || parts.length > 2) {
-            throw new IllegalArgumentException("Unexpected URI format. Expected ... , found '" + remaining + "'");
-        }
-
-        String className = parts[0];
-        Class<?> type = getCamelContext().getClassResolver().resolveClass(className);
-        if (type != null) {
-            configuration.setEntityType(type);
-        }
-
-        if (parts.length > 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: " + op);
-            }
-        }
     }
 
     @Override