Repository: camel Updated Branches: refs/heads/master 04b731819 -> 14d377091
Component docs Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/9a0d90d1 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/9a0d90d1 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/9a0d90d1 Branch: refs/heads/master Commit: 9a0d90d1065233f10b149d0583da69f24e2785ab Parents: 04b7318 Author: Claus Ibsen <[email protected]> Authored: Fri May 29 14:48:17 2015 +0200 Committer: Claus Ibsen <[email protected]> Committed: Fri May 29 14:48:30 2015 +0200 ---------------------------------------------------------------------- .../camel/component/jdbc/JdbcComponent.java | 12 ++++++++---- .../camel/component/jdbc/JdbcEndpoint.java | 20 +++++++++++++++++--- 2 files changed, 25 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/9a0d90d1/components/camel-jdbc/src/main/java/org/apache/camel/component/jdbc/JdbcComponent.java ---------------------------------------------------------------------- diff --git a/components/camel-jdbc/src/main/java/org/apache/camel/component/jdbc/JdbcComponent.java b/components/camel-jdbc/src/main/java/org/apache/camel/component/jdbc/JdbcComponent.java index 9e6d990..a43616c 100755 --- a/components/camel-jdbc/src/main/java/org/apache/camel/component/jdbc/JdbcComponent.java +++ b/components/camel-jdbc/src/main/java/org/apache/camel/component/jdbc/JdbcComponent.java @@ -29,7 +29,7 @@ import org.apache.camel.util.IntrospectionSupport; * @version */ public class JdbcComponent extends UriEndpointComponent { - private DataSource ds; + private DataSource dataSource; public JdbcComponent() { super(JdbcEndpoint.class); @@ -42,17 +42,21 @@ public class JdbcComponent extends UriEndpointComponent { @Override protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception { DataSource dataSource; + String dataSourceRef; - if (ds != null) { + if (this.dataSource != null) { // prefer to use datasource set by setter - dataSource = ds; + dataSource = this.dataSource; + dataSourceRef = "component"; } else { dataSource = CamelContextHelper.mandatoryLookup(getCamelContext(), remaining, DataSource.class); + dataSourceRef = remaining; } Map<String, Object> params = IntrospectionSupport.extractProperties(parameters, "statement."); JdbcEndpoint jdbc = new JdbcEndpoint(uri, this, dataSource); + jdbc.setDataSourceName(dataSourceRef); jdbc.setParameters(params); setProperties(jdbc, parameters); @@ -63,6 +67,6 @@ public class JdbcComponent extends UriEndpointComponent { * To use the {@link DataSource} instance instead of looking up the data source by name from the registry. */ public void setDataSource(DataSource dataSource) { - this.ds = dataSource; + this.dataSource = dataSource; } } http://git-wip-us.apache.org/repos/asf/camel/blob/9a0d90d1/components/camel-jdbc/src/main/java/org/apache/camel/component/jdbc/JdbcEndpoint.java ---------------------------------------------------------------------- diff --git a/components/camel-jdbc/src/main/java/org/apache/camel/component/jdbc/JdbcEndpoint.java b/components/camel-jdbc/src/main/java/org/apache/camel/component/jdbc/JdbcEndpoint.java index 84fd696..d1f037e 100755 --- a/components/camel-jdbc/src/main/java/org/apache/camel/component/jdbc/JdbcEndpoint.java +++ b/components/camel-jdbc/src/main/java/org/apache/camel/component/jdbc/JdbcEndpoint.java @@ -32,10 +32,13 @@ import org.apache.camel.spi.UriPath; /** * @version */ -@UriEndpoint(scheme = "jdbc", title = "JDBC", syntax = "jdbc:dataSource", producerOnly = true, label = "database,sql") +@UriEndpoint(scheme = "jdbc", title = "JDBC", syntax = "jdbc:dataSourceName", producerOnly = true, label = "database,sql") public class JdbcEndpoint extends DefaultEndpoint { - @UriPath @Metadata(required = "true") + private DataSource dataSource; + + @UriPath @Metadata(required = "true") + private String dataSourceName; @UriParam private int readSize; @UriParam @@ -78,6 +81,17 @@ public class JdbcEndpoint extends DefaultEndpoint { return new JdbcProducer(this, dataSource, readSize, parameters); } + public String getDataSourceName() { + return dataSourceName; + } + + /** + * Name of DataSource to lookup in the Registry. + */ + public void setDataSourceName(String dataSourceName) { + this.dataSourceName = dataSourceName; + } + public int getReadSize() { return readSize; } @@ -229,6 +243,6 @@ public class JdbcEndpoint extends DefaultEndpoint { @Override protected String createEndpointUri() { - return "jdbc"; + return dataSourceName != null ? "jdbc:" + dataSourceName : "jdbc"; } }
