camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r773359 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/model/ components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/ components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/ components/camel-i...
Date Sun, 10 May 2009 16:21:39 GMT
Author: davsclaus
Date: Sun May 10 16:21:38 2009
New Revision: 773359

URL: http://svn.apache.org/viewvc?rev=773359&view=rev
Log:
CAMEL-1596: Added statementType option to control which SqlMapClient method to invoke.

Added:
    camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/StatementType.java
  (with props)
    camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueryForDeleteTest.java
  (with props)
    camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueryForInsertTest.java
  (with props)
    camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueryForListTest.java
  (with props)
    camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueryForListWithSplitTest.java
  (with props)
    camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueryForObjectTest.java
  (with props)
    camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueryForUpdateTest.java
  (with props)
    camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisTestSupport.java
  (with props)
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/model/AsyncDefinition.java
    camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisEndpoint.java
    camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisProducer.java
    camel/trunk/components/camel-ibatis/src/test/resources/log4j.properties
    camel/trunk/components/camel-ibatis/src/test/resources/org/apache/camel/component/ibatis/Account.xml

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/AsyncDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/AsyncDefinition.java?rev=773359&r1=773358&r2=773359&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/AsyncDefinition.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/AsyncDefinition.java Sun May
10 16:21:38 2009
@@ -97,7 +97,7 @@
     /**
      * Setting to whether to wait for async tasks to be complete before continuing original
route.
      * <p/>
-     * Is default <tt>true</tt>
+     * Is default <tt>IfReplyExpected</tt>
      *
      * @param wait the wait option
      * @return the builder

Modified: camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisEndpoint.java?rev=773359&r1=773358&r2=773359&view=diff
==============================================================================
--- camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisEndpoint.java
(original)
+++ camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisEndpoint.java
Sun May 10 16:21:38 2009
@@ -35,6 +35,7 @@
     private IBatisProcessingStrategy strategy;
     private boolean useTransactions;
     private String statement;
+    private StatementType statementType = StatementType.Default;
 
     public IBatisEndpoint() {
     }
@@ -115,4 +116,11 @@
         this.useTransactions = useTransactions;
     }
 
+    public StatementType getStatementType() {
+        return statementType;
+    }
+
+    public void setStatementType(StatementType statementType) {
+        this.statementType = statementType;
+    }
 }

Modified: camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisProducer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisProducer.java?rev=773359&r1=773358&r2=773359&view=diff
==============================================================================
--- camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisProducer.java
(original)
+++ camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisProducer.java
Sun May 10 16:21:38 2009
@@ -17,10 +17,8 @@
 package org.apache.camel.component.ibatis;
 
 import java.util.Iterator;
-import java.util.List;
 
 import com.ibatis.sqlmap.client.SqlMapClient;
-
 import org.apache.camel.Exchange;
 import org.apache.camel.Message;
 import org.apache.camel.impl.DefaultProducer;
@@ -46,27 +44,153 @@
      * Calls insert on the SqlMapClient.
      */
     public void process(Exchange exchange) throws Exception {
-        SqlMapClient client = endpoint.getSqlMapClient();
+        switch (endpoint.getStatementType()) {
+        case QueryForObject:
+            doQueryForObject(exchange); break;
+        case QueryForList:
+            doQueryForList(exchange); break;
+        case Insert:
+            doInsert(exchange); break;
+        case Update:
+            doUpdate(exchange); break;
+        case Delete:
+            doDelete(exchange); break;
+        case Default:
+            doDefault(exchange); break;
+        default:
+            doDefault(exchange); break;
+        }
+    }
+
+    private void doDefault(Exchange exchange) throws Exception {
         Object body = exchange.getIn().getBody();
         if (ObjectHelper.isEmpty(body)) {
             // must be a poll so lets do a query
-            Message msg = exchange.getOut();
+            doQueryForList(exchange);
+        } else {
+            // otherwise we insert
+            doInsert(exchange);
+        }
+    }
+
+    private void doQueryForObject(Exchange exchange) throws Exception {
+        SqlMapClient client = endpoint.getSqlMapClient();
+
+        Object result;
+        Object in = exchange.getIn().getBody();
+        if (in != null) {
+            if (LOG.isTraceEnabled()) {
+                LOG.trace("QueryForObject: " + in + "  using statement: " + statement);
+            }
+            result = client.queryForObject(statement, in);
+        } else {
+            if (LOG.isTraceEnabled()) {
+                LOG.trace("QueryForObject using statement: " + statement);
+            }
+            result = client.queryForObject(statement);
+        }
+
+        doProcessResult(exchange, result);
+    }
+
+    private void doQueryForList(Exchange exchange) throws Exception {
+        SqlMapClient client = endpoint.getSqlMapClient();
+
+        Object result;
+        Object in = exchange.getIn().getBody();
+        if (in != null) {
             if (LOG.isTraceEnabled()) {
-                LOG.trace("Querying for list: " + statement);
+                LOG.trace("QueryForList: " + in + "  using statement: " + statement);
             }
-            List list = client.queryForList(statement);
-            msg.setBody(list);
-            msg.setHeader(IBatisConstants.IBATIS_STATEMENT_NAME, statement);
+            result = client.queryForList(statement, in);
         } else {
+            if (LOG.isTraceEnabled()) {
+                LOG.trace("QueryForList using statement: " + statement);
+            }
+            result = client.queryForList(statement);
+        }
+
+        doProcessResult(exchange, result);
+    }
+
+    private void doInsert(Exchange exchange) throws Exception {
+        SqlMapClient client = endpoint.getSqlMapClient();
+
+        Object result;
+        Object in = exchange.getIn().getBody();
+        if (in != null) {
             // lets handle arrays or collections of objects
-            Iterator iter = ObjectHelper.createIterator(body);
+            Iterator iter = ObjectHelper.createIterator(in);
             while (iter.hasNext()) {
                 Object value = iter.next();
                 if (LOG.isTraceEnabled()) {
                     LOG.trace("Inserting: " + value + " using statement: " + statement);
                 }
-                client.insert(statement, value);
+                result = client.insert(statement, value);
+                doProcessResult(exchange, result);
             }
+        } else {
+            if (LOG.isTraceEnabled()) {
+                LOG.trace("Inserting using statement: " + statement);
+            }
+            result = client.insert(statement);
+            doProcessResult(exchange, result);
+        }
+    }
+
+    private void doUpdate(Exchange exchange) throws Exception {
+        SqlMapClient client = endpoint.getSqlMapClient();
+
+        Object result;
+        Object in = exchange.getIn().getBody();
+        if (in != null) {
+            // lets handle arrays or collections of objects
+            Iterator iter = ObjectHelper.createIterator(in);
+            while (iter.hasNext()) {
+                Object value = iter.next();
+                if (LOG.isTraceEnabled()) {
+                    LOG.trace("Updating: " + value + " using statement: " + statement);
+                }
+                result = client.update(statement, value);
+                doProcessResult(exchange, result);
+            }
+        } else {
+            if (LOG.isTraceEnabled()) {
+                LOG.trace("Updating using statement: " + statement);
+            }
+            result = client.update(statement);
+            doProcessResult(exchange, result);
         }
     }
