You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2016/11/16 09:41:11 UTC

camel git commit: CAMEL-10453: camel-elsql does not set CamelSqlUpdateCount header on update operation

Repository: camel
Updated Branches:
  refs/heads/master 36089587b -> 1d3a20061


CAMEL-10453: camel-elsql does not set CamelSqlUpdateCount header on update operation


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

Branch: refs/heads/master
Commit: 1d3a200610daae8e30e6378bce3661258fabea7c
Parents: 3608958
Author: Andrea Cosentino <an...@gmail.com>
Authored: Wed Nov 16 10:40:36 2016 +0100
Committer: Andrea Cosentino <an...@gmail.com>
Committed: Wed Nov 16 10:40:36 2016 +0100

----------------------------------------------------------------------
 .../camel/component/elsql/ElsqlProducer.java    |  4 ++++
 .../elsql/ElSqlProducerBodySimpleTest.java      | 20 ++++++++++++++++++++
 .../src/test/resources/elsql/projects.elsql     |  4 ++++
 3 files changed, 28 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/1d3a2006/components/camel-elsql/src/main/java/org/apache/camel/component/elsql/ElsqlProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-elsql/src/main/java/org/apache/camel/component/elsql/ElsqlProducer.java b/components/camel-elsql/src/main/java/org/apache/camel/component/elsql/ElsqlProducer.java
index e2783b5..2667566 100644
--- a/components/camel-elsql/src/main/java/org/apache/camel/component/elsql/ElsqlProducer.java
+++ b/components/camel-elsql/src/main/java/org/apache/camel/component/elsql/ElsqlProducer.java
@@ -134,6 +134,10 @@ public class ElsqlProducer extends DefaultProducer {
                         } else {
                             throw new IllegalArgumentException("Invalid outputType=" + outputType);
                         }
+                    } else {
+                        // if we are here, there isResultSet is false. This can happen only if we are doing an update operation or there is no result.
+                        // we can simply add the updateCount in this case.
+                        exchange.getOut().setHeader(SqlConstants.SQL_UPDATE_COUNT, ps.getUpdateCount());
                     }
                 } finally {
                     closeResultSet(rs);

http://git-wip-us.apache.org/repos/asf/camel/blob/1d3a2006/components/camel-elsql/src/test/java/org/apache/camel/component/elsql/ElSqlProducerBodySimpleTest.java
----------------------------------------------------------------------
diff --git a/components/camel-elsql/src/test/java/org/apache/camel/component/elsql/ElSqlProducerBodySimpleTest.java b/components/camel-elsql/src/test/java/org/apache/camel/component/elsql/ElSqlProducerBodySimpleTest.java
index 5fab274..4bac301 100644
--- a/components/camel-elsql/src/test/java/org/apache/camel/component/elsql/ElSqlProducerBodySimpleTest.java
+++ b/components/camel-elsql/src/test/java/org/apache/camel/component/elsql/ElSqlProducerBodySimpleTest.java
@@ -17,6 +17,7 @@
 package org.apache.camel.component.elsql;
 
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -105,6 +106,21 @@ public class ElSqlProducerBodySimpleTest extends CamelTestSupport {
 
         assertEquals("Camel", row.get("PROJECT"));
     }
+    
+    @Test
+    public void testUpdateHeader() throws InterruptedException {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMessageCount(1);
+        mock.message(0).header(SqlConstants.SQL_UPDATE_COUNT).isEqualTo(1);
+        
+        Map<String, Object> headers = new HashMap<>();       
+        headers.put("id", "3");
+        headers.put("lic", "GNU");
+
+        template.sendBodyAndHeaders("direct:update", "", headers);
+
+        mock.assertIsSatisfied();
+    }
 
     @After
     public void tearDown() throws Exception {
@@ -124,6 +140,10 @@ public class ElSqlProducerBodySimpleTest extends CamelTestSupport {
                 from("direct:parameters")
                         .to("elsql:projectById:elsql/projects.elsql?dataSource=#dataSource")
                         .to("mock:result");
+                
+                from("direct:update")
+                        .to("elsql:updateLicense:elsql/projects.elsql?dataSource=#dataSource")
+                        .to("mock:result");
             }
         };
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/1d3a2006/components/camel-elsql/src/test/resources/elsql/projects.elsql
----------------------------------------------------------------------
diff --git a/components/camel-elsql/src/test/resources/elsql/projects.elsql b/components/camel-elsql/src/test/resources/elsql/projects.elsql
index 470a33f..42fc6e9 100644
--- a/components/camel-elsql/src/test/resources/elsql/projects.elsql
+++ b/components/camel-elsql/src/test/resources/elsql/projects.elsql
@@ -16,3 +16,7 @@
   SELECT *
   FROM projects
   WHERE id = :id
+@NAME(updateLicense)
+  UPDATE projects
+  SET license = :lic
+  WHERE id = :id