camel-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Willem Jiang <willem.ji...@gmail.com>
Subject Re: svn commit: r980675 - in /camel/trunk/components/camel-josql: ./ src/main/java/org/apache/camel/language/ src/main/java/org/apache/camel/language/sql/ src/main/resources/META-INF/services/ src/main/resources/META-INF/services/org/ src/main/resour
Date Fri, 30 Jul 2010 08:45:27 GMT
Well spot, I will change it in my next commit.

Willem
Claus Ibsen wrote:
> SqlLanguage should be singleton as it doesnt store any internal state
> 
> +    public boolean isSingleton() {
> +        return false;
> +    }
> 
> Should return true;
> 
> 
> 
> On Fri, Jul 30, 2010 at 10:22 AM,  <ningjiang@apache.org> wrote:
>> Author: ningjiang
>> Date: Fri Jul 30 08:22:09 2010
>> New Revision: 980675
>>
>> URL: http://svn.apache.org/viewvc?rev=980675&view=rev
>> Log:
>> CAMEL-3014 camel-josql should have SQL language META-INF which can be found automatically
by camel-core
>>
>> Added:
>>    camel/trunk/components/camel-josql/src/main/java/org/apache/camel/language/
>>    camel/trunk/components/camel-josql/src/main/java/org/apache/camel/language/sql/
>>    camel/trunk/components/camel-josql/src/main/java/org/apache/camel/language/sql/SqlLanguage.java
  (with props)
>>    camel/trunk/components/camel-josql/src/main/resources/META-INF/services/
>>    camel/trunk/components/camel-josql/src/main/resources/META-INF/services/org/
>>    camel/trunk/components/camel-josql/src/main/resources/META-INF/services/org/apache/
>>    camel/trunk/components/camel-josql/src/main/resources/META-INF/services/org/apache/camel/
>>    camel/trunk/components/camel-josql/src/main/resources/META-INF/services/org/apache/camel/language/
>>    camel/trunk/components/camel-josql/src/main/resources/META-INF/services/org/apache/camel/language/sql
>>    camel/trunk/components/camel-josql/src/test/java/org/apache/camel/lanaguage/
>>    camel/trunk/components/camel-josql/src/test/java/org/apache/camel/lanaguage/sql/
>>    camel/trunk/components/camel-josql/src/test/java/org/apache/camel/lanaguage/sql/SqlLanguageTest.java
  (with props)