+
+    private void doDelete(Exchange exchange) throws Exception {
+        SqlMapClient client = endpoint.getSqlMapClient();
+
+        Object result;
+        Object in = exchange.getIn().getBody();
+        if (in != null) {
+            // lets handle arrays or collections of objects
+            Iterator iter = ObjectHelper.createIterator(in);
+            while (iter.hasNext()) {
+                Object value = iter.next();
+                if (LOG.isTraceEnabled()) {
+                    LOG.trace("Deleting: " + value + " using statement: " + statement);
+                }
+                result = client.delete(statement, value);
+                doProcessResult(exchange, result);
+            }
+        } else {
+            if (LOG.isTraceEnabled()) {
+                LOG.trace("Deleting using statement: " + statement);
+            }
+            result = client.delete(statement);
+            doProcessResult(exchange, result);
+        }
+    }
+
+    private void doProcessResult(Exchange exchange, Object result) {
+        Message msg = exchange.getOut();
+        msg.setBody(result);
+        msg.setHeader(IBatisConstants.IBATIS_STATEMENT_NAME, statement);
+    }
 }

Added: camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/StatementType.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/StatementType.java?rev=773359&view=auto
==============================================================================
--- camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/StatementType.java
(added)
+++ camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/StatementType.java
Sun May 10 16:21:38 2009
@@ -0,0 +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.ibatis;
+
+/**
+ * Statement types to instruct which iBatis operation to use.
+ * <p/>
+ * Default will use the default Behavior in Camel: No body then <tt>QueryForList</tt>
is used, otherwise
+ * <tt>Insert</tt> is used.
+ *
+ * @version $Revision$
+ */
+public enum StatementType {
+
+    QueryForObject, QueryForList, Insert, Update, Delete, Default
+}

