Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id F0CDF18CCD for ; Sat, 9 Jan 2016 10:44:44 +0000 (UTC) Received: (qmail 30140 invoked by uid 500); 9 Jan 2016 10:44:44 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 30071 invoked by uid 500); 9 Jan 2016 10:44:44 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 30058 invoked by uid 99); 9 Jan 2016 10:44:44 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 09 Jan 2016 10:44:44 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 5CD40DFF73; Sat, 9 Jan 2016 10:44:44 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: davsclaus@apache.org To: commits@camel.apache.org Date: Sat, 09 Jan 2016 10:44:49 -0000 Message-Id: <71c9f2f59c0d417d9c17026a14ca0ad2@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [6/9] camel git commit: CAMEL-4725: Polished CAMEL-4725: Polished Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/0dcd69af Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/0dcd69af Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/0dcd69af Branch: refs/heads/master Commit: 0dcd69af5a0f880ce994ab88f2d4390d9b83123b Parents: c8cbcde Author: Claus Ibsen Authored: Sat Jan 9 11:16:06 2016 +0100 Committer: Claus Ibsen Committed: Sat Jan 9 11:16:06 2016 +0100 ---------------------------------------------------------------------- .../sql/stored/SqlStoredComponent.java | 23 ++++++++++--- .../component/sql/stored/SqlStoredEndpoint.java | 16 +++++++++ .../component/sql/stored/SqlStoredProducer.java | 31 ++++++++++++------ .../template/TemplateStoredProcedure.java | 30 +++++++++++------ .../TemplateStoredProcedureFactory.java | 34 ++++++++++++-------- .../sql/stored/template/ast/InputParameter.java | 31 +++++++++++------- .../sql/stored/template/ast/OutParameter.java | 29 +++++++++++------ .../sql/stored/template/ast/ParseHelper.java | 22 +++++++++++-- .../template/ast/ParseRuntimeException.java | 3 -- .../sql/stored/template/ast/Template.java | 26 +++++++++++---- .../camel/component/sql/stored/ParserTest.java | 32 ++++++++++-------- .../component/sql/stored/ProducerTest.java | 31 +++++++++++------- .../sql/stored/TemplateStoredProcedureTest.java | 34 +++++++++++--------- .../sql/stored/TestStoredProcedure.java | 23 +++++++++---- 14 files changed, 249 insertions(+), 116 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/0dcd69af/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/SqlStoredComponent.java ---------------------------------------------------------------------- diff --git a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/SqlStoredComponent.java b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/SqlStoredComponent.java index 20aedf1..4814be9 100644 --- a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/SqlStoredComponent.java +++ b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/SqlStoredComponent.java @@ -1,3 +1,19 @@ +/** + * 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.CamelContext; @@ -10,9 +26,6 @@ import org.springframework.jdbc.core.JdbcTemplate; import javax.sql.DataSource; import java.util.Map; -/** - * Created by snurmine on 1/3/16. - */ public class SqlStoredComponent extends UriEndpointComponent { private DataSource dataSource; @@ -46,7 +59,6 @@ public class SqlStoredComponent extends UriEndpointComponent { throw new IllegalArgumentException("DataSource must be configured"); } - return new SqlStoredEndpoint(new JdbcTemplate(target), remaining); } @@ -54,6 +66,9 @@ public class SqlStoredComponent extends UriEndpointComponent { return dataSource; } + /** + * Sets the DataSource to use to communicate with the database. + */ public void setDataSource(DataSource dataSource) { this.dataSource = dataSource; } http://git-wip-us.apache.org/repos/asf/camel/blob/0dcd69af/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/SqlStoredEndpoint.java ---------------------------------------------------------------------- diff --git a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/SqlStoredEndpoint.java b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/SqlStoredEndpoint.java index ae7348c..8ded03a 100644 --- a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/SqlStoredEndpoint.java +++ b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/SqlStoredEndpoint.java @@ -1,3 +1,19 @@ +/** + * 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.Producer; http://git-wip-us.apache.org/repos/asf/camel/blob/0dcd69af/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 f306a4c..81ff287 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 @@ -1,3 +1,19 @@ +/** + * 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.Endpoint; @@ -6,25 +22,20 @@ import org.apache.camel.component.sql.stored.template.TemplateStoredProcedure; import org.apache.camel.component.sql.stored.template.TemplateStoredProcedureFactory; import org.apache.camel.impl.DefaultProducer; -/** - * Created by snurmine on 1/3/16. - */ public class SqlStoredProducer extends DefaultProducer { - final TemplateStoredProcedureFactory templateStoredProcedureFactory; + private TemplateStoredProcedureFactory templateStoredProcedureFactory; + private TemplateStoredProcedure defaultTemplateStoredProcedure; - final TemplateStoredProcedure defaultTemplateStoredProcedure; - - public SqlStoredProducer(Endpoint endpoint, String template, TemplateStoredProcedureFactory - templateStoredProcedureFactory) { + public SqlStoredProducer(Endpoint endpoint, String template, TemplateStoredProcedureFactory templateStoredProcedureFactory) { super(endpoint); - this.defaultTemplateStoredProcedure = templateStoredProcedureFactory.createFromString(template); this.templateStoredProcedureFactory = templateStoredProcedureFactory; + this.defaultTemplateStoredProcedure = templateStoredProcedureFactory.createFromString(template); } @Override public void process(Exchange exchange) throws Exception { - this.defaultTemplateStoredProcedure.execute(exchange); + defaultTemplateStoredProcedure.execute(exchange); } } http://git-wip-us.apache.org/repos/asf/camel/blob/0dcd69af/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/TemplateStoredProcedure.java ---------------------------------------------------------------------- diff --git a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/TemplateStoredProcedure.java b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/TemplateStoredProcedure.java index 44103d8..e0821f5 100644 --- a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/TemplateStoredProcedure.java +++ b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/TemplateStoredProcedure.java @@ -1,5 +1,24 @@ +/** + * 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.template; +import java.util.HashMap; +import java.util.Map; + import org.apache.camel.Exchange; import org.apache.camel.component.sql.stored.template.ast.InputParameter; import org.apache.camel.component.sql.stored.template.ast.OutParameter; @@ -9,14 +28,9 @@ import org.springframework.jdbc.core.SqlOutParameter; import org.springframework.jdbc.core.SqlParameter; import org.springframework.jdbc.object.StoredProcedure; -import javax.sql.DataSource; -import java.util.HashMap; -import java.util.Map; - - public class TemplateStoredProcedure extends StoredProcedure { - Template template; + private final Template template; public TemplateStoredProcedure(JdbcTemplate jdbcTemplate, Template template) { this.template = template; @@ -34,11 +48,8 @@ public class TemplateStoredProcedure extends StoredProcedure { } compile(); - } - - public void execute(Exchange exchange) { Map params = new HashMap<>(); @@ -55,5 +66,4 @@ public class TemplateStoredProcedure extends StoredProcedure { } - } http://git-wip-us.apache.org/repos/asf/camel/blob/0dcd69af/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/TemplateStoredProcedureFactory.java ---------------------------------------------------------------------- diff --git a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/TemplateStoredProcedureFactory.java b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/TemplateStoredProcedureFactory.java index 947a6a5..78f034e 100644 --- a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/TemplateStoredProcedureFactory.java +++ b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/TemplateStoredProcedureFactory.java @@ -1,5 +1,23 @@ +/** + * 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.template; +import java.io.StringReader; + import org.apache.camel.component.sql.stored.template.ast.ParseRuntimeException; import org.apache.camel.component.sql.stored.template.ast.Template; import org.apache.camel.component.sql.stored.template.generated.ParseException; @@ -7,17 +25,11 @@ import org.apache.camel.component.sql.stored.template.generated.SSPTParser; import org.apache.camel.util.LRUCache; import org.springframework.jdbc.core.JdbcTemplate; -import javax.sql.DataSource; -import java.io.StringReader; - public class TemplateStoredProcedureFactory { - final int TEMPLATE_CACHE_DEFAULT_SIZE = 200; - - final JdbcTemplate jdbcTemplate; - - LRUCache templateCache = new LRUCache(200); - + private final int TEMPLATE_CACHE_DEFAULT_SIZE = 200; + private final JdbcTemplate jdbcTemplate; + private LRUCache templateCache = new LRUCache(200); public TemplateStoredProcedureFactory(JdbcTemplate jdbcTemplate) { this.jdbcTemplate = jdbcTemplate; @@ -36,12 +48,10 @@ public class TemplateStoredProcedureFactory { templateCache.put(string, ret); return ret; - } public Template parseTemplate(String template) { try { - SSPTParser parser = new SSPTParser(new StringReader(template)); return validate(parser.parse()); } catch (ParseException parseException) { @@ -50,9 +60,7 @@ public class TemplateStoredProcedureFactory { } private Template validate(Template input) { - //TODO:remove validation ? return input; } - } http://git-wip-us.apache.org/repos/asf/camel/blob/0dcd69af/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/ast/InputParameter.java ---------------------------------------------------------------------- diff --git a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/ast/InputParameter.java b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/ast/InputParameter.java index 69a9703..68927a2 100644 --- a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/ast/InputParameter.java +++ b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/ast/InputParameter.java @@ -1,19 +1,30 @@ +/** + * 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.template.ast; import org.apache.camel.Expression; import org.apache.camel.builder.ExpressionBuilder; - public class InputParameter { - String name; - - int sqlType; - - Expression valueExpression; - - Class javaType; - + private final String name; + private final int sqlType; + private final Expression valueExpression; + private final Class javaType; public InputParameter(String name, int sqlType, String valueSrcAsStr, Class javaType) { this.name = name; @@ -22,7 +33,6 @@ public class InputParameter { this.valueExpression = parseValueExpression(valueSrcAsStr); } - private Expression parseValueExpression(String str) { return ExpressionBuilder.simpleExpression(str); } @@ -43,5 +53,4 @@ public class InputParameter { return javaType; } - } http://git-wip-us.apache.org/repos/asf/camel/blob/0dcd69af/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/ast/OutParameter.java ---------------------------------------------------------------------- diff --git a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/ast/OutParameter.java b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/ast/OutParameter.java index 2182bd7..f01bf57 100644 --- a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/ast/OutParameter.java +++ b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/ast/OutParameter.java @@ -1,17 +1,26 @@ -package org.apache.camel.component.sql.stored.template.ast; - /** - * Created by snurmine on 12/20/15. + * 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. */ -public class OutParameter { - - - String name; - - int sqlType; +package org.apache.camel.component.sql.stored.template.ast; - String outHeader; +public class OutParameter { + private String name; + private int sqlType; + private String outHeader; public OutParameter(String name, int sqlType, String outHeader) { this.name = name; http://git-wip-us.apache.org/repos/asf/camel/blob/0dcd69af/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/ast/ParseHelper.java ---------------------------------------------------------------------- diff --git a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/ast/ParseHelper.java b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/ast/ParseHelper.java index e84c7a9..8e88691 100644 --- a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/ast/ParseHelper.java +++ b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/ast/ParseHelper.java @@ -1,12 +1,27 @@ +/** + * 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.template.ast; -import org.springframework.util.ReflectionUtils; - import java.lang.reflect.Field; import java.math.BigInteger; import java.sql.Date; import java.sql.Types; +import org.springframework.util.ReflectionUtils; public class ParseHelper { @@ -49,10 +64,11 @@ public class ParseHelper { ret = Date.class; break; } + if (ret == null) { throw new ParseRuntimeException("Unable to map SQL type " + sqlTypeStr + " to Java type"); - } return ret; } + } http://git-wip-us.apache.org/repos/asf/camel/blob/0dcd69af/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/ast/ParseRuntimeException.java ---------------------------------------------------------------------- diff --git a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/ast/ParseRuntimeException.java b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/ast/ParseRuntimeException.java index b3b8fc8..80fe52c 100644 --- a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/ast/ParseRuntimeException.java +++ b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/ast/ParseRuntimeException.java @@ -1,8 +1,5 @@ package org.apache.camel.component.sql.stored.template.ast; -/** - * Created by snurmine on 1/3/16. - */ public class ParseRuntimeException extends RuntimeException { public ParseRuntimeException(String message) { super(message); http://git-wip-us.apache.org/repos/asf/camel/blob/0dcd69af/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/ast/Template.java ---------------------------------------------------------------------- diff --git a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/ast/Template.java b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/ast/Template.java index b442fde..935609c 100644 --- a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/ast/Template.java +++ b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/ast/Template.java @@ -1,3 +1,19 @@ +/** + * 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.template.ast; import java.util.ArrayList; @@ -8,19 +24,15 @@ import java.util.List; */ public class Template { - String procedureName; - - List inputParameterList = new ArrayList<>(); - - List outParameterList = new ArrayList<>(); + private String procedureName; + private final List inputParameterList = new ArrayList<>(); + private final List outParameterList = new ArrayList<>(); public void addParameter(Object parameter) { - if (parameter instanceof OutParameter) { outParameterList.add((OutParameter) parameter); } else { inputParameterList.add((InputParameter) parameter); - } } http://git-wip-us.apache.org/repos/asf/camel/blob/0dcd69af/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/ParserTest.java ---------------------------------------------------------------------- diff --git a/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/ParserTest.java b/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/ParserTest.java index 9982138..1141886 100644 --- a/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/ParserTest.java +++ b/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/ParserTest.java @@ -1,29 +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.math.BigInteger; +import java.sql.Types; import org.apache.camel.Exchange; +import org.apache.camel.component.sql.stored.template.TemplateStoredProcedureFactory; import org.apache.camel.component.sql.stored.template.ast.InputParameter; import org.apache.camel.component.sql.stored.template.ast.OutParameter; import org.apache.camel.component.sql.stored.template.ast.ParseRuntimeException; import org.apache.camel.component.sql.stored.template.ast.Template; -import org.apache.camel.component.sql.stored.template.TemplateStoredProcedureFactory; -import org.apache.camel.component.sql.stored.template.generated.ParseException; import org.apache.camel.test.junit4.CamelTestSupport; import org.junit.Assert; import org.junit.Test; -import java.math.BigInteger; -import java.sql.Types; - public class ParserTest extends CamelTestSupport { TemplateStoredProcedureFactory parser = new TemplateStoredProcedureFactory(null); - @Test public void shouldParseOk() { - - Template template = parser.parseTemplate("addnumbers(INTEGER ${header.header1}," + "VARCHAR ${property.property1},BIGINT ${header.header2},OUT INTEGER header1)"); @@ -54,10 +65,8 @@ public class ParserTest extends CamelTestSupport { Assert.assertEquals("_3", sptpOutputNode.getName()); Assert.assertEquals(Types.INTEGER, sptpOutputNode.getSqlType()); Assert.assertEquals("header1", sptpOutputNode.getOutHeader()); - } - @Test(expected = ParseRuntimeException.class) public void noOutputParameterShouldFail() { parser.parseTemplate("ADDNUMBERS2" + @@ -69,15 +78,12 @@ public class ParserTest extends CamelTestSupport { public void unexistingTypeShouldFail() { parser.parseTemplate("ADDNUMBERS2" + "(XML VALUE1 ${header.v1},OUT INTEGER VALUE2 ${header.v2})"); - } - @Test(expected = ParseRuntimeException.class) public void unmappedTypeShouldFaild() { parser.parseTemplate("ADDNUMBERS2" + "(OTHER VALUE1 ${header.v1},INTEGER VALUE2 ${header.v2})"); - } } http://git-wip-us.apache.org/repos/asf/camel/blob/0dcd69af/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 f7efd87..19a8089 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 @@ -1,9 +1,27 @@ +/** + * 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.util.HashMap; +import java.util.Map; + import org.apache.camel.Exchange; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.component.sql.SqlComponent; import org.apache.camel.test.junit4.CamelTestSupport; import org.junit.After; import org.junit.Before; @@ -12,30 +30,20 @@ import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; -import java.util.HashMap; -import java.util.Map; - -/** - * Created by snurmine on 12/30/15. - */ public class ProducerTest extends CamelTestSupport { - private EmbeddedDatabase db; - @Before public void setUp() throws Exception { db = new EmbeddedDatabaseBuilder() .setType(EmbeddedDatabaseType.DERBY).addScript("sql/storedProcedureTest.sql").build(); - super.setUp(); } @After public void tearDown() throws Exception { super.tearDown(); - db.shutdown(); } @@ -70,4 +78,5 @@ public class ProducerTest extends CamelTestSupport { } }; } + } http://git-wip-us.apache.org/repos/asf/camel/blob/0dcd69af/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/TemplateStoredProcedureTest.java ---------------------------------------------------------------------- diff --git a/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/TemplateStoredProcedureTest.java b/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/TemplateStoredProcedureTest.java index 3b06390..f92f7df 100644 --- a/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/TemplateStoredProcedureTest.java +++ b/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/TemplateStoredProcedureTest.java @@ -1,6 +1,21 @@ +/** + * 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.Exchange; import org.apache.camel.component.sql.stored.template.TemplateStoredProcedure; import org.apache.camel.component.sql.stored.template.TemplateStoredProcedureFactory; @@ -16,8 +31,7 @@ import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; public class TemplateStoredProcedureTest extends CamelTestSupport { - TemplateStoredProcedureFactory parser; - + private TemplateStoredProcedureFactory parser; private EmbeddedDatabase db; private JdbcTemplate jdbcTemplate; @@ -25,12 +39,8 @@ public class TemplateStoredProcedureTest extends CamelTestSupport { public void setUp() throws Exception { db = new EmbeddedDatabaseBuilder() .setType(EmbeddedDatabaseType.DERBY).addScript("sql/storedProcedureTest.sql").build(); - jdbcTemplate = new JdbcTemplate(db); - - parser = new TemplateStoredProcedureFactory(jdbcTemplate); - super.setUp(); } @@ -44,32 +54,26 @@ public class TemplateStoredProcedureTest extends CamelTestSupport { exchange.getIn().setHeader("v1", 1); exchange.getIn().setHeader("v2", 2); - sp.execute(exchange); Assert.assertEquals(Integer.valueOf(3), exchange.getOut().getHeader("resultofsum")); - - } - @Test public void shouldExecuteNilacidProcedure() { - TemplateStoredProcedure sp = new TemplateStoredProcedure(jdbcTemplate, parser.parseTemplate("NILADIC" + - "()")); + TemplateStoredProcedure sp = new TemplateStoredProcedure(jdbcTemplate, parser.parseTemplate("NILADIC()")); Exchange exchange = createExchangeWithBody(null); exchange.getIn().setHeader("v1", 1); exchange.getIn().setHeader("v2", 2); - sp.execute(exchange); } @After public void tearDown() throws Exception { super.tearDown(); - db.shutdown(); } + } http://git-wip-us.apache.org/repos/asf/camel/blob/0dcd69af/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/TestStoredProcedure.java ---------------------------------------------------------------------- diff --git a/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/TestStoredProcedure.java b/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/TestStoredProcedure.java index cc514e3..cf05611 100644 --- a/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/TestStoredProcedure.java +++ b/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/TestStoredProcedure.java @@ -1,24 +1,35 @@ +/** + * 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.slf4j.Logger; import org.slf4j.LoggerFactory; -/** - * Created by snurmine on 12/20/15. - */ public class TestStoredProcedure { private static final Logger LOG = LoggerFactory.getLogger(TestStoredProcedure.class); - public static void addnumbers(int val1, int val2, int[] ret) { LOG.info("calling addnumbers:{} + {}", val1, val2); - ret[0] = val1 + val2; - } public static void niladic() { LOG.info("nilacid called"); } + }