List of usage examples for com.mongodb DBCursor close
@Override public void close()
From source file:org.eclipse.linuxtools.tmf.totalads.algorithms.ksm.KernelStateModeling.java
License:Open Source License
/** * Gets maximum KL and MM// ww w . j a v a 2 s .c om * @param cursor * @param maxKL * @param maxMM */ private Double[] getMaxKLandMM(DBCursor cursor) { Double[] maxKLMM = { 0.0, 0.0 }; while (cursor.hasNext()) { DBObject doc = cursor.next(); Double KL = (Double) doc.get("KL"); Double MM = (Double) doc.get("MM"); if (KL > maxKLMM[0]) maxKLMM[0] = KL; if (MM > maxKLMM[1]) maxKLMM[1] = MM; } cursor.close(); return maxKLMM; }
From source file:org.eclipse.linuxtools.tmf.totalads.algorithms.slidingwindow.SlidingWindow.java
License:Open Source License
/** * Initializes the model if already exists in the database * @param connection DBMS object/*from w ww . j ava 2 s. c o m*/ * @param database Database name */ private void initialize(DBMS connection, String database) { DBCursor cursor = connection.selectAll(database, this.TRACE_COLLECTION); if (cursor != null) { while (cursor.hasNext()) { DBObject dbObject = cursor.next(); Gson gson = new Gson(); String key = dbObject.get("_id").toString(); Event[] event = gson.fromJson(dbObject.get("tree").toString(), Event[].class); sysCallSequences.put(key, event); } cursor.close(); } // get the maxwin cursor = connection.selectAll(database, this.SETTINGS_COLLECTION); if (cursor != null) { while (cursor.hasNext()) { DBObject dbObject = cursor.next(); maxWin = Integer.parseInt(dbObject.get(SettingsCollection.MAX_WIN.toString()).toString()); maxHamDis = Integer.parseInt(dbObject.get(SettingsCollection.MAX_HAM_DIS.toString()).toString()); } cursor.close(); } }
From source file:org.eclipse.linuxtools.tmf.totalads.algorithms.slidingwindow.SlidingWindow.java
License:Open Source License
/** * /*w w w .j av a2 s. c om*/ * Set the settings of an algorithm as option name at index i and value ate index i+1 * @return String[] Array of String * */ @Override public String[] getTestingOptions(String database, DBMS connection) { DBCursor cursor = connection.selectAll(database, this.SETTINGS_COLLECTION); if (cursor != null) { while (cursor.hasNext()) { DBObject dbObject = cursor.next(); //maxWin=Integer.parseInt(dbObject.get(SETTINGS_COLL_FIELDS.MAX_WIN).toString()); maxHamDis = Integer.parseInt(dbObject.get(SettingsCollection.MAX_HAM_DIS.toString()).toString()); } cursor.close(); } testingOptions[1] = maxHamDis.toString(); return testingOptions; }
From source file:org.eclipse.linuxtools.tmf.totalads.dbms.DBMS.java
License:Open Source License
/** * Selects a max value from a collection (table) * @param key Field name to return the max of. Use an index key otherwise the results will be slow * @param database Database name//from w ww .ja v a 2s .c o m * @param collection Collection name * @return Maximum value as a string */ public String selectMax(String key, String database, String collection) { String maxVal = ""; DB db = mongoClient.getDB(database); DBCollection coll = db.getCollection(collection); BasicDBObject query = new BasicDBObject(key, -1); DBCursor curs = coll.find().sort(query).limit(1); if (curs.hasNext()) maxVal = curs.next().get(key).toString(); curs.close(); return maxVal; }
From source file:org.einherjer.week2.samples.DotNotationSample.java
License:Apache License
public static void main(String[] args) throws UnknownHostException { Mongo client = new Mongo(); DB db = client.getDB("course"); DBCollection lines = db.getCollection("dotNotationSample"); lines.drop();//from w w w. j a va 2 s.co m Random rand = new Random(); // insert 10 lines with random start and end points for (int i = 0; i < 10; i++) { lines.insert( new BasicDBObject("_id", i) .append("start", new BasicDBObject("x", rand.nextInt(90) + 10).append("y", rand.nextInt(90) + 10)) .append("end", new BasicDBObject("x", rand.nextInt(90) + 10).append("y", rand.nextInt(90) + 10))); } QueryBuilder builder = QueryBuilder.start("start.x").greaterThan(50); DBCursor cursor = lines.find(builder.get(), new BasicDBObject("start.y", true).append("_id", false)); try { while (cursor.hasNext()) { DBObject cur = cursor.next(); System.out.println(cur); } } finally { cursor.close(); } }
From source file:org.einherjer.week2.samples.FieldSelectionSample.java
License:Apache License
public static void main(String[] args) throws UnknownHostException { Mongo client = new Mongo(); DB db = client.getDB("course"); DBCollection collection = db.getCollection("fieldSelectionSample"); collection.drop();//from www .j a v a2 s . c o m Random rand = new Random(); // insert 10 documents with two random integers for (int i = 0; i < 10; i++) { collection.insert(new BasicDBObject("x", rand.nextInt(2)).append("y", rand.nextInt(100)).append("z", rand.nextInt(1000))); } DBObject query = QueryBuilder.start("x").is(0).and("y").greaterThan(10).lessThan(70).get(); //use second find parameter to filter the returned fields DBCursor cursor = collection.find(query, new BasicDBObject("y", true).append("_id", false)); try { while (cursor.hasNext()) { DBObject cur = cursor.next(); System.out.println(cur); } } finally { cursor.close(); } }
From source file:org.einherjer.week2.samples.FindAndModifySample.java
License:Apache License
private static void printCollection(final DBCollection collection) { DBCursor cursor = collection.find().sort(new BasicDBObject("_id", 1)); try {/* www . j a v a2 s .c om*/ while (cursor.hasNext()) { System.out.println(cursor.next()); } } finally { cursor.close(); } }
From source file:org.einherjer.week2.samples.FindCriteriaSample.java
License:Apache License
public static void main(String[] args) throws UnknownHostException { Mongo client = new Mongo(); DB db = client.getDB("course"); DBCollection collection = db.getCollection("findCriteriaSample"); collection.drop();//from www.ja va 2s .c o m // insert 10 documents with two random integers for (int i = 0; i < 10; i++) { collection .insert(new BasicDBObject("x", new Random().nextInt(2)).append("y", new Random().nextInt(100))); } //1- The query document can be created by using a QueryBuilder... QueryBuilder builder = QueryBuilder.start("x").is(0).and("y").greaterThan(10).lessThan(70); //2- or, the query document can be created manually DBObject query = new BasicDBObject("x", 0).append("y", new BasicDBObject("$gt", 10).append("$lt", 90)); System.out.println("\nCount:"); long count = collection.count(builder.get()); System.out.println(count); System.out.println("\nFind all: "); DBCursor cursor = collection.find(builder.get()); try { while (cursor.hasNext()) { DBObject cur = cursor.next(); System.out.println(cur); } } finally { cursor.close(); } }
From source file:org.einherjer.week2.samples.FindSample.java
License:Apache License
public static void main(String[] args) throws UnknownHostException { Mongo client = new Mongo(); DB db = client.getDB("course"); DBCollection collection = db.getCollection("findSample"); collection.drop();// ww w . j ava 2 s.co m // insert 10 documents with a random integer as the value of field "x" for (int i = 0; i < 10; i++) { collection.insert(new BasicDBObject("x", new Random().nextInt(100))); } System.out.println("Find one:"); DBObject one = collection.findOne(); System.out.println(one); System.out.println("\nFind all: "); DBCursor cursor = collection.find(); try { while (cursor.hasNext()) { DBObject cur = cursor.next(); System.out.println(cur); } } finally { cursor.close(); } System.out.println("\nCount:"); long count = collection.count(); System.out.println(count); }
From source file:org.einherjer.week2.samples.SortSkipLimitSample.java
License:Apache License
public static void main(String[] args) throws UnknownHostException { Mongo client = new Mongo(); DB db = client.getDB("course"); DBCollection lines = db.getCollection("sortSkipLimitSample"); lines.drop();/* ww w. j av a2 s .c om*/ Random rand = new Random(); // insert 10 lines with random start and end points for (int i = 0; i < 10; i++) { lines.insert(new BasicDBObject("_id", i) .append("start", new BasicDBObject("x", rand.nextInt(2)).append("y", rand.nextInt(90) + 10)) .append("end", new BasicDBObject("x", rand.nextInt(2)).append("y", rand.nextInt(90) + 10))); } DBCursor cursor = lines.find().sort(new BasicDBObject("start.x", 1).append("start.y", -1)).skip(2) .limit(10); try { while (cursor.hasNext()) { DBObject cur = cursor.next(); System.out.println(cur); } } finally { cursor.close(); } }