camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [1/2] camel git commit: CAMEL-10444: return header CamelMongoDbRecordsAffected from update and remove operations
Date Mon, 07 Nov 2016 09:47:53 GMT
Repository: camel
Updated Branches:
  refs/heads/camel-2.18.x f04f785ab -> 8a5363020
  refs/heads/master e272e52f7 -> 70ac57f42


CAMEL-10444: return header CamelMongoDbRecordsAffected from update and remove operations


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

Branch: refs/heads/master
Commit: 70ac57f42d27b090d403e2ae336fdb09e6613471
Parents: e272e52
Author: Nick Busy <nbusy@enfoll.com>
Authored: Sat Nov 5 16:30:22 2016 +1100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Mon Nov 7 10:38:53 2016 +0100

----------------------------------------------------------------------
 .../component/mongodb/MongoDbProducer.java      |  6 ++++++
 .../mongodb/MongoDbOperationsTest.java          | 22 ++++++++++++++++++--
 2 files changed, 26 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/70ac57f4/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbProducer.java
b/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbProducer.java
index 9a72e7e..52e4ed6 100644
--- a/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbProducer.java
+++ b/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbProducer.java
@@ -409,6 +409,9 @@ public class MongoDbProducer extends DefaultProducer {
                 } else {
                     result = dbCol.updateMany(updateCriteria, objNew, options);
                 }
+                if (result.isModifiedCountAvailable()) {
+                    exchange1.getOut().setHeader(MongoDbConstants.RECORDS_AFFECTED, result.getModifiedCount());
+                }
                 return result;
             } catch (InvalidPayloadException e) {
                 throw new CamelMongoDbException("Invalid payload for update", e);
@@ -423,6 +426,9 @@ public class MongoDbProducer extends DefaultProducer {
                 BasicDBObject removeObj = exchange1.getIn().getMandatoryBody(BasicDBObject.class);
 
                 DeleteResult result = dbCol.deleteMany(removeObj);
+                if (result.wasAcknowledged()) {
+                    exchange1.getOut().setHeader(MongoDbConstants.RECORDS_AFFECTED, result.getDeletedCount());
+                }
                 return result;
             } catch (InvalidPayloadException e) {
                 throw new CamelMongoDbException("Invalid payload for remove", e);

http://git-wip-us.apache.org/repos/asf/camel/blob/70ac57f4/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbOperationsTest.java
----------------------------------------------------------------------
diff --git a/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbOperationsTest.java
b/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbOperationsTest.java
index 842af35..eb6b4ea 100644
--- a/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbOperationsTest.java
+++ b/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbOperationsTest.java
@@ -29,6 +29,9 @@ import com.mongodb.client.result.DeleteResult;
 import com.mongodb.client.result.UpdateResult;
 import com.mongodb.util.JSON;
 
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
 import org.bson.Document;
 import org.bson.types.ObjectId;
@@ -137,8 +140,16 @@ public class MongoDbOperationsTest extends AbstractMongoDbTest {
 
         DBObject updateObj = new BasicDBObject("$set", new BasicDBObject("scientist", "Darwin"));
         
-        Object result = template.requestBodyAndHeader("direct:update", new Object[] {extraField,
updateObj}, MongoDbConstants.MULTIUPDATE, true);
+        Exchange resultExchange = template.request("direct:update", new Processor() {
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setBody(new Object[] {extraField, updateObj});
+                exchange.getIn().setHeader(MongoDbConstants.MULTIUPDATE, true);
+            }
+        });
+        Object result = resultExchange.getOut().getBody();
         assertTrue(result instanceof UpdateResult);
+        assertEquals("Number of records updated header should equal 50", 50L, resultExchange.getOut().getHeader(MongoDbConstants.RECORDS_AFFECTED));
         
         assertEquals("Number of records with 'scientist' field = Darwin on must equal 50
after update", 50, 
                 testCollection.count(new BasicDBObject("scientist", "Darwin")));
@@ -166,8 +177,15 @@ public class MongoDbOperationsTest extends AbstractMongoDbTest {
         BasicDBObject extraField = new BasicDBObject("extraField", true);
         assertEquals("Number of records with 'extraField' flag on must equal 50", 50L, testCollection.count(extraField));
         
-        Object result = template.requestBody("direct:remove", extraField);
+        Exchange resultExchange = template.request("direct:remove", new Processor() {
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setBody(extraField);
+            }
+        });
+        Object result = resultExchange.getOut().getBody();
         assertTrue(result instanceof DeleteResult);
+        assertEquals("Number of records deleted header should equal 50", 50L, resultExchange.getOut().getHeader(MongoDbConstants.RECORDS_AFFECTED));
         
         assertEquals("Number of records with 'extraField' flag on must be 0 after remove",
0, 
                 testCollection.count(extraField));


Mime
View raw message