Propchange: camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/StatementType.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/StatementType.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueryForDeleteTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueryForDeleteTest.java?rev=773359&view=auto
==============================================================================
--- camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueryForDeleteTest.java
(added)
+++ camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueryForDeleteTest.java
Sun May 10 16:21:38 2009
@@ -0,0 +1,71 @@
+/**
+ * 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.ibatis;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ * @version $Revision$
+ */
+public class IBatisQueryForDeleteTest extends IBatisTestSupport {
+
+    public void testDelete() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMessageCount(1);
+
+        template.sendBody("direct:start", 456);
+
+        assertMockEndpointsSatisfied();
+
+        // there should be 1 rows now
+        Integer rows = template.requestBody("ibatis:count?statementType=QueryForObject",
null, Integer.class);
+        assertEquals("There should be 1 rows", 1, rows.intValue());
+
+        template.sendBody("direct:start", 123);
+
+        // there should be 0 rows now
+        rows = template.requestBody("ibatis:count?statementType=QueryForObject", null, Integer.class);
+        assertEquals("There should be 0 rows", 0, rows.intValue());
+    }
+
+    public void testDeleteNotFound() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMessageCount(1);
+
+        template.sendBody("direct:start", 999);
+
+        assertMockEndpointsSatisfied();
+
+        // there should be 2 rows now
+        Integer rows = template.requestBody("ibatis:count?statementType=QueryForObject",
null, Integer.class);
+        assertEquals("There should be 2 rows", 2, rows.intValue());
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start")
+                    .to("ibatis:deleteAccountById?statementType=Delete")
+                    .to("mock:result");
+            }
+        };
+    }
+
+}
\ No newline at end of file

Propchange: camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueryForDeleteTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueryForDeleteTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueryForInsertTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueryForInsertTest.java?rev=773359&view=auto
==============================================================================
--- camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueryForInsertTest.java
(added)
+++ camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueryForInsertTest.java
Sun May 10 16:21:38 2009
@@ -0,0 +1,58 @@
+/**
+ * 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.ibatis;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ * @version $Revision$
+ */
+public class IBatisQueryForInsertTest extends IBatisTestSupport {
+
+    public void testInsert() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMessageCount(1);
+
+        Account account = new Account();
+        account.setId(444);
+        account.setFirstName("Willem");
+        account.setLastName("Jiang");
+        account.setEmailAddress("Faraway@gmail.com");
+
+        template.sendBody("direct:start", account);
+
+        assertMockEndpointsSatisfied();
+
+        // there should be 3 rows now
+        Integer rows = template.requestBody("ibatis:count?statementType=QueryForObject",
null, Integer.class);
+        assertEquals("There should be 3 rows", 3, rows.intValue());
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start")
+                    .to("ibatis:insertAccount?statementType=Insert")
+                    .to("mock:result");
+            }
+        };
+    }
+
+}
\ No newline at end of file

Propchange: camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueryForInsertTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueryForInsertTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueryForListTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueryForListTest.java?rev=773359&view=auto
==============================================================================
--- camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueryForListTest.java
(added)
+++ camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueryForListTest.java
Sun May 10 16:21:38 2009
@@ -0,0 +1,58 @@
+/**
+ * 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.ibatis;
+
+import java.util.List;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ * @version $Revision$
+ */
+public class IBatisQueryForListTest extends IBatisTestSupport {
+
+    public void testQueryForList() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMessageCount(1);
+
+        template.sendBody("direct:start", null);
+
+        assertMockEndpointsSatisfied();
+
+        List list = mock.getReceivedExchanges().get(0).getIn().getBody(List.class);
+        Account james = (Account) list.get(0);
+        Account claus = (Account) list.get(1);
+        assertEquals("James", james.getFirstName());
+        assertEquals("Claus", claus.getFirstName());
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                // START SNIPPET: e1
+                from("direct:start")
+                    .to("ibatis:selectAllAccounts?statementType=QueryForList")
+                    .to("mock:result");
+                // END SNIPPET: e1
+            }
+        };
+    }
+
+}
\ No newline at end of file

