changeset 194:87c7c86ecca2

change mongodb ver 3.0.0
author tatsuki
date Thu, 30 Apr 2015 23:13:33 +0900
parents 6819a376de75
children c42e26557279
files src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/test/DataBaseBenchMark.java src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/test/findMongoAttributeThread.java
diffstat 2 files changed, 17 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/test/DataBaseBenchMark.java	Thu Apr 30 21:44:38 2015 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/test/DataBaseBenchMark.java	Thu Apr 30 23:13:33 2015 +0900
@@ -2,6 +2,8 @@
 
 
 import com.mongodb.*;
+import com.mongodb.client.MongoCollection;
+import com.mongodb.client.MongoDatabase;
 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.DefaultJungle;
 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.Jungle;
 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree;
@@ -10,6 +12,7 @@
 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNodePath;
 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultTreeEditor;
 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.DefaultTraverser;
+import org.bson.Document;
 import org.xml.sax.SAXException;
 
 import javax.xml.parsers.ParserConfigurationException;
@@ -40,18 +43,14 @@
     private static void mongoBench(String[] args, int cpuNum) throws IOException, InterruptedException {
         MongoClient client = new MongoClient("localhost", 27017);
         client.setWriteConcern(WriteConcern.JOURNALED);
-        //client.dropDatabase("test");
-        DB db = client.getDB("test");
-        DBCollection coll = null;
-        if (!db.collectionExists("testCollection")) {
-            coll = db.getCollection("testCollection");
+        client.dropDatabase("test");
+        MongoDatabase database = client.getDatabase("mydb");
+        MongoCollection<Document> coll = database.getCollection("mycoll");
             for (int i = 0; i < 1000; i++) {
                 if (i % 100 == 0)
                     System.out.println(i / 100);
-                coll.insert(new BasicDBObject("key", String.valueOf(i)));
+                coll.insertOne(new Document("key",String.valueOf(i)));
             }
-        } else
-            coll = db.getCollection("testCollection");
         coll.createIndex(new BasicDBObject("key", 1));
         File file = new File("./time/" + args[0] + args[1] + "Time");
         PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(file)));
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/test/findMongoAttributeThread.java	Thu Apr 30 21:44:38 2015 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/test/findMongoAttributeThread.java	Thu Apr 30 23:13:33 2015 +0900
@@ -1,8 +1,9 @@
 package jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.test;
 
-import com.mongodb.BasicDBObject;
-import com.mongodb.DBCollection;
-import com.mongodb.DBCursor;
+import com.mongodb.client.MongoCollection;
+import org.bson.Document;
+
+import java.util.ArrayList;
 
 /**
  * Created by e115731 on 15/04/30.
@@ -10,9 +11,9 @@
 public class findMongoAttributeThread extends DataBaseBenchMarkThread {
     private long findCount;
     boolean loop = true;
-    DBCollection coll;
+    MongoCollection<Document> coll;
 
-    public findMongoAttributeThread(DBCollection coll) {
+    public findMongoAttributeThread( MongoCollection<Document> coll) {
         this.coll = coll;
         this.findCount = 0;
     }
@@ -29,10 +30,11 @@
 
     @Override
     public void run() {
-        BasicDBObject query = new BasicDBObject("key", "0");
+        ArrayList<Document> list = new ArrayList<Document>();
+        list.add(new Document("key","1"));
         while (loop) {
-            DBCursor cursor = coll.find(query);
-            if (cursor.hasNext()) {
+            ArrayList<Document> searchResultList = coll.find().into(list);
+            if (!searchResultList.isEmpty()) {
                 findCount++;
             }
         }