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 2009/04/24 17:41:12 UTC
svn commit: r768334 - in /camel/trunk/components/camel-ibatis/src:
main/java/org/apache/camel/component/ibatis/IBatisPollingConsumer.java
test/java/org/apache/camel/component/ibatis/IBatisRouteEmptyResultSetTest.java
Author: davsclaus
Date: Fri Apr 24 15:41:12 2009
New Revision: 768334
URL: http://svn.apache.org/viewvc?rev=768334&view=rev
Log:
CAMEL-1534: Option to route empty resultsets. Applied patch with thanks to Joe Luo.
Added:
camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisRouteEmptyResultSetTest.java (with props)
Modified:
camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisPollingConsumer.java
Modified: camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisPollingConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisPollingConsumer.java?rev=768334&r1=768333&r2=768334&view=diff
==============================================================================
--- camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisPollingConsumer.java (original)
+++ camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisPollingConsumer.java Fri Apr 24 15:41:12 2009
@@ -105,6 +105,11 @@
*/
private boolean useIterator = true;
+ /**
+ * Whether allow empty resultset to be routed to the next hop
+ */
+ private boolean routeEmptyResultSet = false;
+
public IBatisPollingConsumer(IBatisEndpoint endpoint, Processor processor) throws Exception {
super(endpoint, processor);
}
@@ -130,7 +135,9 @@
}
}
} else {
- process(data);
+ if (!data.isEmpty() || routeEmptyResultSet) {
+ process(data);
+ }
}
}
@@ -180,7 +187,6 @@
this.onConsume = onConsume;
}
-
/**
* Indicates how resultset should be delivered to the route
*/
@@ -196,4 +202,19 @@
public void setUseIterator(boolean useIterator) {
this.useIterator = useIterator;
}
+
+ /**
+ * Indicates whether empty resultset should be allowed to be sent to the next hop or not
+ */
+ public boolean isRouteEmptyResultSet() {
+ return routeEmptyResultSet;
+ }
+
+ /**
+ * Sets whether empty resultset should be allowed to be sent to the next hop.
+ * defaults to false. So the empty resultset will be filtered out.
+ */
+ public void setRouteEmptyResultSet(boolean routeEmptyResultSet) {
+ this.routeEmptyResultSet = routeEmptyResultSet;
+ }
}
Added: camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisRouteEmptyResultSetTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisRouteEmptyResultSetTest.java?rev=768334&view=auto
==============================================================================
--- camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisRouteEmptyResultSetTest.java (added)
+++ camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisRouteEmptyResultSetTest.java Fri Apr 24 15:41:12 2009
@@ -0,0 +1,79 @@
+/**
+ * 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 java.util.List;
+import java.util.ArrayList;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ * @version $Revision$
+ */
+public class IBatisRouteEmptyResultSetTest extends ContextTestSupport {
+
+ public void testRouteEmptyResultSet() throws Exception {
+ MockEndpoint endpoint = getMockEndpoint("mock:results");
+ endpoint.expectedMinimumMessageCount(1);
+
+ assertMockEndpointsSatisfied();
+
+ // should be an empty list
+ assertEquals("Should be an empty list", 0, endpoint.getReceivedExchanges().get(0).getIn().getBody(ArrayList.class).size());
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() throws Exception {
+ from("ibatis:selectAllAccounts?consumer.useIterator=false&consumer.routeEmptyResultSet=true").to("mock:results");
+
+ from("direct:start").to("ibatis:insertAccount");
+ }
+ };
+ }
+
+ @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();
+ }
+
+ @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/IBatisRouteEmptyResultSetTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisRouteEmptyResultSetTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date