List of usage examples for com.mongodb BasicDBObject BasicDBObject
public BasicDBObject(final String key, final Object value)
From source file:act.installer.reachablesexplorer.Loader.java
License:Open Source License
Reachable queryById(Long id) { DBObject query = new BasicDBObject(Reachable.ID_FIELD_NAME, id); return jacksonReachablesCollection.findOne(query); }
From source file:act.installer.reachablesexplorer.WordCloudGenerator.java
License:Open Source License
public Set<String> getBingInchis() { BasicDBObject query = new BasicDBObject("xref.BING.metadata.usage_terms.0", new BasicDBObject(MongoKeywords.EXISTS$.MODULE$.value(), true)); BasicDBObject keys = new BasicDBObject(ChemicalKeywords.INCHI$.MODULE$.value(), true); DBIterator ite = bingDb.getIteratorOverChemicals(query, keys); Set<String> bingSet = new HashSet<>(); while (ite.hasNext()) { BasicDBObject o = (BasicDBObject) ite.next(); String inchi = o.getString(ChemicalKeywords.INCHI$.MODULE$.value()); if (inchi != null) { bingSet.add(inchi);//from w w w .ja v a 2 s . c o m } } return bingSet; }
From source file:act.server.MongoDB.java
License:Open Source License
/** * Appends XRef data for the chemical with the specified inchi. Might only apply to Metacyc for now. Does not crash * if idPath or metaPath are null.//from w w w. jav a 2 s. c o m * * This uses Mongo's query mechanism to add new ids to a set of xref ids only if they don't already exist, and to * append (without comparison) new xref metadata to an existing list without having to read/de-serialize/add/serialize * the object ourselves. This results in a significant performance improvement, especially towards the end of the * Metacyc installation process. * * TODO: this API is awful. Fix it up to be less Metacyc-specific and more explicit in its behavior. * * @param inchi The inchi of the chemical to update in Mongo. * @param idPath The path to the field where ids should be added, like xref.METACYC.id. * @param id The id for this chemical reference to write. * @param metaPath The path to the field where metadata blobs should be stored, like xref.METACYC.meta. * @param metaObjects A list of metadata objects to append to the metadata list in Mongo. */ public void appendChemicalXRefMetadata(String inchi, String idPath, String id, String metaPath, BasicDBList metaObjects) { if (idPath == null && metaPath == null) { return; } // Get chemical by InChI. BasicDBObject query = new BasicDBObject("InChI", inchi); BasicDBObject update = new BasicDBObject(); if (idPath != null) { // Add to set will add an id to the array of xref ids only if it doesn't already exist in the array. update.put("$addToSet", new BasicDBObject(idPath, id)); } if (metaPath != null) { /* Add all metadata objects to the xref list containing metadata for this source. * Note: $push + $each applied to an array of objects is like $pushAll, which is now deprecated. */ update.put("$push", new BasicDBObject(metaPath, new BasicDBObject("$each", metaObjects))); } // Run exactly one query to update, which should save a lot of time over the course of the installation. this.dbChemicals.update(query, update); }
From source file:act.server.MongoDB.java
License:Open Source License
public void updateChemicalWithRoBinningInformation(long id, List<Integer> matchedROs) { BasicDBObject query = new BasicDBObject("_id", id); BasicDBObject createDerivedDataContainer = new BasicDBObject("$set", new BasicDBObject("derived_data", new BasicDBObject())); this.dbChemicals.update(query, createDerivedDataContainer); BasicDBList listOfRos = new BasicDBList(); listOfRos.addAll(matchedROs);/*from w w w.j ava2s.c o m*/ BasicDBObject updateDerivedDataContainerWithMatchedRos = new BasicDBObject("$set", new BasicDBObject("derived_data.matched_ros", listOfRos)); this.dbChemicals.update(query, updateDerivedDataContainerWithMatchedRos); }
From source file:act.server.MongoDB.java
License:Open Source License
public boolean alreadyEnteredChemical(String inchi) { if (this.dbChemicals == null) return false; // TODO: should this throw an exception instead? BasicDBObject query = new BasicDBObject("InChI", inchi); long c = this.dbChemicals.count(query); return c > 0; }
From source file:act.server.MongoDB.java
License:Open Source License
public Long getExistingDBIdForInChI(String inchi) { // TODO: should this return some UUID type instead of Long? if (this.dbChemicals == null) return null; // TODO: should this throw an exception instead? BasicDBObject query = new BasicDBObject("InChI", inchi); BasicDBObject fields = new BasicDBObject("_id", true); DBObject o = this.dbChemicals.findOne(query, fields); if (o == null) { return null; }// w ww .ja v a 2 s . c o m // TODO: does this need to be checked? return (Long) o.get("_id"); }
From source file:act.server.MongoDB.java
License:Open Source License
public Iterator<String> getIteratorOverInchis(BasicDBObject matchCriterion) { BasicDBObject keys = new BasicDBObject(ChemicalKeywords.INCHI$.MODULE$.toString(), true); final DBIterator iter = getIteratorOverChemicals(matchCriterion, keys); return new Iterator<String>() { @Override/*from ww w . j ava2s.c o m*/ public boolean hasNext() { boolean hasNext = iter.hasNext(); if (!hasNext) iter.close(); return hasNext; } @Override public String next() { DBObject o = iter.next(); return (String) o.get("InChI"); } }; }
From source file:act.server.MongoDB.java
License:Open Source License
public Iterator<Chemical> getChemicalsbyIds(List<Long> ids, boolean notimeout) { BasicDBList queryList = new BasicDBList(); for (Long id : ids) { queryList.add(new BasicDBObject(ChemicalKeywords.ID$.MODULE$.toString(), id)); }/* w w w . j a v a 2s.com*/ return getJavaIteratorOverChemicals(new BasicDBObject(MongoKeywords.OR$.MODULE$.toString(), queryList)); }
From source file:act.server.MongoDB.java
License:Open Source License
public Iterator<Reaction> getReactionsIteratorById(List<Long> ids, boolean notimeout) { BasicDBList reactionList = new BasicDBList(); for (Long id : ids) { reactionList.add(new BasicDBObject(ChemicalKeywords.ID$.MODULE$.toString(), id)); }/* ww w . j av a2 s . com*/ BasicDBObject query = new BasicDBObject(MongoKeywords.OR$.MODULE$.toString(), reactionList); final DBIterator iter = getIteratorOverReactions(query, null); return new Iterator<Reaction>() { @Override public boolean hasNext() { boolean hasNext = iter.hasNext(); if (!hasNext) iter.close(); return hasNext; } @Override public Reaction next() { DBObject o = iter.next(); return convertDBObjectToReaction(o); } }; }
From source file:act.server.MongoDB.java
License:Open Source License
public Seq getSeqFromSequence(String seq) { DBObject o = this.dbSeq.findOne(new BasicDBObject("seq", seq), new BasicDBObject()); if (o == null) return null; return convertDBObjectToSeq(o); }