camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [4/8] camel git commit: CAMEL-8668: MongoDbTailTrackingManager to MongoDB 3
Date Fri, 03 Jun 2016 08:01:45 GMT
CAMEL-8668: MongoDbTailTrackingManager to MongoDB 3


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

Branch: refs/heads/master
Commit: 700175344f057c8f1a24e7925261dcaf02c4fe5b
Parents: ef0342a
Author: Arno Noordover <anoordover@users.noreply.github.com>
Authored: Sun May 29 21:47:41 2016 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Fri Jun 3 09:56:37 2016 +0200

----------------------------------------------------------------------
 .../component/mongodb/MongoDbComponent.java     |  6 ++--
 .../component/mongodb/MongoDbEndpoint.java      |  7 +++--
 .../mongodb/MongoDbTailTrackingManager.java     | 31 +++++++++++---------
 3 files changed, 25 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/70017534/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbComponent.java
b/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbComponent.java
index 419893e..0315890 100644
--- a/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbComponent.java
+++ b/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbComponent.java
@@ -22,6 +22,8 @@ import java.util.Map;
 import java.util.Set;
 
 import com.mongodb.Mongo;
+import com.mongodb.MongoClient;
+
 import org.apache.camel.Endpoint;
 import org.apache.camel.impl.UriEndpointComponent;
 import org.apache.camel.util.CamelContextHelper;
@@ -37,7 +39,7 @@ public class MongoDbComponent extends UriEndpointComponent {
             new HashSet<MongoDbOperation>(Arrays.asList(MongoDbOperation.insert, MongoDbOperation.save,

                     MongoDbOperation.update, MongoDbOperation.remove));
     private static final Logger LOG = LoggerFactory.getLogger(MongoDbComponent.class);
-    private volatile Mongo db;
+    private volatile MongoClient db;
 
     public MongoDbComponent() {
         super(MongoDbEndpoint.class);
@@ -49,7 +51,7 @@ public class MongoDbComponent extends UriEndpointComponent {
     protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object>
parameters) throws Exception {
         // TODO: this only supports one mongodb
         if (db == null) {
-            db = CamelContextHelper.mandatoryLookup(getCamelContext(), remaining, Mongo.class);
+            db = CamelContextHelper.mandatoryLookup(getCamelContext(), remaining, MongoClient.class);
             LOG.debug("Resolved the connection with the name {} as {}", remaining, db);
         }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/70017534/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbEndpoint.java
b/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbEndpoint.java
index 577b574..d6c3f46 100644
--- a/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbEndpoint.java
+++ b/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbEndpoint.java
@@ -27,6 +27,7 @@ import com.mongodb.DB;
 import com.mongodb.DBCollection;
 import com.mongodb.DBObject;
 import com.mongodb.Mongo;
+import com.mongodb.MongoClient;
 import com.mongodb.ReadPreference;
 import com.mongodb.WriteConcern;
 import com.mongodb.WriteResult;
@@ -52,7 +53,7 @@ public class MongoDbEndpoint extends DefaultEndpoint {
 
     private static final Logger LOG = LoggerFactory.getLogger(MongoDbEndpoint.class);
 
-    private Mongo mongoConnection;
+    private MongoClient mongoConnection;
 
     @UriPath @Metadata(required = "true")
     private String connectionBean;
@@ -402,11 +403,11 @@ public class MongoDbEndpoint extends DefaultEndpoint {
      * 
      * @param mongoConnection the connection to the database
      */
-    public void setMongoConnection(Mongo mongoConnection) {
+    public void setMongoConnection(MongoClient mongoConnection) {
         this.mongoConnection = mongoConnection;
     }
 
-    public Mongo getMongoConnection() {
+    public MongoClient getMongoConnection() {
         return mongoConnection;
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/70017534/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbTailTrackingManager.java
----------------------------------------------------------------------
diff --git a/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbTailTrackingManager.java
b/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbTailTrackingManager.java
index 96637ef..50c3154 100644
--- a/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbTailTrackingManager.java
+++ b/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbTailTrackingManager.java
@@ -21,8 +21,11 @@ import com.mongodb.BasicDBObjectBuilder;
 import com.mongodb.DBCollection;
 import com.mongodb.DBObject;
 import com.mongodb.Mongo;
+import com.mongodb.MongoClient;
 import com.mongodb.WriteConcern;
+import com.mongodb.client.MongoCollection;
 
+import org.bson.Document;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -32,12 +35,12 @@ public class MongoDbTailTrackingManager {
     
     public Object lastVal;
 
-    private final Mongo connection;
+    private final MongoClient connection;
     private final MongoDbTailTrackingConfig config;
-    private DBCollection dbCol;
-    private DBObject trackingObj;
+    private MongoCollection<Document> dbCol;
+    private Document trackingObj;
     
-    public MongoDbTailTrackingManager(Mongo connection, MongoDbTailTrackingConfig config)
{
+    public MongoDbTailTrackingManager(MongoClient connection, MongoDbTailTrackingConfig config)
{
         this.connection = connection;
         this.config = config;
     }
@@ -47,15 +50,15 @@ public class MongoDbTailTrackingManager {
             return;
         }
         
-        dbCol = connection.getDB(config.db).getCollection(config.collection);
-        DBObject filter = new BasicDBObject("persistentId", config.persistentId);
-        trackingObj = dbCol.findOne(filter);
+        dbCol = connection.getDatabase(config.db).getCollection(config.collection);
+        Document filter = new Document("persistentId", config.persistentId);
+        trackingObj = dbCol.find(filter).first();
         if (trackingObj == null) {
-            dbCol.insert(filter, WriteConcern.SAFE);
-            trackingObj = dbCol.findOne(filter);
+            dbCol.insertOne(filter);
+            trackingObj = dbCol.find(filter).first();
         }
         // keep only the _id, the rest is useless and causes more overhead during update
-        trackingObj = new BasicDBObject("_id", trackingObj.get("_id"));
+        trackingObj = new Document("_id", trackingObj.get("_id"));
     }
     
     public synchronized void persistToStore() {
@@ -67,9 +70,9 @@ public class MongoDbTailTrackingManager {
             LOG.debug("Persisting lastVal={} to store, collection: {}", lastVal, config.collection);
         }
         
-        DBObject updateObj = BasicDBObjectBuilder.start().add("$set", new BasicDBObject(config.field,
lastVal)).get();
-        dbCol.update(trackingObj, updateObj, false, false, WriteConcern.SAFE);
-        trackingObj = dbCol.findOne();
+        Document updateObj = new Document().append("$set", new BasicDBObject(config.field,
lastVal));
+        dbCol.updateOne(trackingObj, updateObj);
+        trackingObj = dbCol.find().first();
     }
     
     public synchronized Object recoverFromStore() {
@@ -77,7 +80,7 @@ public class MongoDbTailTrackingManager {
             return null;
         }
         
-        lastVal = dbCol.findOne(trackingObj).get(config.field);
+        lastVal = dbCol.find(trackingObj).first().get(config.field);
         
         if (LOG.isDebugEnabled()) {
             LOG.debug("Recovered lastVal={} from store, collection: {}", lastVal, config.collection);


Mime
View raw message