Propchange: camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueryForListTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueryForListTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueryForListWithSplitTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueryForListWithSplitTest.java?rev=773359&view=auto
==============================================================================
--- camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueryForListWithSplitTest.java
(added)
+++ camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueryForListWithSplitTest.java
Sun May 10 16:21:38 2009
@@ -0,0 +1,57 @@
+/**
+ * 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.ibatis;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ * @version $Revision$
+ */
+public class IBatisQueryForListWithSplitTest extends IBatisTestSupport {
+
+    public void testQueryForList() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMessageCount(2);
+
+        template.sendBody("direct:start", null);
+
+        assertMockEndpointsSatisfied();
+
+        Account james = mock.getReceivedExchanges().get(0).getIn().getBody(Account.class);
+        Account claus = mock.getReceivedExchanges().get(1).getIn().getBody(Account.class);
+        assertEquals("James", james.getFirstName());
+        assertEquals("Claus", claus.getFirstName());
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                // START SNIPPET: e1
+                from("direct:start")
+                    .to("ibatis:selectAllAccounts?statementType=QueryForList")
+                    // just use split body to split the List into individual objects
+                    .split(body())
+                    .to("mock:result");
+                // END SNIPPET: e1
+            }
+        };
+    }
+
+}
\ No newline at end of file

Propchange: camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueryForListWithSplitTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueryForListWithSplitTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueryForObjectTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueryForObjectTest.java?rev=773359&view=auto
==============================================================================
--- camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueryForObjectTest.java
(added)
+++ camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueryForObjectTest.java
Sun May 10 16:21:38 2009
@@ -0,0 +1,64 @@
+/**
+ * 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.ibatis;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ * @version $Revision$
+ */
+public class IBatisQueryForObjectTest extends IBatisTestSupport {
+
+    public void testQueryForObject() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMessageCount(1);
+        mock.message(0).body().isInstanceOf(Account.class);
+
+        template.sendBody("direct:start", 456);
+
+        assertMockEndpointsSatisfied();
+
+        Account account = mock.getReceivedExchanges().get(0).getIn().getBody(Account.class);
+        assertEquals("Claus", account.getFirstName());
+    }
+
+    public void testQueryForNotFound() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMessageCount(1);
+        mock.message(0).body().isNull();
+
+        template.sendBody("direct:start", 999);
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                // START SNIPPET: e1
+                from("direct:start")
+                    .to("ibatis:selectAccountById?statementType=QueryForObject")
+                    .to("mock:result");
+                // END SNIPPET: e1
+            }
+        };
+    }
+
+}

Propchange: camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueryForObjectTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueryForObjectTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueryForUpdateTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueryForUpdateTest.java?rev=773359&view=auto
==============================================================================
--- camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueryForUpdateTest.java
(added)
+++ camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueryForUpdateTest.java
Sun May 10 16:21:38 2009
@@ -0,0 +1,65 @@
+/**
+ * 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.ibatis;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ * @version $Revision$
+ */
+public class IBatisQueryForUpdateTest extends IBatisTestSupport {
+
+    public void testUpdate() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMessageCount(1);
+
+        Account account = new Account();
+        account.setId(456);
+        account.setFirstName("Claus");
+        account.setLastName("Jensen");
+        account.setEmailAddress("Other@gmail.com");
+
+        template.sendBody("direct:start", account);
+
+        assertMockEndpointsSatisfied();
+
+        // there should be 2 rows now
+        Integer rows = template.requestBody("ibatis:count?statementType=QueryForObject",
null, Integer.class);
+        assertEquals("There should be 2 rows", 2, rows.intValue());
+
+        Account claus = template.requestBody("ibatis:selectAccountById?statementType=QueryForObject",
456, Account.class);
+        assertEquals("Claus", claus.getFirstName());
+        assertEquals("Jensen", claus.getLastName());
+        assertEquals("Other@gmail.com", claus.getEmailAddress());
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                // START SNIPPET: e1
+                from("direct:start")
+                    .to("ibatis:updateAccount?statementType=Update")
+                    .to("mock:result");
+                // END SNIPPET: e1
+            }
+        };
+    }
+
+}
\ No newline at end of file

