CAMEL-8226 Deprecated feature dataSourceRef not working correctly
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/ecf42a1d Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/ecf42a1d Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/ecf42a1d Branch: refs/heads/camel-2.13.x Commit: ecf42a1d6778c590d05e38b559c6497a22bae1b5 Parents: c95fe97 Author: Claus Ibsen <davscl...@apache.org> Authored: Tue Feb 10 09:18:47 2015 +0100 Committer: Claus Ibsen <davscl...@apache.org> Committed: Tue Feb 10 09:19:35 2015 +0100 ---------------------------------------------------------------------- .../camel/component/sql/SqlComponent.java | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/ecf42a1d/components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlComponent.java ---------------------------------------------------------------------- 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 a4eb816..d334b06 100755 --- 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 @@ -43,21 +43,23 @@ public class SqlComponent extends UriEndpointComponent { @Override protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception { + // endpoint options overrule component configured datasource DataSource ds = resolveAndRemoveReferenceParameter(parameters, "dataSource", DataSource.class); - if (ds != null) { - dataSource = ds; - } - - //TODO cmueller: remove the 'dataSourceRef' lookup in Camel 3.0 String dataSourceRef = getAndRemoveParameter(parameters, "dataSourceRef", String.class); - if (dataSource == null && dataSourceRef != null) { - dataSource = CamelContextHelper.mandatoryLookup(getCamelContext(), dataSourceRef, DataSource.class); - } + if (ds == null && dataSourceRef != null) { + ds = CamelContextHelper.mandatoryLookup(getCamelContext(), dataSourceRef, DataSource.class); + } + if (ds == null) { + // fallback and use component + ds = dataSource; + } + if (ds == null) { + throw new IllegalArgumentException("DataSource must be configured"); } String parameterPlaceholderSubstitute = getAndRemoveParameter(parameters, "placeholder", String.class, "#"); - JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); + JdbcTemplate jdbcTemplate = new JdbcTemplate(ds); IntrospectionSupport.setProperties(jdbcTemplate, parameters, "template."); String query = remaining.replaceAll(parameterPlaceholderSubstitute, "?");