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 2016/02/19 14:03:00 UTC

[1/4] camel git commit: Fixed typo

Repository: camel
Updated Branches:
  refs/heads/master fe635234b -> 38c1f6f7f


Fixed typo


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/b7f7acb0
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b7f7acb0
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b7f7acb0

Branch: refs/heads/master
Commit: b7f7acb099e96f630c21256cd68ca5992c3cae8b
Parents: fe63523
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Feb 19 12:00:05 2016 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Feb 19 12:00:05 2016 +0100

----------------------------------------------------------------------
 .../camel/component/sql/stored/template/grammar/sspt.jj   | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/b7f7acb0/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/grammar/sspt.jj
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/grammar/sspt.jj b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/grammar/sspt.jj
index ab483b5..0b3a295 100644
--- a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/grammar/sspt.jj
+++ b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/grammar/sspt.jj
@@ -30,26 +30,26 @@ package org.apache.camel.component.sql.stored.template.generated;
 import org.apache.camel.component.sql.stored.template.ast.*;
 
 public class SSPTParser {
-   int paramaterNameCounter = 0;
+   int parameterNameCounter = 0;
 
    String createNextParameterName() {
-      return "_"+(paramaterNameCounter++);
+      return "_"+(parameterNameCounter++);
    }
 }
 
 PARSER_END(SSPTParser)
 
 public Template parse() :
