# HG changeset patch # User tatsuki # Date 1430403213 -32400 # Node ID 87c7c86ecca2064dcfff61946b9bc9401f6a9e4e # Parent 6819a376de75ab8f802ba9e26f7f13290c2fe0ef change mongodb ver 3.0.0 diff -r 6819a376de75 -r 87c7c86ecca2 src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/test/DataBaseBenchMark.java --- 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 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))); diff -r 6819a376de75 -r 87c7c86ecca2 src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/test/findMongoAttributeThread.java --- 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 coll; - public findMongoAttributeThread(DBCollection coll) { + public findMongoAttributeThread( MongoCollection coll) { this.coll = coll; this.findCount = 0; } @@ -29,10 +30,11 @@ @Override public void run() { - BasicDBObject query = new BasicDBObject("key", "0"); + ArrayList list = new ArrayList(); + list.add(new Document("key","1")); while (loop) { - DBCursor cursor = coll.find(query); - if (cursor.hasNext()) { + ArrayList searchResultList = coll.find().into(list); + if (!searchResultList.isEmpty()) { findCount++; } }