List of usage examples for com.mongodb DBCursor close
@Override public void close()
From source file:gMIRC_server.java
public static void cleaner() { try {// w w w . j a v a 2 s . c o m boolean hard_clean = false; MongoClient mongoClient = new MongoClient(); DB db = mongoClient.getDB("mirc"); DBCollection coll = db.getCollection("activeUser"); DBCursor cursor = coll.find(); try { Date now = new Date(); long timestamp_now = now.getTime(); long treshold = timestamp_now - (1000 * 60 * 5); //5 minutes while (cursor.hasNext()) { hard_clean = true; BasicDBObject temp = (BasicDBObject) cursor.next(); Date time_temp = (Date) temp.get("timestamp"); long timestamp_temp = time_temp.getTime(); if (timestamp_temp < treshold) { String target = temp.getString("username"); gMIRC_handler.SoftDelete(target); } } HardClean(); } finally { cursor.close(); } } catch (UnknownHostException ex) { Logger.getLogger(gMIRC_server.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:gMIRC_server.java
public static void HardClean() { try {/*from w w w . ja v a2s. co m*/ MongoClient mongoClient = new MongoClient(); DB db = mongoClient.getDB("mirc"); DBCollection coll[] = new DBCollection[4]; coll[0] = db.getCollection("channelCollection"); coll[1] = db.getCollection("inbox"); coll[2] = db.getCollection("activeUser"); coll[3] = db.getCollection("passiveUser"); DBCursor cursor = coll[3].find(); try { while (cursor.hasNext()) { BasicDBObject temp = (BasicDBObject) cursor.next(); String username = temp.getString("username"); BasicDBObject query = new BasicDBObject("username", username); System.out.println("cleaning " + username); for (int i = 0; i < 4; i++) { DBCursor cursor2 = coll[i].find(query); try { while (cursor2.hasNext()) { DBObject temp2 = cursor2.next(); coll[i].remove(temp2); } } finally { cursor2.close(); } } } } finally { cursor.close(); } } catch (UnknownHostException ex) { Logger.getLogger(gMIRC_server.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:act.server.MongoDB.java
License:Open Source License
public List<Long> getRxnsWith(Long reactant, Long product) { BasicDBObject query = new BasicDBObject(); query.put("enz_summary.products.pubchem", product); query.put("enz_summary.substrates.pubchem", reactant); DBCursor cur = this.dbReactions.find(query); List<Long> reactions = new ArrayList<Long>(); while (cur.hasNext()) { DBObject o = cur.next();//from w w w .ja v a 2 s .c o m long id = (Integer) o.get("_id"); // checked: db type IS int reactions.add(id); } cur.close(); return reactions; }
From source file:act.server.MongoDB.java
License:Open Source License
public List<Reaction> getRxnsWithAll(List<Long> reactants, List<Long> products) { if (reactants.size() == 0 && products.size() == 0) { throw new IllegalArgumentException("Reactants and products both empty! Query would return entire DB."); }//from w w w .ja v a 2s. c o m BasicDBObject query = new BasicDBObject(); if (!reactants.isEmpty()) { BasicDBList substrateIds = new BasicDBList(); substrateIds.addAll(reactants); query.put("enz_summary.substrates.pubchem", new BasicDBObject("$all", substrateIds)); } if (!products.isEmpty()) { BasicDBList productIds = new BasicDBList(); productIds.addAll(products); query.put("enz_summary.products.pubchem", new BasicDBObject("$all", productIds)); } DBCursor cur = this.dbReactions.find(query); List<Reaction> reactions = new ArrayList<Reaction>(); try { while (cur.hasNext()) { DBObject o = cur.next(); reactions.add(convertDBObjectToReaction(o)); } } finally { cur.close(); } return reactions; }
From source file:act.server.MongoDB.java
License:Open Source License
public List<Long> getRxnsWithEnzyme(String enzyme, Long org, List<Long> substrates) { BasicDBObject query = new BasicDBObject(); query.put("ecnum", enzyme); query.put("organisms.id", org); for (Long substrate : substrates) { BasicDBObject mainQuery = new BasicDBObject(); mainQuery.put("$ne", substrate); BasicDBList queryList = new BasicDBList(); BasicDBObject productQuery = new BasicDBObject(); productQuery.put("enz_summary.products.pubchem", mainQuery); BasicDBObject substrateQuery = new BasicDBObject(); substrateQuery.put("enz_summary.substrates.pubchem", mainQuery); queryList.add(substrateQuery);// w w w . j av a 2 s.c o m queryList.add(productQuery); query.put("$or", queryList); } DBCursor cur = this.dbReactions.find(query); List<Long> reactions = new ArrayList<Long>(); while (cur.hasNext()) { DBObject o = cur.next(); long id = (Integer) o.get("_id"); // checked: db type IS int reactions.add(id); } cur.close(); return reactions; }
From source file:act.server.MongoDB.java
License:Open Source License
public List<Long> getRxnsWithSubstrate(String enzyme, Long org, List<Long> substrates) { BasicDBObject query = new BasicDBObject(); query.put("organisms.id", org); BasicDBObject enzymeQuery = new BasicDBObject(); enzymeQuery.put("ecnum", enzyme); query.put("$ne", enzymeQuery); for (Long substrate : substrates) { BasicDBList queryList = new BasicDBList(); DBObject querySubstrate = new BasicDBObject(); querySubstrate.put("enz_summary.substrates.pubchem", substrate); DBObject queryProduct = new BasicDBObject(); queryProduct.put("enz_summary.products.pubchem", substrate); queryList.add(querySubstrate);//ww w. ja va 2 s . c om queryList.add(queryProduct); query.put("$or", queryList); } DBCursor cur = this.dbReactions.find(query); List<Long> reactions = new ArrayList<Long>(); while (cur.hasNext()) { DBObject o = cur.next(); long id = (Integer) o.get("_id"); // checked: db type IS int reactions.add(id); } cur.close(); return reactions; }
From source file:act.server.MongoDB.java
License:Open Source License
public List<Chemical> constructAllChemicalsFromActData(String field, Object val, BasicDBObject keys) { DBCursor cur = constructCursorForMatchingChemicals(field, val, keys); List<Chemical> chems = new ArrayList<Chemical>(); while (cur.hasNext()) chems.add(convertDBObjectToChemical(cur.next())); cur.close(); return chems; }
From source file:act.server.MongoDB.java
License:Open Source License
public Map<String, Long> constructAllInChIs() { Map<String, Long> chems = new HashMap<String, Long>(); BasicDBObject keys = new BasicDBObject(); keys.append("_id", true); keys.append("InChI", true); DBCursor cur = constructCursorForMatchingChemicals(null, null, keys); while (cur.hasNext()) { DBObject o = cur.next();//from w w w .ja v a 2 s .c o m long uuid = (Long) o.get("_id"); // checked: db type IS long String inchi = (String) o.get("InChI"); chems.put(inchi, uuid); } cur.close(); return chems; }
From source file:act.server.MongoDB.java
License:Open Source License
public void smartsMatchAllChemicals(String target) { Indigo indigo = new Indigo(); IndigoInchi inchi = new IndigoInchi(indigo); IndigoObject query = indigo.loadSmarts(target); query.optimize();// ww w . j a v a2 s.c om DBCursor cur = constructCursorForAllChemicals(); IndigoObject mol = null, matcher; int cnt; while (cur.hasNext()) { Chemical c = convertDBObjectToChemical(cur.next()); try { mol = inchi.loadMolecule(c.getInChI()); } catch (IndigoException e) { if (e.getMessage().startsWith("core: Indigo-InChI: InChI loading failed:")) continue; // could not load } matcher = indigo.substructureMatcher(mol); if ((cnt = matcher.countMatches(query)) > 0) { // matches.add(c); memout's System.out.format("%d\t%s\n", c.getUuid(), c.getInChI()); } } cur.close(); }
From source file:act.server.MongoDB.java
License:Open Source License
private List<Chemical> keywordInChemicals(String in_field, String keyword) { List<Chemical> chemicals = new ArrayList<Chemical>(); DBCursor cur = constructCursorForMatchingChemicals(in_field, keyword, null); while (cur.hasNext()) { DBObject o = cur.next();/*from ww w. j a va 2 s . c om*/ chemicals.add(convertDBObjectToChemical(o)); } cur.close(); return chemicals; }