>> Modified:
>>    camel/trunk/components/camel-josql/pom.xml
>>    camel/trunk/components/camel-josql/src/test/java/org/apache/camel/builder/sql/SqlTest.java
>>
>> Modified: camel/trunk/components/camel-josql/pom.xml
>> URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-josql/pom.xml?rev=980675&r1=980674&r2=980675&view=diff
>> ==============================================================================
>> --- camel/trunk/components/camel-josql/pom.xml (original)
>> +++ camel/trunk/components/camel-josql/pom.xml Fri Jul 30 08:22:09 2010
>> @@ -64,7 +64,13 @@
>>
>>     <dependency>
>>       <groupId>commons-logging</groupId>
>> -      <artifactId>commons-logging-api</artifactId>
>> +      <artifactId>commons-logging</artifactId>
>> +      <scope>test</scope>
>> +    </dependency>
>> +    <dependency>
>> +      <groupId>log4j</groupId>
>> +      <artifactId>log4j</artifactId>
>> +      <scope>test</scope>
>>     </dependency>
>>
>>     <dependency>
>>
>> Added: camel/trunk/components/camel-josql/src/main/java/org/apache/camel/language/sql/SqlLanguage.java
>> URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-josql/src/main/java/org/apache/camel/language/sql/SqlLanguage.java?rev=980675&view=auto
>> ==============================================================================
>> --- camel/trunk/components/camel-josql/src/main/java/org/apache/camel/language/sql/SqlLanguage.java
(added)
>> +++ camel/trunk/components/camel-josql/src/main/java/org/apache/camel/language/sql/SqlLanguage.java
Fri Jul 30 08:22:09 2010
>> @@ -0,0 +1,61 @@
>> +/**
>> + * 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.language.sql;
>> +
>> +import javax.xml.namespace.QName;
>> +
>> +import org.apache.camel.Expression;
>> +import org.apache.camel.IsSingleton;
>> +import org.apache.camel.Predicate;
>> +import org.apache.camel.RuntimeCamelException;
>> +import org.apache.camel.builder.sql.SqlBuilder;
>> +import org.apache.camel.builder.xml.XPathBuilder;
>> +import org.apache.camel.spi.Language;
>> +import org.josql.QueryParseException;
>> +
>> +/**
>> + * XPath language.
>> + *
>> + * @version $Revision$
>> + */
>> +public class SqlLanguage implements Language, IsSingleton {
>> +
>> +    public Predicate createPredicate(String expression) {
>> +        try {
>> +            SqlBuilder builder = SqlBuilder.sql(expression);
>> +            return builder;
>> +        } catch (QueryParseException e) {
>> +            RuntimeException exception = new RuntimeCamelException("Canont create
the SqlBuilder.", e);
>> +            throw exception;
>> +        }
>> +
>> +    }
>> +
>> +    public Expression createExpression(String expression) {
>> +        try {
>> +            SqlBuilder builder = SqlBuilder.sql(expression);
>> +            return builder;
>> +        } catch (QueryParseException e) {
>> +            RuntimeException exception = new RuntimeCamelException("Canont create
the SqlBuilder.", e);
>> +            throw exception;
>> +        }
>> +    }
>> +
>> +    public boolean isSingleton() {
>> +        return false;
>> +    }
>> +}
>>
>> Propchange: camel/trunk/components/camel-josql/src/main/java/org/apache/camel/language/sql/SqlLanguage.java
>> ------------------------------------------------------------------------------
>>    svn:eol-style = native
>>
>> Propchange: camel/trunk/components/camel-josql/src/main/java/org/apache/camel/language/sql/SqlLanguage.java
>> ------------------------------------------------------------------------------
>>    svn:keywords = Rev Date
>>
>> Added: camel/trunk/components/camel-josql/src/main/resources/META-INF/services/org/apache/camel/language/sql
>> URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-josql/src/main/resources/META-INF/services/org/apache/camel/language/sql?rev=980675&view=auto
>> ==============================================================================
>> --- camel/trunk/components/camel-josql/src/main/resources/META-INF/services/org/apache/camel/language/sql
(added)
>> +++ camel/trunk/components/camel-josql/src/main/resources/META-INF/services/org/apache/camel/language/sql
Fri Jul 30 08:22:09 2010
>> @@ -0,0 +1,18 @@
>> +#
>> +# 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.
>> +#
>> +
>> +class=org.apache.camel.language.sql.SqlLanguage
>>
>> Modified: camel/trunk/components/camel-josql/src/test/java/org/apache/camel/builder/sql/SqlTest.java
>> URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-josql/src/test/java/org/apache/camel/builder/sql/SqlTest.java?rev=980675&r1=980674&r2=980675&view=diff
>> ==============================================================================
>> --- camel/trunk/components/camel-josql/src/test/java/org/apache/camel/builder/sql/SqlTest.java
(original)
>> +++ camel/trunk/components/camel-josql/src/test/java/org/apache/camel/builder/sql/SqlTest.java
Fri Jul 30 08:22:09 2010
>> @@ -24,6 +24,7 @@ import org.apache.camel.Expression;
>>  import org.apache.camel.Message;
>>  import org.apache.camel.impl.DefaultCamelContext;
>>  import org.apache.camel.impl.DefaultExchange;
>> +import org.apache.camel.test.junit4.CamelTestSupport;
>>  import org.apache.camel.test.junit4.TestSupport;
>>  import org.junit.Before;
>>  import org.junit.Test;
>> @@ -33,9 +34,9 @@ import static org.apache.camel.builder.s
>>  /**
>>  * @version $Revision$
>>  */
>> -public class SqlTest extends TestSupport {
>> +public class SqlTest extends CamelTestSupport {
>>
>> -    protected CamelContext context = new DefaultCamelContext();
>> +    //protected CamelContext context = new DefaultCamelContext();
>>     protected Exchange exchange;
>>
>>     @Test
>> @@ -79,7 +80,8 @@ public class SqlTest extends TestSupport
>>     }
>>
>>     @Before
>> -    public void setUp() throws Exception {
>> +    public void setUp() throws Exception {
>> +        super.setUp();
>>         exchange = createExchange();
>>     }
>>
>>
>> Added: camel/trunk/components/camel-josql/src/test/java/org/apache/camel/lanaguage/sql/SqlLanguageTest.java
>> URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-josql/src/test/java/org/apache/camel/lanaguage/sql/SqlLanguageTest.java?rev=980675&view=auto
>> ==============================================================================
>> --- camel/trunk/components/camel-josql/src/test/java/org/apache/camel/lanaguage/sql/SqlLanguageTest.java
(added)
>> +++ camel/trunk/components/camel-josql/src/test/java/org/apache/camel/lanaguage/sql/SqlLanguageTest.java
Fri Jul 30 08:22:09 2010
>> @@ -0,0 +1,82 @@
>> +/**
>> + * 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.lanaguage.sql;
>> +
>> +import java.util.List;
>> +
>> +import org.apache.camel.Expression;
>> +import org.apache.camel.builder.sql.Person;
>> +import org.apache.camel.builder.sql.SqlTest;
>> +import org.apache.camel.spi.Language;
>> +import org.junit.Test;
>> +
>> +/**
>> + * @version $Revision$
>> + */
>> +public class SqlLanguageTest extends SqlTest {
>> +
>> +    @Test
>> +    public void testExpression() throws Exception {
>> +        Language language = assertResolveLanguage(getLanguageName());
>> +
>> +        Expression expression = language.createExpression("SELECT * FROM org.apache.camel.builder.sql.Person
where city = 'London'");
>> +        List value = expression.evaluate(exchange, List.class);
>> +
>> +        List list = (List)value;
>> +        assertEquals("List size", 2, list.size());
>> +
>> +        for (Object person : list) {
>> +            log.info("Found: " + person);
>> +        }
>> +    }
>> +
>> +    @SuppressWarnings("unchecked")
>> +    @Test
>> +    public void testExpressionWithHeaderVariable() throws Exception {
>> +        Language language = assertResolveLanguage(getLanguageName());
>> +
>> +        Expression expression = language.createExpression("SELECT * FROM org.apache.camel.builder.sql.Person
where name = :fooHeader");
>> +        List value = expression.evaluate(exchange, List.class);
>> +
>> +        List<Person> list = (List<Person>)value;
>> +        assertEquals("List size", 1, list.size());
>> +
>> +        for (Person person : list) {
>> +            log.info("Found: " + person);
>> +
>> +            assertEquals("name", "James", person.getName());
>> +        }
>> +    }
>> +
>> +    @Test
>> +    public void testPredicates() throws Exception {
>> +        Language language = assertResolveLanguage(getLanguageName());
>> +        assertPredicate(language.createPredicate("SELECT * FROM org.apache.camel.builder.sql.Person
where city = 'London'"), exchange, true);
>> +        assertPredicate(language.createPredicate("SELECT * FROM org.apache.camel.builder.sql.Person
where city = 'Manchester'"), exchange, false);
>> +    }
>> +
>> +    @Test
>> +    public void testPredicateWithHeaderVariable() throws Exception {
>> +        Language language = assertResolveLanguage(getLanguageName());
>> +        assertPredicate(language.createPredicate("SELECT * FROM org.apache.camel.builder.sql.Person
where name = :fooHeader"), exchange, true);
>> +    }
>> +
>> +    protected String getLanguageName() {
>> +        return "sql";
>> +    }
>> +
>> +}
>>
>> Propchange: camel/trunk/components/camel-josql/src/test/java/org/apache/camel/lanaguage/sql/SqlLanguageTest.java
>> ------------------------------------------------------------------------------
>>    svn:eol-style = native
>>
>> Propchange: camel/trunk/components/camel-josql/src/test/java/org/apache/camel/lanaguage/sql/SqlLanguageTest.java
>> ------------------------------------------------------------------------------
>>    svn:keywords = Rev Date
>>
>>
>>
> 
> 
> 


Mime
View raw message