Propchange: camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueryForUpdateTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueryForUpdateTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisTestSupport.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisTestSupport.java?rev=773359&view=auto
==============================================================================
--- camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisTestSupport.java
(added)
+++ camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisTestSupport.java
Sun May 10 16:21:38 2009
@@ -0,0 +1,66 @@
+/**
+ * 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.ibatis;
+
+import java.sql.Connection;
+import java.sql.Statement;
+
+import org.apache.camel.ContextTestSupport;
+
+public class IBatisTestSupport extends ContextTestSupport {
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        // lets create the database...
+        Connection connection = createConnection();
+        Statement statement = connection.createStatement();
+        statement.execute("create table ACCOUNT ( ACC_ID INTEGER , ACC_FIRST_NAME VARCHAR(255),
ACC_LAST_NAME VARCHAR(255), ACC_EMAIL VARCHAR(255)  )");
+        connection.close();
+
+        Account account = new Account();
+        account.setId(123);
+        account.setFirstName("James");
+        account.setLastName("Strachan");
+        account.setEmailAddress("TryGuessing@gmail.com");
+        template.sendBody("ibatis:insertAccount", account);
+
+        account = new Account();
+        account.setId(456);
+        account.setFirstName("Claus");
+        account.setLastName("Ibsen");
+        account.setEmailAddress("Noname@gmail.com");
+
+        template.sendBody("ibatis:insertAccount", account);
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        Connection connection = createConnection();
+        Statement statement = connection.createStatement();
+        statement.execute("drop table ACCOUNT");
+        connection.close();
+
+        super.tearDown();
+    }
+
+    private Connection createConnection() throws Exception {
+        IBatisEndpoint endpoint = resolveMandatoryEndpoint("ibatis:Account", IBatisEndpoint.class);
+        return endpoint.getSqlMapClient().getDataSource().getConnection();
+    }
+}
\ No newline at end of file

Propchange: camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisTestSupport.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisTestSupport.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: camel/trunk/components/camel-ibatis/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ibatis/src/test/resources/log4j.properties?rev=773359&r1=773358&r2=773359&view=diff
==============================================================================
--- camel/trunk/components/camel-ibatis/src/test/resources/log4j.properties (original)
+++ camel/trunk/components/camel-ibatis/src/test/resources/log4j.properties Sun May 10 16:21:38
2009
@@ -18,10 +18,11 @@
 #
 # The logging properties used for eclipse testing, We want to see debug output on the console.
 #
-log4j.rootLogger=INFO, out
+log4j.rootLogger=INFO, file
 
 # uncomment the following to enable debug of Camel
-log4j.logger.org.apache.camel=DEBUG
+#log4j.logger.org.apache.camel=DEBUG
+#log4j.logger.org.apache.ibatis=DEBUG
 
 #log4j.logger.org.apache.activemq=DEBUG
 
@@ -32,8 +33,8 @@
 #log4j.appender.stdout.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
 
 # File appender
-log4j.appender.out=org.apache.log4j.FileAppender
-log4j.appender.out.layout=org.apache.log4j.PatternLayout
-log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
-log4j.appender.out.file=target/camel-ibatis-test.log
-log4j.appender.out.append=true
+log4j.appender.file=org.apache.log4j.FileAppender
+log4j.appender.file.layout=org.apache.log4j.PatternLayout
+log4j.appender.file.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+log4j.appender.file.file=target/camel-ibatis-test.log
+log4j.appender.file.append=true

Modified: camel/trunk/components/camel-ibatis/src/test/resources/org/apache/camel/component/ibatis/Account.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ibatis/src/test/resources/org/apache/camel/component/ibatis/Account.xml?rev=773359&r1=773358&r2=773359&view=diff
==============================================================================
--- camel/trunk/components/camel-ibatis/src/test/resources/org/apache/camel/component/ibatis/Account.xml
(original)
+++ camel/trunk/components/camel-ibatis/src/test/resources/org/apache/camel/component/ibatis/Account.xml
Sun May 10 16:21:38 2009
@@ -37,7 +37,7 @@
 
   <!-- Select with no parameters using the result map for Account class. -->
   <select id="selectAllAccounts" resultMap="AccountResult">
-    select * from ACCOUNT
+    select * from ACCOUNT order by ACC_ID
   </select>
 
   <!-- A simpler select example without the result map.  Note the
@@ -96,4 +96,8 @@
   </update>
   <!-- END SNIPPET: e2 -->
 
+  <select id="count" resultClass="int">
+       select count(*) from ACCOUNT
+  </select>
+
 </sqlMap>
\ No newline at end of file



Mime
View raw message