-{   Token procudureName;
+{   Token procedureName;
     Template template = new Template();
     Object parameter = null;
 }
 {
-  (procudureName = <IDENTIFIER> "(" ( (parameter = Parameter() { template.addParameter(parameter);}) (","
+  (procedureName = <IDENTIFIER> "(" ( (parameter = Parameter() { template.addParameter(parameter);}) (","
   parameter
   = Parameter(){template.addParameter(parameter);})*)? ")" <EOF>)
   {
-   template.setProcedureName(procudureName.toString());
+   template.setProcedureName(procedureName.toString());
    return template;
   }
 }


[2/4] camel git commit: CAMEL-9461: camel-sql - Allow to load sql from resource. Also renamed some typo errors.

Posted by da...@apache.org.
CAMEL-9461: camel-sql - Allow to load sql from resource. Also renamed some typo errors.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/8b3715d3
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/8b3715d3
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/8b3715d3

Branch: refs/heads/master
Commit: 8b3715d3d776631a3450e1c7704442b2504bf2ac
Parents: b7f7acb
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Feb 19 12:26:57 2016 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Feb 19 12:27:38 2016 +0100

----------------------------------------------------------------------
 .../camel/component/sql/DefaultSqlEndpoint.java | 15 +++++++
 .../sql/DefaultSqlPrepareStatementStrategy.java |  7 +--
 .../camel/component/sql/SqlComponent.java       |  6 ++-
 .../apache/camel/component/sql/SqlConsumer.java | 11 ++++-
 .../apache/camel/component/sql/SqlEndpoint.java |  5 ++-
 .../apache/camel/component/sql/SqlHelper.java   | 45 ++++++++++++++++++++
 .../apache/camel/component/sql/SqlProducer.java | 11 ++++-
 .../sql/stored/CallableStatementWrapper.java    |  2 +-
 .../stored/CallableStatementWrapperFactory.java |  2 +-
 .../component/sql/stored/SqlStoredProducer.java | 26 ++++++++---
 .../component/sql/stored/StamentWrapper.java    | 41 ------------------
 .../component/sql/stored/StatementWrapper.java  | 40 +++++++++++++++++
 .../sql/stored/WrapperExecuteCallback.java      |  2 +-
 .../stored/template/generated/SSPTParser.java   | 10 ++---
 .../sql/SqlConsumerFromClasspathTest.java       | 38 +++++++++++++++++
 .../camel/component/sql/SqlConsumerTest.java    |  2 +-
 .../sql/SqlProducerWhereIssueClasspathTest.java | 38 +++++++++++++++++
 .../sql/SqlProducerWhereIssueTest.java          |  2 +-
 .../stored/CallableStatementWrapperTest.java    | 12 +++---
 .../sql/stored/ProducerClasspathTest.java       | 36 ++++++++++++++++
 .../component/sql/stored/ProducerTest.java      |  2 +-
 .../src/test/resources/sql/projectsRowCount.sql |  5 +++
 .../src/test/resources/sql/selectProjects.sql   |  4 ++
 .../src/test/resources/sql/selectStored.sql     |  1 +
 24 files changed, 291 insertions(+), 72 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/8b3715d3/components/camel-sql/src/main/java/org/apache/camel/component/sql/DefaultSqlEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/main/java/org/apache/camel/component/sql/DefaultSqlEndpoint.java b/components/camel-sql/src/main/java/org/apache/camel/component/sql/DefaultSqlEndpoint.java
index 17fcb68..8a13a74 100644
--- a/components/camel-sql/src/main/java/org/apache/camel/component/sql/DefaultSqlEndpoint.java
+++ b/components/camel-sql/src/main/java/org/apache/camel/component/sql/DefaultSqlEndpoint.java
@@ -110,6 +110,8 @@ public abstract class DefaultSqlEndpoint extends DefaultPollingEndpoint {
     @UriParam(label = "advanced", defaultValue = "#", description = "Specifies a character that will be replaced to ? in SQL query."
             + " Notice, that it is simple String.replaceAll() operation and no SQL parsing is involved (quoted strings will also change).")
     private String placeholder = "#";
+    @UriParam(label = "advanced", defaultValue = "true", description = "Sets whether to use placeholder and replace all placeholder characters with ? sign in the SQL queries.")
+    private boolean usePlaceholder = true;
     @UriParam(label = "advanced", prefix = "template.", multiValue = true,
             description = "Configures the Spring JdbcTemplate with the key/values from the Map")
     private Map<String, Object> templateOptions;
@@ -418,6 +420,19 @@ public abstract class DefaultSqlEndpoint extends DefaultPollingEndpoint {
         this.placeholder = placeholder;
     }
 
+    public boolean isUsePlaceholder() {
+        return usePlaceholder;
+    }
+
+    /**
+     * Sets whether to use placeholder and replace all placeholder characters with ? sign in the SQL queries.
+     * <p/>
+     * This option is default <tt>true</tt>
+     */
+    public void setUsePlaceholder(boolean usePlaceholder) {
+        this.usePlaceholder = usePlaceholder;
+    }
+
     public Map<String, Object> getTemplateOptions() {
         return templateOptions;
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/8b3715d3/components/camel-sql/src/main/java/org/apache/camel/component/sql/DefaultSqlPrepareStatementStrategy.java
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/main/java/org/apache/camel/component/sql/DefaultSqlPrepareStatementStrategy.java b/components/camel-sql/src/main/java/org/apache/camel/component/sql/DefaultSqlPrepareStatementStrategy.java
index b46714e..bed55d1 100644
--- a/components/camel-sql/src/main/java/org/apache/camel/component/sql/DefaultSqlPrepareStatementStrategy.java
+++ b/components/camel-sql/src/main/java/org/apache/camel/component/sql/DefaultSqlPrepareStatementStrategy.java
@@ -41,6 +41,8 @@ import org.springframework.jdbc.core.ArgumentPreparedStatementSetter;
 public class DefaultSqlPrepareStatementStrategy implements SqlPrepareStatementStrategy {
 
     private static final Logger LOG = LoggerFactory.getLogger(DefaultSqlPrepareStatementStrategy.class);
+    private static final Pattern REPLACE_PATTERN = Pattern.compile("\\:\\?\\w+|\\:\\?\\$\\{[^\\}]+\\}", Pattern.MULTILINE);
+    private static final Pattern NAME_PATTERN = Pattern.compile("\\:\\?(\\w+|\\$\\{[^\\}]+\\})", Pattern.MULTILINE);
     private final char separator;
 
     public DefaultSqlPrepareStatementStrategy() {
@@ -56,7 +58,7 @@ public class DefaultSqlPrepareStatementStrategy implements SqlPrepareStatementSt
         String answer;
         if (allowNamedParameters && hasNamedParameters(query)) {
             // replace all :?word and :?${foo} with just ?
-            answer = query.replaceAll("\\:\\?\\w+|\\:\\?\\$\\{[^\\}]+\\}", "\\?");
+            answer = REPLACE_PATTERN.matcher(query).replaceAll("\\?");
         } else {
             answer = query;
         }
@@ -125,11 +127,10 @@ public class DefaultSqlPrepareStatementStrategy implements SqlPrepareStatementSt
 
     private static final class NamedQueryParser {
 
-        private static final Pattern PATTERN = Pattern.compile("\\:\\?(\\w+|\\$\\{[^\\}]+\\})");
         private final Matcher matcher;
 
         private NamedQueryParser(String query) {
-            this.matcher = PATTERN.matcher(query);
+            this.matcher = NAME_PATTERN.matcher(query);
         }
 
         public String next() {

http://git-wip-us.apache.org/repos/asf/camel/blob/8b3715d3/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 460b4f3..385d087 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
@@ -80,7 +80,10 @@ public class SqlComponent extends UriEndpointComponent {
         Map<String, Object> templateOptions = IntrospectionSupport.extractProperties(parameters, "template.");
         IntrospectionSupport.setProperties(jdbcTemplate, templateOptions);
 
-        String query = remaining.replaceAll(parameterPlaceholderSubstitute, "?");
+        String query = remaining;
+        if (usePlaceholder) {
+            query = query.replaceAll(parameterPlaceholderSubstitute, "?");
+        }
 
         String onConsume = getAndRemoveParameter(parameters, "consumer.onConsume", String.class);
         if (onConsume == null) {
@@ -106,6 +109,7 @@ public class SqlComponent extends UriEndpointComponent {
 
         SqlEndpoint endpoint = new SqlEndpoint(uri, this, jdbcTemplate, query);
         endpoint.setPlaceholder(parameterPlaceholderSubstitute);
+        endpoint.setUsePlaceholder(isUsePlaceholder());
         endpoint.setOnConsume(onConsume);
         endpoint.setOnConsumeFailed(onConsumeFailed);
         endpoint.setOnConsumeBatchComplete(onConsumeBatchComplete);

http://git-wip-us.apache.org/repos/asf/camel/blob/8b3715d3/components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlConsumer.java b/components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlConsumer.java
index 40e0eb9..a9bc8ea 100644
--- a/components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlConsumer.java
+++ b/components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlConsumer.java
@@ -42,6 +42,7 @@ import static org.springframework.jdbc.support.JdbcUtils.closeResultSet;
 public class SqlConsumer extends ScheduledBatchPollingConsumer {
 
     private final String query;
+    private String resolvedQuery;
     private final JdbcTemplate jdbcTemplate;
     private final NamedParameterJdbcTemplate namedJdbcTemplate;
     private final SqlParameterSource parameterSource;
@@ -92,12 +93,20 @@ public class SqlConsumer extends ScheduledBatchPollingConsumer {
     }
 
     @Override
+    protected void doStart() throws Exception {
+        super.doStart();
+
+        String placeholder = getEndpoint().isUsePlaceholder() ? getEndpoint().getPlaceholder() : null;
+        resolvedQuery = SqlHelper.resolveQuery(getEndpoint().getCamelContext(), query, placeholder);
+    }
+
+    @Override
     protected int poll() throws Exception {
         // must reset for each poll
         shutdownRunningTask = null;
         pendingExchanges = 0;
 
-        final String preparedQuery = sqlPrepareStatementStrategy.prepareQuery(query, getEndpoint().isAllowNamedParameters());
+        final String preparedQuery = sqlPrepareStatementStrategy.prepareQuery(resolvedQuery, getEndpoint().isAllowNamedParameters());
         final PreparedStatementCallback<Integer> callback = new PreparedStatementCallback<Integer>() {
             @Override
             public Integer doInPreparedStatement(PreparedStatement preparedStatement) throws SQLException, DataAccessException {

http://git-wip-us.apache.org/repos/asf/camel/blob/8b3715d3/components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlEndpoint.java b/components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlEndpoint.java
index c521339..d9e6751 100644
--- a/components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlEndpoint.java
+++ b/components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlEndpoint.java
@@ -32,7 +32,8 @@ import org.springframework.jdbc.core.JdbcTemplate;
 @UriEndpoint(scheme = "sql", title = "SQL", syntax = "sql:query", consumerClass = SqlConsumer.class, label = "database,sql")
 public class SqlEndpoint extends DefaultSqlEndpoint {
 
-    @UriPath(description = "Sets the SQL query to perform") @Metadata(required = "true")
+    @UriPath(description = "Sets the SQL query to perform. You can externalize the query by using file: or classpath: as prefix and specify the location of the file.")
+    @Metadata(required = "true")
     private String query;
 
     public SqlEndpoint() {
@@ -78,7 +79,7 @@ public class SqlEndpoint extends DefaultSqlEndpoint {
     }
 
     /**
-     * Sets the SQL query to perform
+     * Sets the SQL query to perform. You can externalize the query by using file: or classpath: as prefix and specify the location of the file.
      */
     public void setQuery(String query) {
         this.query = query;

http://git-wip-us.apache.org/repos/asf/camel/blob/8b3715d3/components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlHelper.java
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlHelper.java b/components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlHelper.java
new file mode 100644
index 0000000..f935b37
--- /dev/null
+++ b/components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlHelper.java
@@ -0,0 +1,45 @@
+/**
+ * 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.sql;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.NoTypeConversionAvailableException;
+import org.apache.camel.util.ResourceHelper;
+
+public final class SqlHelper {
+
+    private SqlHelper() {
+    }
+
+    /**
+     * Resolve the query by loading the query from the classpath or file resource if needed.
+     */
+    public static String resolveQuery(CamelContext camelContext, String query, String placeholder) throws NoTypeConversionAvailableException, IOException {
+        String answer = query;
+        if (ResourceHelper.hasScheme(query)) {
+            InputStream is = ResourceHelper.resolveMandatoryResourceAsInputStream(camelContext, query);
+            answer = camelContext.getTypeConverter().mandatoryConvertTo(String.class, is);
+            if (placeholder != null) {
+                answer = answer.replaceAll(placeholder, "?");
+            }
+        }
+        return answer;
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/8b3715d3/components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlProducer.java b/components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlProducer.java
index 483bd72..3d70acd 100644
--- a/components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlProducer.java
+++ b/components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlProducer.java
@@ -36,6 +36,7 @@ import static org.springframework.jdbc.support.JdbcUtils.closeResultSet;
 
 public class SqlProducer extends DefaultProducer {
     private final String query;
+    private String resolvedQuery;
     private final JdbcTemplate jdbcTemplate;
     private final boolean batch;
     private final boolean alwaysPopulateStatement;
@@ -59,13 +60,21 @@ public class SqlProducer extends DefaultProducer {
         return (SqlEndpoint) super.getEndpoint();
     }
 
+    @Override
+    protected void doStart() throws Exception {
+        super.doStart();
+
+        String placeholder = getEndpoint().isUsePlaceholder() ? getEndpoint().getPlaceholder() : null;
+        resolvedQuery = SqlHelper.resolveQuery(getEndpoint().getCamelContext(), query, placeholder);
+    }
+
     public void process(final Exchange exchange) throws Exception {
         final String sql;
         if (useMessageBodyForSql) {
             sql = exchange.getIn().getBody(String.class);
         } else {
             String queryHeader = exchange.getIn().getHeader(SqlConstants.SQL_QUERY, String.class);
-            sql = queryHeader != null ? queryHeader : query;
+            sql = queryHeader != null ? queryHeader : resolvedQuery;
         }
         final String preparedQuery = sqlPrepareStatementStrategy.prepareQuery(sql, getEndpoint().isAllowNamedParameters());
 

http://git-wip-us.apache.org/repos/asf/camel/blob/8b3715d3/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/CallableStatementWrapper.java
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/CallableStatementWrapper.java b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/CallableStatementWrapper.java
index b46e1a5..2693b0a 100644
--- a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/CallableStatementWrapper.java
+++ b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/CallableStatementWrapper.java
@@ -31,7 +31,7 @@ import org.springframework.dao.DataAccessException;
 import org.springframework.jdbc.core.CallableStatementCallback;
 import org.springframework.jdbc.core.CallableStatementCreator;
 
-public class CallableStatementWrapper implements StamentWrapper {
+public class CallableStatementWrapper implements StatementWrapper {
 
     final CallableStatementWrapperFactory factory;
 

http://git-wip-us.apache.org/repos/asf/camel/blob/8b3715d3/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/CallableStatementWrapperFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/CallableStatementWrapperFactory.java b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/CallableStatementWrapperFactory.java
index 503fdb3..7b19da9 100644
--- a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/CallableStatementWrapperFactory.java
+++ b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/CallableStatementWrapperFactory.java
@@ -46,7 +46,7 @@ public class CallableStatementWrapperFactory extends ServiceSupport {
         this.templateParser = templateParser;
     }
 
-    public StamentWrapper create(String sql) throws SQLException {
+    public StatementWrapper create(String sql) throws SQLException {
         return new CallableStatementWrapper(sql, this);
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/8b3715d3/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/SqlStoredProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/SqlStoredProducer.java b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/SqlStoredProducer.java
index eff61b1..8215b4b 100644
--- a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/SqlStoredProducer.java
+++ b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/SqlStoredProducer.java
@@ -20,10 +20,13 @@ import java.sql.SQLException;
 import java.util.Iterator;
 
 import org.apache.camel.Exchange;
+import org.apache.camel.component.sql.SqlHelper;
 import org.apache.camel.impl.DefaultProducer;
 import org.springframework.dao.DataAccessException;
 
 public class SqlStoredProducer extends DefaultProducer {
+
+    private String resolvedTemplate;
     private CallableStatementWrapperFactory callableStatementWrapperFactory;
 
     public SqlStoredProducer(SqlStoredEndpoint endpoint) {
@@ -36,10 +39,10 @@ public class SqlStoredProducer extends DefaultProducer {
     }
 
     public void process(final Exchange exchange) throws Exception {
-        StamentWrapper stamentWrapper = createStatement(exchange);
-        stamentWrapper.call(new WrapperExecuteCallback() {
+        StatementWrapper statementWrapper = createStatement(exchange);
+        statementWrapper.call(new WrapperExecuteCallback() {
             @Override
-            public void execute(StamentWrapper ps) throws SQLException, DataAccessException {
+            public void execute(StatementWrapper ps) throws SQLException, DataAccessException {
                 // transfer incoming message body data to prepared statement parameters, if necessary
                 if (getEndpoint().isBatch()) {
                     Iterator<?> iterator;
@@ -100,17 +103,28 @@ public class SqlStoredProducer extends DefaultProducer {
         });
     }
 
-    private StamentWrapper createStatement(Exchange exchange) throws SQLException {
-        final String sql;
+    private StatementWrapper createStatement(Exchange exchange) throws SQLException {
+        String sql;
         if (getEndpoint().isUseMessageBodyForTemplate()) {
             sql = exchange.getIn().getBody(String.class);
         } else {
             String templateHeader = exchange.getIn().getHeader(SqlStoredConstants.SQL_STORED_TEMPLATE, String.class);
-            sql = templateHeader != null ? templateHeader : getEndpoint().getTemplate();
+            sql = templateHeader != null ? templateHeader : resolvedTemplate;
+        }
+
+        try {
+            sql = SqlHelper.resolveQuery(getEndpoint().getCamelContext(), sql, null);
+        } catch (Exception e) {
+            throw new SQLException("Error loading template resource: " + sql, e);
         }
 
         return getEndpoint().getWrapperFactory().create(sql);
     }
 
+    @Override
+    protected void doStart() throws Exception {
+        super.doStart();
 
+        resolvedTemplate = SqlHelper.resolveQuery(getEndpoint().getCamelContext(), getEndpoint().getTemplate(), null);
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/8b3715d3/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/StamentWrapper.java
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/StamentWrapper.java b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/StamentWrapper.java
deleted file mode 100644
index bcf842d..0000000
--- a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/StamentWrapper.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/**
- * 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.sql.stored;
-
-import java.sql.SQLException;
-
-import org.apache.camel.Exchange;
-
-/**
- * Wrapper that simplifies operations on  {@link java.sql.CallableStatement}
- * in {@link SqlStoredProducer}.
- * Wrappers are statefull objects and must not be reused.
- */
-public interface StamentWrapper {
-
-    void call(WrapperExecuteCallback cb) throws Exception;
-
-    int[] executeBatch() throws SQLException;
-
-    Integer getUpdateCount() throws SQLException;
-
-    Object executeStatement() throws SQLException;
-
-    void populateStatement(Object value, Exchange exchange) throws SQLException;
-
-    void addBatch(Object value, Exchange exchange);
-}

http://git-wip-us.apache.org/repos/asf/camel/blob/8b3715d3/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/StatementWrapper.java
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/StatementWrapper.java b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/StatementWrapper.java
new file mode 100644
index 0000000..931119d
--- /dev/null
+++ b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/StatementWrapper.java
@@ -0,0 +1,40 @@
+/**
+ * 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.sql.stored;
+
+import java.sql.SQLException;
+
+import org.apache.camel.Exchange;
+
+/**
+ * Wrapper that simplifies operations on  {@link java.sql.CallableStatement} in {@link SqlStoredProducer}.
+ * Wrappers are stateful objects and must not be reused.
+ */
+public interface StatementWrapper {
+
+    void call(WrapperExecuteCallback cb) throws Exception;
+
+    int[] executeBatch() throws SQLException;
+
+    Integer getUpdateCount() throws SQLException;
+
+    Object executeStatement() throws SQLException;
+
+    void populateStatement(Object value, Exchange exchange) throws SQLException;
+
+    void addBatch(Object value, Exchange exchange);
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/8b3715d3/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/WrapperExecuteCallback.java
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/WrapperExecuteCallback.java b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/WrapperExecuteCallback.java
index fedd926..ee3d354 100644
--- a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/WrapperExecuteCallback.java
+++ b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/WrapperExecuteCallback.java
@@ -22,5 +22,5 @@ import org.springframework.dao.DataAccessException;
 
 public interface WrapperExecuteCallback {
 
-    void execute(StamentWrapper stamentWrapper) throws SQLException, DataAccessException;
+    void execute(StatementWrapper statementWrapper) throws SQLException, DataAccessException;
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/8b3715d3/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/generated/SSPTParser.java
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/generated/SSPTParser.java b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/generated/SSPTParser.java
index d55b900..858b203 100644
--- a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/generated/SSPTParser.java
+++ b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/generated/SSPTParser.java
@@ -4,17 +4,17 @@ package org.apache.camel.component.sql.stored.template.generated;
 import org.apache.camel.component.sql.stored.template.ast.*;
 
 public class SSPTParser implements SSPTParserConstants {
-   int paramaterNameCounter = 0;
+   int parameterNameCounter = 0;
 
    String createNextParameterName() {
-      return "_"+(paramaterNameCounter++);
+      return "_"+(parameterNameCounter++);
    }
 
   final public Template parse() throws ParseException {
-    Token procudureName;
+    Token procedureName;
     Template template = new Template();
     Object parameter = null;
-    procudureName = jj_consume_token(IDENTIFIER);
+    procedureName = jj_consume_token(IDENTIFIER);
     jj_consume_token(1);
     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
     case 5:
@@ -43,7 +43,7 @@ public class SSPTParser implements SSPTParserConstants {
     }
     jj_consume_token(3);
     jj_consume_token(0);
-   template.setProcedureName(procudureName.toString());
+   template.setProcedureName(procedureName.toString());
    {if (true) return template;}
     throw new Error("Missing return statement in function");
   }

http://git-wip-us.apache.org/repos/asf/camel/blob/8b3715d3/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlConsumerFromClasspathTest.java
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlConsumerFromClasspathTest.java b/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlConsumerFromClasspathTest.java
new file mode 100644
index 0000000..81a675c
--- /dev/null
+++ b/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlConsumerFromClasspathTest.java
@@ -0,0 +1,38 @@
+/**
+ * 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.sql;
+
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ *
+ */
+public class SqlConsumerFromClasspathTest extends SqlConsumerTest {
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                getContext().getComponent("sql", SqlComponent.class).setDataSource(db);
+
+                from("sql:classpath:sql/selectProjects.sql")
+                    .to("mock:result");
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/8b3715d3/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlConsumerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlConsumerTest.java b/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlConsumerTest.java
index bcb3c53..69e23ec 100644
--- a/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlConsumerTest.java
+++ b/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlConsumerTest.java
@@ -35,7 +35,7 @@ import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
  */
 public class SqlConsumerTest extends CamelTestSupport {
 
-    private EmbeddedDatabase db;
+    EmbeddedDatabase db;
 
     @Before
     public void setUp() throws Exception {

http://git-wip-us.apache.org/repos/asf/camel/blob/8b3715d3/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlProducerWhereIssueClasspathTest.java
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlProducerWhereIssueClasspathTest.java b/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlProducerWhereIssueClasspathTest.java
new file mode 100644
index 0000000..6ac764e
--- /dev/null
+++ b/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlProducerWhereIssueClasspathTest.java
@@ -0,0 +1,38 @@
+/**
+ * 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.sql;
+
+import org.apache.camel.builder.RouteBuilder;
+
+public class SqlProducerWhereIssueClasspathTest extends SqlProducerWhereIssueTest {
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                // required for the sql component
+                getContext().getComponent("sql", SqlComponent.class).setDataSource(db);
+
+                from("direct:query")
+                    .to("sql:classpath:sql/projectsRowCount.sql")
+                    .to("log:query")
+                    .to("mock:query");
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/8b3715d3/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlProducerWhereIssueTest.java
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlProducerWhereIssueTest.java b/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlProducerWhereIssueTest.java
index bd41bb3..1302c94 100644
--- a/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlProducerWhereIssueTest.java
+++ b/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlProducerWhereIssueTest.java
@@ -31,7 +31,7 @@ import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
 
 public class SqlProducerWhereIssueTest extends CamelTestSupport {
 
-    private EmbeddedDatabase db;
+    EmbeddedDatabase db;
 
     @Before
     public void setUp() throws Exception {

http://git-wip-us.apache.org/repos/asf/camel/blob/8b3715d3/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/CallableStatementWrapperTest.java
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/CallableStatementWrapperTest.java b/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/CallableStatementWrapperTest.java
index 33a95d5..09ccbe9 100644
--- a/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/CallableStatementWrapperTest.java
+++ b/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/CallableStatementWrapperTest.java
@@ -62,10 +62,10 @@ public class CallableStatementWrapperTest extends CamelTestSupport {
 
         wrapper.call(new WrapperExecuteCallback() {
             @Override
-            public void execute(StamentWrapper stamentWrapper) throws SQLException, DataAccessException {
-                stamentWrapper.populateStatement(null, exchange);
+            public void execute(StatementWrapper statementWrapper) throws SQLException, DataAccessException {
+                statementWrapper.populateStatement(null, exchange);
 
-                Map resultOfQuery = (Map) stamentWrapper.executeStatement();
+                Map resultOfQuery = (Map) statementWrapper.executeStatement();
                 Assert.assertEquals(Integer.valueOf(-1), ((Map) resultOfQuery).get("resultofsub"));
             }
         });
@@ -78,10 +78,10 @@ public class CallableStatementWrapperTest extends CamelTestSupport {
 
         wrapper.call(new WrapperExecuteCallback() {
             @Override
-            public void execute(StamentWrapper stamentWrapper) throws SQLException, DataAccessException {
+            public void execute(StatementWrapper statementWrapper) throws SQLException, DataAccessException {
 
-                stamentWrapper.populateStatement(null, null);
-                Map result = (Map) stamentWrapper.executeStatement();
+                statementWrapper.populateStatement(null, null);
+                Map result = (Map) statementWrapper.executeStatement();
                 //no output parameter in stored procedure NILADIC()
                 //Spring sets #update-count-1
                 assertNotNull(result.get("#update-count-1"));

http://git-wip-us.apache.org/repos/asf/camel/blob/8b3715d3/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/ProducerClasspathTest.java
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/ProducerClasspathTest.java b/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/ProducerClasspathTest.java
new file mode 100644
index 0000000..b374437
--- /dev/null
+++ b/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/ProducerClasspathTest.java
@@ -0,0 +1,36 @@
+/**
+ * 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.sql.stored;
+
+import org.apache.camel.builder.RouteBuilder;
+
+public class ProducerClasspathTest extends ProducerTest {
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                // required for the sql component
+                getContext().getComponent("sql-stored", SqlStoredComponent.class).setDataSource(db);
+
+                from("direct:query").to("sql-stored:classpath:sql/selectStored.sql").to("mock:query");
+            }
+        };
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/8b3715d3/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/ProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/ProducerTest.java b/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/ProducerTest.java
index 1e8bc35..8eb704b 100644
--- a/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/ProducerTest.java
+++ b/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/ProducerTest.java
@@ -32,7 +32,7 @@ import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
 
 public class ProducerTest extends CamelTestSupport {
 
-    private EmbeddedDatabase db;
+    EmbeddedDatabase db;
 
     @Before
     public void setUp() throws Exception {

http://git-wip-us.apache.org/repos/asf/camel/blob/8b3715d3/components/camel-sql/src/test/resources/sql/projectsRowCount.sql
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/test/resources/sql/projectsRowCount.sql b/components/camel-sql/src/test/resources/sql/projectsRowCount.sql
new file mode 100644
index 0000000..da3f4ac
--- /dev/null
+++ b/components/camel-sql/src/test/resources/sql/projectsRowCount.sql
@@ -0,0 +1,5 @@
+-- this is a comment
+select count(*) rowcount, license
+from projects
+where id=:#lowId or id=2 or id=3
+group by license
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/8b3715d3/components/camel-sql/src/test/resources/sql/selectProjects.sql
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/test/resources/sql/selectProjects.sql b/components/camel-sql/src/test/resources/sql/selectProjects.sql
new file mode 100644
index 0000000..a12ab31
--- /dev/null
+++ b/components/camel-sql/src/test/resources/sql/selectProjects.sql
@@ -0,0 +1,4 @@
+-- this is a comment
+select *
+from projects
+order by id
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/8b3715d3/components/camel-sql/src/test/resources/sql/selectStored.sql
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/test/resources/sql/selectStored.sql b/components/camel-sql/src/test/resources/sql/selectStored.sql
new file mode 100644
index 0000000..ba6c39c
--- /dev/null
+++ b/components/camel-sql/src/test/resources/sql/selectStored.sql
@@ -0,0 +1 @@
+SUBNUMBERS(INTEGER ${headers.num1},INTEGER ${headers.num2},OUT INTEGER resultofsub)
\ No newline at end of file


[4/4] camel git commit: CAMEL-9461: sql-stored: add support for using new lines and whitespace

Posted by da...@apache.org.
CAMEL-9461: sql-stored: add support for using new lines and whitespace


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/38c1f6f7
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/38c1f6f7
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/38c1f6f7

Branch: refs/heads/master
Commit: 38c1f6f7f06163d3e58400a828ed532a5ab1d8d8
Parents: f1ff40a
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Feb 19 13:35:45 2016 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Feb 19 13:49:42 2016 +0100

----------------------------------------------------------------------
 .../stored/template/generated/SSPTParser.java   |  20 +-
 .../template/generated/SSPTParserConstants.java |  22 +-
 .../generated/SSPTParserTokenManager.java       | 210 +++++++++++++------
 .../sql/stored/template/grammar/sspt.jj         |  16 +-
 .../src/test/resources/sql/selectStored.sql     |   8 +-
 5 files changed, 182 insertions(+), 94 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/38c1f6f7/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/generated/SSPTParser.java
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/generated/SSPTParser.java b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/generated/SSPTParser.java
index 066e5f2..da08c20 100644
--- a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/generated/SSPTParser.java
+++ b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/generated/SSPTParser.java
@@ -15,13 +15,13 @@ public class SSPTParser implements SSPTParserConstants {
     Template template = new Template();
     Object parameter = null;
     procedureName = jj_consume_token(IDENTIFIER);
-    jj_consume_token(1);
+    jj_consume_token(PROCEDURE_BEGIN);
     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
-    case 4:
+    case 2:
     case NUMBER:
     case IDENTIFIER:
       parameter = Parameter();
-                                                                 template.addParameter(parameter);
+                                                                               template.addParameter(parameter);
       label_1:
       while (true) {
         switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
@@ -41,7 +41,7 @@ public class SSPTParser implements SSPTParserConstants {
       jj_la1[1] = jj_gen;
       ;
     }
-    jj_consume_token(2);
+    jj_consume_token(PROCEDURE_END);
     jj_consume_token(0);
    template.setProcedureName(procedureName.toString());
    {if (true) return template;}
@@ -56,7 +56,7 @@ public class SSPTParser implements SSPTParserConstants {
       param = InputParameter();
                                 {if (true) return param;}
       break;
-    case 4:
+    case 2:
       param = OutParameter();
                                                                           {if (true) return param;}
       break;
@@ -73,7 +73,7 @@ public class SSPTParser implements SSPTParserConstants {
      String name;
      Token valueSrcToken;
     sqlTypeToken = ParameterSqlType();
-    jj_consume_token(3);
+    jj_consume_token(1);
     valueSrcToken = InputParameterSrc();
         int sqlType = ParseHelper.parseSqlType(sqlTypeToken);
         {if (true) return new InputParameter(createNextParameterName(),sqlType,valueSrcToken);}
@@ -84,10 +84,10 @@ public class SSPTParser implements SSPTParserConstants {
      Token sqlTypeToken;
      String name;
      String outValueMapKey;
-    jj_consume_token(4);
-    jj_consume_token(3);
+    jj_consume_token(2);
+    jj_consume_token(1);
     sqlTypeToken = ParameterSqlType();
-    jj_consume_token(3);
+    jj_consume_token(1);
     outValueMapKey = OutHeader();
         {if (true) return new OutParameter(createNextParameterName(),ParseHelper.parseSqlType(sqlTypeToken),outValueMapKey);}
     throw new Error("Missing return statement in function");
@@ -152,7 +152,7 @@ public class SSPTParser implements SSPTParserConstants {
       jj_la1_init_0();
    }
    private static void jj_la1_init_0() {
-      jj_la1_0 = new int[] {0x800,0x4030,0x4030,0x4020,0x3000,};
+      jj_la1_0 = new int[] {0x200,0x400c,0x400c,0x4008,0x3000,};
    }
 
   /** Constructor with InputStream. */

http://git-wip-us.apache.org/repos/asf/camel/blob/38c1f6f7/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/generated/SSPTParserConstants.java
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/generated/SSPTParserConstants.java b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/generated/SSPTParserConstants.java
index dc48177..f0ba72c 100644
--- a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/generated/SSPTParserConstants.java
+++ b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/generated/SSPTParserConstants.java
@@ -11,19 +11,23 @@ public interface SSPTParserConstants {
   /** End of File. */
   int EOF = 0;
   /** RegularExpression Id. */
-  int NUMBER = 5;
+  int NUMBER = 3;
   /** RegularExpression Id. */
-  int DIGIT = 6;
+  int DIGIT = 4;
   /** RegularExpression Id. */
-  int LETTER = 7;
+  int LETTER = 5;
   /** RegularExpression Id. */
-  int SPECIAL = 8;
+  int SPECIAL = 6;
   /** RegularExpression Id. */
-  int WHITESPACE = 9;
+  int WHITESPACE = 7;
   /** RegularExpression Id. */
-  int COMMA = 10;
+  int COMMA = 8;
   /** RegularExpression Id. */
-  int SEPARATOR = 11;
+  int SEPARATOR = 9;
+  /** RegularExpression Id. */
+  int PROCEDURE_BEGIN = 10;
+  /** RegularExpression Id. */
+  int PROCEDURE_END = 11;
   /** RegularExpression Id. */
   int SIMPLE_EXP_TOKEN = 12;
   /** RegularExpression Id. */
@@ -37,8 +41,6 @@ public interface SSPTParserConstants {
   /** Literal token values. */
   String[] tokenImage = {
     "<EOF>",
-    "\"(\"",
-    "\")\"",
     "\" \"",
     "\"OUT\"",
     "<NUMBER>",
@@ -48,6 +50,8 @@ public interface SSPTParserConstants {
     "<WHITESPACE>",
     "\",\"",
     "<SEPARATOR>",
+    "<PROCEDURE_BEGIN>",
+    "<PROCEDURE_END>",
     "<SIMPLE_EXP_TOKEN>",
     "<PARAMETER_POS_TOKEN>",
     "<IDENTIFIER>",

http://git-wip-us.apache.org/repos/asf/camel/blob/38c1f6f7/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/generated/SSPTParserTokenManager.java
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/generated/SSPTParserTokenManager.java b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/generated/SSPTParserTokenManager.java
index 9d27a69..15a9347 100644
--- a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/generated/SSPTParserTokenManager.java
+++ b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/generated/SSPTParserTokenManager.java
@@ -15,20 +15,20 @@ private final int jjStopStringLiteralDfa_0(int pos, long active0)
    switch (pos)
    {
       case 0:
-         if ((active0 & 0x10L) != 0L)
+         if ((active0 & 0x4L) != 0L)
          {
             jjmatchedKind = 14;
-            return 11;
+            return 14;
          }
-         if ((active0 & 0x8L) != 0L)
-            return 12;
+         if ((active0 & 0x2L) != 0L)
+            return 19;
          return -1;
       case 1:
-         if ((active0 & 0x10L) != 0L)
+         if ((active0 & 0x4L) != 0L)
          {
             jjmatchedKind = 14;
             jjmatchedPos = 1;
-            return 11;
+            return 14;
          }
          return -1;
       default :
@@ -50,15 +50,11 @@ private int jjMoveStringLiteralDfa0_0()
    switch(curChar)
    {
       case 32:
-         return jjStartNfaWithStates_0(0, 3, 12);
-      case 40:
-         return jjStopAtPos(0, 1);
-      case 41:
-         return jjStopAtPos(0, 2);
+         return jjStartNfaWithStates_0(0, 1, 19);
       case 79:
-         return jjMoveStringLiteralDfa1_0(0x10L);
+         return jjMoveStringLiteralDfa1_0(0x4L);
       default :
-         return jjMoveNfa_0(7, 0);
+         return jjMoveNfa_0(10, 0);
    }
 }
 private int jjMoveStringLiteralDfa1_0(long active0)
@@ -71,7 +67,7 @@ private int jjMoveStringLiteralDfa1_0(long active0)
    switch(curChar)
    {
       case 85:
-         return jjMoveStringLiteralDfa2_0(active0, 0x10L);
+         return jjMoveStringLiteralDfa2_0(active0, 0x4L);
       default :
          break;
    }
@@ -89,8 +85,8 @@ private int jjMoveStringLiteralDfa2_0(long old0, long active0)
    switch(curChar)
    {
       case 84:
-         if ((active0 & 0x10L) != 0L)
-            return jjStartNfaWithStates_0(2, 4, 11);
+         if ((active0 & 0x4L) != 0L)
+            return jjStartNfaWithStates_0(2, 2, 14);
          break;
       default :
          break;
@@ -108,7 +104,7 @@ private int jjStartNfaWithStates_0(int pos, int kind, int state)
 private int jjMoveNfa_0(int startState, int curPos)
 {
    int startsAt = 0;
-   jjnewStateCnt = 12;
+   jjnewStateCnt = 19;
    int i = 1;
    jjstateSet[0] = startState;
    int kind = 0x7fffffff;
@@ -123,91 +119,164 @@ private int jjMoveNfa_0(int startState, int curPos)
          {
             switch(jjstateSet[--i])
             {
-               case 7:
+               case 10:
                   if ((0x3ff609c00000000L & l) != 0L)
                   {
                      if (kind > 14)
                         kind = 14;
-                     jjCheckNAdd(11);
+                     jjCheckNAdd(14);
+                  }
+                  else if ((0x100002600L & l) != 0L)
+                  {
+                     if (kind > 7)
+                        kind = 7;
+                     jjCheckNAddStates(0, 5);
                   }
-                  else if ((0x100000600L & l) != 0L)
-                     jjCheckNAddTwoStates(1, 2);
                   else if (curChar == 58)
-                     jjstateSet[jjnewStateCnt++] = 8;
-                  else if (curChar == 44)
+                     jjstateSet[jjnewStateCnt++] = 11;
+                  else if (curChar == 41)
                   {
                      if (kind > 11)
                         kind = 11;
-                     jjCheckNAdd(3);
+                     jjCheckNAdd(6);
+                  }
+                  else if (curChar == 40)
+                  {
+                     if (kind > 10)
+                        kind = 10;
+                     jjCheckNAdd(4);
+                  }
+                  else if (curChar == 44)
+                  {
+                     if (kind > 9)
+                        kind = 9;
+                     jjCheckNAdd(2);
                   }
                   if ((0x3ff000000000000L & l) != 0L)
                   {
-                     if (kind > 5)
-                        kind = 5;
+                     if (kind > 3)
+                        kind = 3;
                      jjCheckNAdd(0);
                   }
                   else if (curChar == 36)
-                     jjstateSet[jjnewStateCnt++] = 4;
+                     jjstateSet[jjnewStateCnt++] = 7;
                   break;
-               case 12:
-                  if ((0x100000600L & l) != 0L)
-                     jjCheckNAddTwoStates(1, 2);
-                  else if (curChar == 44)
+               case 19:
+                  if ((0x100002600L & l) != 0L)
+                     jjCheckNAddTwoStates(18, 5);
+                  else if (curChar == 41)
                   {
                      if (kind > 11)
                         kind = 11;
-                     jjCheckNAdd(3);
+                     jjCheckNAdd(6);
+                  }
+                  else if (curChar == 40)
+                  {
+                     if (kind > 10)
+                        kind = 10;
+                     jjCheckNAdd(4);
+                  }
+                  else if (curChar == 44)
+                  {
+                     if (kind > 9)
+                        kind = 9;
+                     jjCheckNAdd(2);
                   }
+                  if ((0x100002600L & l) != 0L)
+                     jjCheckNAddTwoStates(17, 3);
+                  if ((0x100002600L & l) != 0L)
+                     jjCheckNAddTwoStates(16, 1);
                   break;
                case 0:
                   if ((0x3ff000000000000L & l) == 0L)
                      break;
-                  if (kind > 5)
-                     kind = 5;
+                  if (kind > 3)
+                     kind = 3;
                   jjCheckNAdd(0);
                   break;
                case 1:
-                  if ((0x100000600L & l) != 0L)
-                     jjCheckNAddTwoStates(1, 2);
+                  if (curChar != 44)
+                     break;
+                  kind = 9;
+                  jjCheckNAdd(2);
                   break;
                case 2:
-                  if (curChar != 44)
+                  if ((0x100002600L & l) == 0L)
                      break;
-                  kind = 11;
-                  jjCheckNAdd(3);
+                  if (kind > 9)
+                     kind = 9;
+                  jjCheckNAdd(2);
                   break;
                case 3:
-                  if ((0x100000600L & l) == 0L)
+                  if (curChar != 40)
+                     break;
+                  kind = 10;
+                  jjCheckNAdd(4);
+                  break;
+               case 4:
+                  if ((0x100002600L & l) == 0L)
+                     break;
+                  if (kind > 10)
+                     kind = 10;
+                  jjCheckNAdd(4);
+                  break;
+               case 5:
+                  if (curChar != 41)
+                     break;
+                  kind = 11;
+                  jjCheckNAdd(6);
+                  break;
+               case 6:
+                  if ((0x100002600L & l) == 0L)
                      break;
                   if (kind > 11)
                      kind = 11;
-                  jjCheckNAdd(3);
+                  jjCheckNAdd(6);
                   break;
-               case 5:
+               case 8:
                   if ((0x3ff609d00000000L & l) != 0L)
-                     jjAddStates(0, 1);
+                     jjAddStates(6, 7);
                   break;
-               case 8:
+               case 11:
                   if (curChar == 35)
-                     jjCheckNAdd(9);
+                     jjCheckNAdd(12);
                   break;
-               case 9:
+               case 12:
                   if ((0x3ff609c00000000L & l) == 0L)
                      break;
                   if (kind > 13)
                      kind = 13;
-                  jjCheckNAdd(9);
+                  jjCheckNAdd(12);
                   break;
-               case 10:
+               case 13:
                   if (curChar == 58)
-                     jjstateSet[jjnewStateCnt++] = 8;
+                     jjstateSet[jjnewStateCnt++] = 11;
                   break;
-               case 11:
+               case 14:
                   if ((0x3ff609c00000000L & l) == 0L)
                      break;
                   if (kind > 14)
                      kind = 14;
-                  jjCheckNAdd(11);
+                  jjCheckNAdd(14);
+                  break;
+               case 15:
+                  if ((0x100002600L & l) == 0L)
+                     break;
+                  if (kind > 7)
+                     kind = 7;
+                  jjCheckNAddStates(0, 5);
+                  break;
+               case 16:
+                  if ((0x100002600L & l) != 0L)
+                     jjCheckNAddTwoStates(16, 1);
+                  break;
+               case 17:
+                  if ((0x100002600L & l) != 0L)
+                     jjCheckNAddTwoStates(17, 3);
+                  break;
+               case 18:
+                  if ((0x100002600L & l) != 0L)
+                     jjCheckNAddTwoStates(18, 5);
                   break;
                default : break;
             }
@@ -220,32 +289,32 @@ private int jjMoveNfa_0(int startState, int curPos)
          {
             switch(jjstateSet[--i])
             {
-               case 7:
-               case 11:
+               case 10:
+               case 14:
                   if ((0x2ffffffe87fffffeL & l) == 0L)
                      break;
                   if (kind > 14)
                      kind = 14;
-                  jjCheckNAdd(11);
+                  jjCheckNAdd(14);
                   break;
-               case 4:
+               case 7:
                   if (curChar == 123)
-                     jjCheckNAdd(5);
+                     jjCheckNAdd(8);
                   break;
-               case 5:
+               case 8:
                   if ((0x2ffffffe87fffffeL & l) != 0L)
-                     jjCheckNAddTwoStates(5, 6);
+                     jjCheckNAddTwoStates(8, 9);
                   break;
-               case 6:
+               case 9:
                   if (curChar == 125 && kind > 12)
                      kind = 12;
                   break;
-               case 9:
+               case 12:
                   if ((0x2ffffffe87fffffeL & l) == 0L)
                      break;
                   if (kind > 13)
                      kind = 13;
-                  jjstateSet[jjnewStateCnt++] = 9;
+                  jjstateSet[jjnewStateCnt++] = 12;
                   break;
                default : break;
             }
@@ -270,19 +339,19 @@ private int jjMoveNfa_0(int startState, int curPos)
          kind = 0x7fffffff;
       }
       ++curPos;
-      if ((i = jjnewStateCnt) == (startsAt = 12 - (jjnewStateCnt = startsAt)))
+      if ((i = jjnewStateCnt) == (startsAt = 19 - (jjnewStateCnt = startsAt)))
          return curPos;
       try { curChar = input_stream.readChar(); }
       catch(java.io.IOException e) { return curPos; }
    }
 }
 static final int[] jjnextStates = {
-   5, 6, 
+   16, 1, 17, 3, 18, 5, 8, 9, 
 };
 
 /** Token literal values. */
 public static final String[] jjstrLiteralImages = {
-"", "\50", "\51", "\40", "\117\125\124", null, null, null, null, null, null, 
+"", "\40", "\117\125\124", null, null, null, null, null, null, null, null, 
 null, null, null, null, };
 
 /** Lexer state names. */
@@ -290,8 +359,8 @@ public static final String[] lexStateNames = {
    "DEFAULT",
 };
 protected SimpleCharStream input_stream;
-private final int[] jjrounds = new int[12];
-private final int[] jjstateSet = new int[24];
+private final int[] jjrounds = new int[19];
+private final int[] jjstateSet = new int[38];
 protected char curChar;
 /** Constructor. */
 public SSPTParserTokenManager(SimpleCharStream stream){
@@ -318,7 +387,7 @@ private void ReInitRounds()
 {
    int i;
    jjround = 0x80000001;
-   for (i = 12; i-- > 0;)
+   for (i = 19; i-- > 0;)
       jjrounds[i] = 0x80000000;
 }
 
@@ -442,4 +511,11 @@ private void jjCheckNAddTwoStates(int state1, int state2)
    jjCheckNAdd(state2);
 }
 
+private void jjCheckNAddStates(int start, int end)
+{
+   do {
+      jjCheckNAdd(jjnextStates[start]);
+   } while (start++ != end);
+}
+
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/38c1f6f7/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/grammar/sspt.jj
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/grammar/sspt.jj b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/grammar/sspt.jj
index da7af35..d078591 100644
--- a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/grammar/sspt.jj
+++ b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/grammar/sspt.jj
@@ -45,9 +45,9 @@ public Template parse() :
     Object parameter = null;
 }
 {
-  (procedureName = <IDENTIFIER> "(" ( (parameter = Parameter() { template.addParameter(parameter);}) (<SEPARATOR>
+  (procedureName = <IDENTIFIER> <PROCEDURE_BEGIN> ( (parameter = Parameter() { template.addParameter(parameter);}) (<SEPARATOR>
   parameter
-  = Parameter(){template.addParameter(parameter);})*)? ")" <EOF>)
+  = Parameter(){template.addParameter(parameter);})*)? <PROCEDURE_END> <EOF>)
   {
    template.setProcedureName(procedureName.toString());
    return template;
@@ -133,7 +133,6 @@ TOKEN: {
     <NUMBER: (["0"-"9"])+>
 }
 
-
 TOKEN: {
     <#DIGIT: (["0"-"9"])>
 }
@@ -147,7 +146,7 @@ TOKEN: {
 }
 
 TOKEN: {
-    <#WHITESPACE: (" "|"\n"|"\t")>
+    <WHITESPACE: (" "|"\n"|"\r"|"\t")>
 }
 
 TOKEN: {
@@ -158,6 +157,14 @@ TOKEN: {
     <SEPARATOR: ( ( <WHITESPACE> )* (<COMMA>) ( <WHITESPACE> )* )>
 }
 
+TOKEN: {
+    <PROCEDURE_BEGIN: ( ( <WHITESPACE> )* "(" ( <WHITESPACE> )* )>
+}
+
+TOKEN: {
+    <PROCEDURE_END: ( ( <WHITESPACE> )* ")" ( <WHITESPACE> )* )>
+}
+
 TOKEN : {
     <SIMPLE_EXP_TOKEN: "${"(<LETTER>|<DIGIT> | <SPECIAL> | " ")+ "}">
 }
@@ -166,7 +173,6 @@ TOKEN : {
     <PARAMETER_POS_TOKEN: ":#"(<LETTER>|<DIGIT>|<SPECIAL> )+>
 }
 
-
 TOKEN : {
     <IDENTIFIER: ( <LETTER> | <DIGIT> | <SPECIAL> )+ >
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/38c1f6f7/components/camel-sql/src/test/resources/sql/selectStored.sql
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/test/resources/sql/selectStored.sql b/components/camel-sql/src/test/resources/sql/selectStored.sql
index f881aa1..7430b7f 100644
--- a/components/camel-sql/src/test/resources/sql/selectStored.sql
+++ b/components/camel-sql/src/test/resources/sql/selectStored.sql
@@ -1,3 +1,5 @@
-SUBNUMBERS(INTEGER ${headers.num1},
-  INTEGER ${headers.num2},
-  OUT INTEGER resultofsub)
\ No newline at end of file
+SUBNUMBERS(
+  INTEGER ${headers.num1} ,
+  INTEGER ${headers.num2} ,
+  OUT INTEGER resultofsub
+)
\ No newline at end of file


[3/4] camel git commit: CAMEL-9461: sql-stored: add support for using new lines and whitespace

Posted by da...@apache.org.
CAMEL-9461: sql-stored: add support for using new lines and whitespace


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/f1ff40ab
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/f1ff40ab
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/f1ff40ab

Branch: refs/heads/master
Commit: f1ff40abe5786ae15d8f433fdac01bb8dd9f7c2b
Parents: 8b3715d
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Feb 19 13:26:52 2016 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Feb 19 13:26:52 2016 +0100

----------------------------------------------------------------------
 .../stored/template/generated/SSPTParser.java   |  22 +--
 .../template/generated/SSPTParserConstants.java |  24 ++-
 .../generated/SSPTParserTokenManager.java       | 155 ++++++++++++-------
 .../sql/stored/template/grammar/sspt.jj         |  14 +-
 .../src/test/resources/sql/selectStored.sql     |   4 +-
 5 files changed, 138 insertions(+), 81 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/f1ff40ab/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/generated/SSPTParser.java
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/generated/SSPTParser.java b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/generated/SSPTParser.java
index 858b203..066e5f2 100644
--- a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/generated/SSPTParser.java
+++ b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/generated/SSPTParser.java
@@ -17,7 +17,7 @@ public class SSPTParser implements SSPTParserConstants {
     procedureName = jj_consume_token(IDENTIFIER);
     jj_consume_token(1);
     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
-    case 5:
+    case 4:
     case NUMBER:
     case IDENTIFIER:
       parameter = Parameter();
@@ -25,14 +25,14 @@ public class SSPTParser implements SSPTParserConstants {
       label_1:
       while (true) {
         switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
-        case 2:
+        case SEPARATOR:
           ;
           break;
         default:
           jj_la1[0] = jj_gen;
           break label_1;
         }
-        jj_consume_token(2);
+        jj_consume_token(SEPARATOR);
         parameter = Parameter();
                 template.addParameter(parameter);
       }
@@ -41,7 +41,7 @@ public class SSPTParser implements SSPTParserConstants {
       jj_la1[1] = jj_gen;
       ;
     }
-    jj_consume_token(3);
+    jj_consume_token(2);
     jj_consume_token(0);
    template.setProcedureName(procedureName.toString());
    {if (true) return template;}
@@ -56,7 +56,7 @@ public class SSPTParser implements SSPTParserConstants {
       param = InputParameter();
                                 {if (true) return param;}
       break;
-    case 5:
+    case 4:
       param = OutParameter();
                                                                           {if (true) return param;}
       break;
@@ -73,7 +73,7 @@ public class SSPTParser implements SSPTParserConstants {
      String name;
      Token valueSrcToken;
     sqlTypeToken = ParameterSqlType();
-    jj_consume_token(4);
+    jj_consume_token(3);
     valueSrcToken = InputParameterSrc();
         int sqlType = ParseHelper.parseSqlType(sqlTypeToken);
         {if (true) return new InputParameter(createNextParameterName(),sqlType,valueSrcToken);}
@@ -84,10 +84,10 @@ public class SSPTParser implements SSPTParserConstants {
      Token sqlTypeToken;
      String name;
      String outValueMapKey;
-    jj_consume_token(5);
     jj_consume_token(4);
+    jj_consume_token(3);
     sqlTypeToken = ParameterSqlType();
-    jj_consume_token(4);
+    jj_consume_token(3);
     outValueMapKey = OutHeader();
         {if (true) return new OutParameter(createNextParameterName(),ParseHelper.parseSqlType(sqlTypeToken),outValueMapKey);}
     throw new Error("Missing return statement in function");
@@ -152,7 +152,7 @@ public class SSPTParser implements SSPTParserConstants {
       jj_la1_init_0();
    }
    private static void jj_la1_init_0() {
-      jj_la1_0 = new int[] {0x4,0x1060,0x1060,0x1040,0xc00,};
+      jj_la1_0 = new int[] {0x800,0x4030,0x4030,0x4020,0x3000,};
    }
 
   /** Constructor with InputStream. */
@@ -269,7 +269,7 @@ public class SSPTParser implements SSPTParserConstants {
   /** Generate ParseException. */
   public ParseException generateParseException() {
     jj_expentries.clear();
-    boolean[] la1tokens = new boolean[13];
+    boolean[] la1tokens = new boolean[15];
     if (jj_kind >= 0) {
       la1tokens[jj_kind] = true;
       jj_kind = -1;
@@ -283,7 +283,7 @@ public class SSPTParser implements SSPTParserConstants {
         }
       }
     }
-    for (int i = 0; i < 13; i++) {
+    for (int i = 0; i < 15; i++) {
       if (la1tokens[i]) {
         jj_expentry = new int[1];
         jj_expentry[0] = i;

http://git-wip-us.apache.org/repos/asf/camel/blob/f1ff40ab/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/generated/SSPTParserConstants.java
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/generated/SSPTParserConstants.java b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/generated/SSPTParserConstants.java
index 0b66a49..dc48177 100644
--- a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/generated/SSPTParserConstants.java
+++ b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/generated/SSPTParserConstants.java
@@ -11,19 +11,25 @@ public interface SSPTParserConstants {
   /** End of File. */
   int EOF = 0;
   /** RegularExpression Id. */
-  int NUMBER = 6;
+  int NUMBER = 5;
   /** RegularExpression Id. */
-  int DIGIT = 7;
+  int DIGIT = 6;
   /** RegularExpression Id. */
-  int LETTER = 8;
+  int LETTER = 7;
   /** RegularExpression Id. */
-  int SPECIAL = 9;
+  int SPECIAL = 8;
   /** RegularExpression Id. */
-  int SIMPLE_EXP_TOKEN = 10;
+  int WHITESPACE = 9;
   /** RegularExpression Id. */
-  int PARAMETER_POS_TOKEN = 11;
+  int COMMA = 10;
   /** RegularExpression Id. */
-  int IDENTIFIER = 12;
+  int SEPARATOR = 11;
+  /** RegularExpression Id. */
+  int SIMPLE_EXP_TOKEN = 12;
+  /** RegularExpression Id. */
+  int PARAMETER_POS_TOKEN = 13;
+  /** RegularExpression Id. */
+  int IDENTIFIER = 14;
 
   /** Lexical state. */
   int DEFAULT = 0;
@@ -32,7 +38,6 @@ public interface SSPTParserConstants {
   String[] tokenImage = {
     "<EOF>",
     "\"(\"",
-    "\",\"",
     "\")\"",
     "\" \"",
     "\"OUT\"",
@@ -40,6 +45,9 @@ public interface SSPTParserConstants {
     "<DIGIT>",
     "<LETTER>",
     "<SPECIAL>",
+    "<WHITESPACE>",
+    "\",\"",
+    "<SEPARATOR>",
     "<SIMPLE_EXP_TOKEN>",
     "<PARAMETER_POS_TOKEN>",
     "<IDENTIFIER>",

http://git-wip-us.apache.org/repos/asf/camel/blob/f1ff40ab/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/generated/SSPTParserTokenManager.java
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/generated/SSPTParserTokenManager.java b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/generated/SSPTParserTokenManager.java
index 1dd57a1..9d27a69 100644
--- a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/generated/SSPTParserTokenManager.java
+++ b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/generated/SSPTParserTokenManager.java
@@ -15,18 +15,20 @@ private final int jjStopStringLiteralDfa_0(int pos, long active0)
    switch (pos)
    {
       case 0:
-         if ((active0 & 0x20L) != 0L)
+         if ((active0 & 0x10L) != 0L)
          {
-            jjmatchedKind = 12;
-            return 8;
+            jjmatchedKind = 14;
+            return 11;
          }
+         if ((active0 & 0x8L) != 0L)
+            return 12;
          return -1;
       case 1:
-         if ((active0 & 0x20L) != 0L)
+         if ((active0 & 0x10L) != 0L)
          {
-            jjmatchedKind = 12;
+            jjmatchedKind = 14;
             jjmatchedPos = 1;
-            return 8;
+            return 11;
          }
          return -1;
       default :
@@ -48,17 +50,15 @@ private int jjMoveStringLiteralDfa0_0()
    switch(curChar)
    {
       case 32:
-         return jjStopAtPos(0, 4);
+         return jjStartNfaWithStates_0(0, 3, 12);
       case 40:
          return jjStopAtPos(0, 1);
       case 41:
-         return jjStopAtPos(0, 3);
-      case 44:
          return jjStopAtPos(0, 2);
       case 79:
-         return jjMoveStringLiteralDfa1_0(0x20L);
+         return jjMoveStringLiteralDfa1_0(0x10L);
       default :
-         return jjMoveNfa_0(4, 0);
+         return jjMoveNfa_0(7, 0);
    }
 }
 private int jjMoveStringLiteralDfa1_0(long active0)
@@ -71,7 +71,7 @@ private int jjMoveStringLiteralDfa1_0(long active0)
    switch(curChar)
    {
       case 85:
-         return jjMoveStringLiteralDfa2_0(active0, 0x20L);
+         return jjMoveStringLiteralDfa2_0(active0, 0x10L);
       default :
          break;
    }
@@ -89,8 +89,8 @@ private int jjMoveStringLiteralDfa2_0(long old0, long active0)
    switch(curChar)
    {
       case 84:
-         if ((active0 & 0x20L) != 0L)
-            return jjStartNfaWithStates_0(2, 5, 8);
+         if ((active0 & 0x10L) != 0L)
+            return jjStartNfaWithStates_0(2, 4, 11);
          break;
       default :
          break;
@@ -108,7 +108,7 @@ private int jjStartNfaWithStates_0(int pos, int kind, int state)
 private int jjMoveNfa_0(int startState, int curPos)
 {
    int startsAt = 0;
-   jjnewStateCnt = 9;
+   jjnewStateCnt = 12;
    int i = 1;
    jjstateSet[0] = startState;
    int kind = 0x7fffffff;
@@ -123,56 +123,91 @@ private int jjMoveNfa_0(int startState, int curPos)
          {
             switch(jjstateSet[--i])
             {
-               case 4:
+               case 7:
                   if ((0x3ff609c00000000L & l) != 0L)
                   {
-                     if (kind > 12)
-                        kind = 12;
-                     jjCheckNAdd(8);
+                     if (kind > 14)
+                        kind = 14;
+                     jjCheckNAdd(11);
                   }
+                  else if ((0x100000600L & l) != 0L)
+                     jjCheckNAddTwoStates(1, 2);
                   else if (curChar == 58)
-                     jjstateSet[jjnewStateCnt++] = 5;
+                     jjstateSet[jjnewStateCnt++] = 8;
+                  else if (curChar == 44)
+                  {
+                     if (kind > 11)
+                        kind = 11;
+                     jjCheckNAdd(3);
+                  }
                   if ((0x3ff000000000000L & l) != 0L)
                   {
-                     if (kind > 6)
-                        kind = 6;
+                     if (kind > 5)
+                        kind = 5;
                      jjCheckNAdd(0);
                   }
                   else if (curChar == 36)
-                     jjstateSet[jjnewStateCnt++] = 1;
+                     jjstateSet[jjnewStateCnt++] = 4;
+                  break;
+               case 12:
+                  if ((0x100000600L & l) != 0L)
+                     jjCheckNAddTwoStates(1, 2);
+                  else if (curChar == 44)
+                  {
+                     if (kind > 11)
+                        kind = 11;
+                     jjCheckNAdd(3);
+                  }
                   break;
                case 0:
                   if ((0x3ff000000000000L & l) == 0L)
                      break;
-                  if (kind > 6)
-                     kind = 6;
+                  if (kind > 5)
+                     kind = 5;
                   jjCheckNAdd(0);
                   break;
+               case 1:
+                  if ((0x100000600L & l) != 0L)
+                     jjCheckNAddTwoStates(1, 2);
+                  break;
                case 2:
+                  if (curChar != 44)
+                     break;
+                  kind = 11;
+                  jjCheckNAdd(3);
+                  break;
+               case 3:
+                  if ((0x100000600L & l) == 0L)
+                     break;
+                  if (kind > 11)
+                     kind = 11;
+                  jjCheckNAdd(3);
+                  break;
+               case 5:
                   if ((0x3ff609d00000000L & l) != 0L)
                      jjAddStates(0, 1);
                   break;
-               case 5:
+               case 8:
                   if (curChar == 35)
-                     jjCheckNAdd(6);
+                     jjCheckNAdd(9);
                   break;
-               case 6:
+               case 9:
                   if ((0x3ff609c00000000L & l) == 0L)
                      break;
-                  if (kind > 11)
-                     kind = 11;
-                  jjCheckNAdd(6);
+                  if (kind > 13)
+                     kind = 13;
+                  jjCheckNAdd(9);
                   break;
-               case 7:
+               case 10:
                   if (curChar == 58)
-                     jjstateSet[jjnewStateCnt++] = 5;
+                     jjstateSet[jjnewStateCnt++] = 8;
                   break;
-               case 8:
+               case 11:
                   if ((0x3ff609c00000000L & l) == 0L)
                      break;
-                  if (kind > 12)
-                     kind = 12;
-                  jjCheckNAdd(8);
+                  if (kind > 14)
+                     kind = 14;
+                  jjCheckNAdd(11);
                   break;
                default : break;
             }
@@ -185,32 +220,32 @@ private int jjMoveNfa_0(int startState, int curPos)
          {
             switch(jjstateSet[--i])
             {
-               case 4:
-               case 8:
+               case 7:
+               case 11:
                   if ((0x2ffffffe87fffffeL & l) == 0L)
                      break;
-                  if (kind > 12)
-                     kind = 12;
-                  jjCheckNAdd(8);
+                  if (kind > 14)
+                     kind = 14;
+                  jjCheckNAdd(11);
                   break;
-               case 1:
+               case 4:
                   if (curChar == 123)
-                     jjCheckNAdd(2);
+                     jjCheckNAdd(5);
                   break;
-               case 2:
+               case 5:
                   if ((0x2ffffffe87fffffeL & l) != 0L)
-                     jjCheckNAddTwoStates(2, 3);
-                  break;
-               case 3:
-                  if (curChar == 125 && kind > 10)
-                     kind = 10;
+                     jjCheckNAddTwoStates(5, 6);
                   break;
                case 6:
+                  if (curChar == 125 && kind > 12)
+                     kind = 12;
+                  break;
+               case 9:
                   if ((0x2ffffffe87fffffeL & l) == 0L)
                      break;
-                  if (kind > 11)
-                     kind = 11;
-                  jjstateSet[jjnewStateCnt++] = 6;
+                  if (kind > 13)
+                     kind = 13;
+                  jjstateSet[jjnewStateCnt++] = 9;
                   break;
                default : break;
             }
@@ -235,28 +270,28 @@ private int jjMoveNfa_0(int startState, int curPos)
          kind = 0x7fffffff;
       }
       ++curPos;
-      if ((i = jjnewStateCnt) == (startsAt = 9 - (jjnewStateCnt = startsAt)))
+      if ((i = jjnewStateCnt) == (startsAt = 12 - (jjnewStateCnt = startsAt)))
          return curPos;
       try { curChar = input_stream.readChar(); }
       catch(java.io.IOException e) { return curPos; }
    }
 }
 static final int[] jjnextStates = {
-   2, 3, 
+   5, 6, 
 };
 
 /** Token literal values. */
 public static final String[] jjstrLiteralImages = {
-"", "\50", "\54", "\51", "\40", "\117\125\124", null, null, null, null, null, 
-null, null, };
+"", "\50", "\51", "\40", "\117\125\124", null, null, null, null, null, null, 
+null, null, null, null, };
 
 /** Lexer state names. */
 public static final String[] lexStateNames = {
    "DEFAULT",
 };
 protected SimpleCharStream input_stream;
-private final int[] jjrounds = new int[9];
-private final int[] jjstateSet = new int[18];
+private final int[] jjrounds = new int[12];
+private final int[] jjstateSet = new int[24];
 protected char curChar;
 /** Constructor. */
 public SSPTParserTokenManager(SimpleCharStream stream){
@@ -283,7 +318,7 @@ private void ReInitRounds()
 {
    int i;
    jjround = 0x80000001;
-   for (i = 9; i-- > 0;)
+   for (i = 12; i-- > 0;)
       jjrounds[i] = 0x80000000;
 }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/f1ff40ab/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/grammar/sspt.jj
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/grammar/sspt.jj b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/grammar/sspt.jj
index 0b3a295..da7af35 100644
--- a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/grammar/sspt.jj
+++ b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/grammar/sspt.jj
@@ -45,7 +45,7 @@ public Template parse() :
     Object parameter = null;
 }
 {
-  (procedureName = <IDENTIFIER> "(" ( (parameter = Parameter() { template.addParameter(parameter);}) (","
+  (procedureName = <IDENTIFIER> "(" ( (parameter = Parameter() { template.addParameter(parameter);}) (<SEPARATOR>
   parameter
   = Parameter(){template.addParameter(parameter);})*)? ")" <EOF>)
   {
@@ -146,6 +146,18 @@ TOKEN: {
     <#SPECIAL: (["#","_","-","'",".","$","{","}","\""])>
 }
 
+TOKEN: {
+    <#WHITESPACE: (" "|"\n"|"\t")>
+}
+
+TOKEN: {
+    <#COMMA: ",">
+}
+
+TOKEN: {
+    <SEPARATOR: ( ( <WHITESPACE> )* (<COMMA>) ( <WHITESPACE> )* )>
+}
+
 TOKEN : {
     <SIMPLE_EXP_TOKEN: "${"(<LETTER>|<DIGIT> | <SPECIAL> | " ")+ "}">
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/f1ff40ab/components/camel-sql/src/test/resources/sql/selectStored.sql
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/test/resources/sql/selectStored.sql b/components/camel-sql/src/test/resources/sql/selectStored.sql
index ba6c39c..f881aa1 100644
--- a/components/camel-sql/src/test/resources/sql/selectStored.sql
+++ b/components/camel-sql/src/test/resources/sql/selectStored.sql
@@ -1 +1,3 @@
-SUBNUMBERS(INTEGER ${headers.num1},INTEGER ${headers.num2},OUT INTEGER resultofsub)
\ No newline at end of file
+SUBNUMBERS(INTEGER ${headers.num1},
+  INTEGER ${headers.num2},
+  OUT INTEGER resultofsub)
\ No newline at end of file