List of usage examples for com.mongodb DBObject put
Object put(String key, Object v);
From source file:act.server.MongoDB.java
License:Open Source License
public void updateEstimatedEnergy(Reaction reaction) { BasicDBObject query = new BasicDBObject().append("_id", reaction.getUUID()); DBObject obj = this.dbReactions.findOne(query); obj.put("estimateEnergy", reaction.getEstimatedEnergy()); this.dbReactions.update(query, obj); }
From source file:act.server.MongoDB.java
License:Open Source License
public void updateReactionRefsOf(Seq seq) { BasicDBObject query = new BasicDBObject().append("_id", seq.getUUID()); DBObject obj = this.dbSeq.findOne(query); BasicDBList refs = new BasicDBList(); for (Long r : seq.getReactionsCatalyzed()) refs.add(r);/*from w w w . ja va 2s . c om*/ obj.put("rxn_refs", refs); this.dbSeq.update(query, obj); }
From source file:act.server.MongoDB.java
License:Open Source License
public void updateKeywordsCascade(Long id, Set<String> kwrds, Set<String> ciKwrds) { BasicDBObject query = new BasicDBObject().append("_id", id); DBObject obj = this.dbCascades.findOne(query); obj.put("keywords", kwrds); obj.put("keywords_case_insensitive", ciKwrds); this.dbCascades.update(query, obj); }
From source file:act.server.MongoDB.java
License:Open Source License
public void updateKeywordsWaterfall(Long id, Set<String> kwrds, Set<String> ciKwrds) { BasicDBObject query = new BasicDBObject().append("_id", id); DBObject obj = this.dbWaterfalls.findOne(query); obj.put("keywords", kwrds); obj.put("keywords_case_insensitive", ciKwrds); this.dbWaterfalls.update(query, obj); }
From source file:act.server.MongoDB.java
License:Open Source License
public void updateKeywords(Reaction reaction) { BasicDBObject query = new BasicDBObject().append("_id", reaction.getUUID()); DBObject obj = this.dbReactions.findOne(query); obj.put("keywords", reaction.getKeywords()); obj.put("keywords_case_insensitive", reaction.getCaseInsensitiveKeywords()); this.dbReactions.update(query, obj); }
From source file:act.server.MongoDB.java
License:Open Source License
public void updateActReaction(Reaction r, int id) { // db.collection.update(query, update, options) // updates document(s) that match query with the update doc // Ref: http://docs.mongodb.org/manual/reference/method/db.collection.update/ ////from w ww . j a va 2 s. c o m // Update doc: Can be { $set : { <field> : <val> } } // in case you need to keep the old document, but just update // some fields inside of it. // Ref: http://docs.mongodb.org/manual/reference/operator/update/set/ // // But here (and in updateActChemical) we want to overwrite // the entire document with a new one, and so // a simple update call with the new document is what we need. BasicDBObject doc = createReactionDoc(r, id); DBObject query = new BasicDBObject(); query.put("_id", id); this.dbReactions.update(query, doc); }
From source file:act.server.MongoDB.java
License:Open Source License
public static BasicDBObject createReactionDoc(Reaction r, int id) { BasicDBObject doc = new BasicDBObject(); doc.put("_id", id); doc.put("ecnum", r.getECNum()); doc.put("easy_desc", r.getReactionName()); BasicDBList substr = new BasicDBList(); Long[] ss = r.getSubstrates(); for (int i = 0; i < ss.length; i++) { DBObject o = getObject("pubchem", ss[i]); o.put("coefficient", r.getSubstrateCoefficient(ss[i])); substr.put(i, o);//from w w w .j a v a 2 s .c o m } BasicDBList prods = new BasicDBList(); Long[] pp = r.getProducts(); for (int i = 0; i < pp.length; i++) { DBObject o = getObject("pubchem", pp[i]); o.put("coefficient", r.getProductCoefficient(pp[i])); prods.put(i, o); } BasicDBList prodCofactors = new BasicDBList(); Long[] ppc = r.getProductCofactors(); for (int i = 0; i < ppc.length; i++) { DBObject o = getObject("pubchem", ppc[i]); prodCofactors.put(i, o); } BasicDBList substrCofactors = new BasicDBList(); Long[] ssc = r.getSubstrateCofactors(); for (int i = 0; i < ssc.length; i++) { DBObject o = getObject("pubchem", ssc[i]); substrCofactors.put(i, o); } BasicDBList coenzymes = new BasicDBList(); Long[] coenz = r.getCoenzymes(); for (int i = 0; i < coenz.length; i++) { DBObject o = getObject("pubchem", coenz[i]); coenzymes.put(i, o); } BasicDBObject enz = new BasicDBObject(); enz.put("products", prods); enz.put("substrates", substr); enz.put("product_cofactors", prodCofactors); enz.put("substrate_cofactors", substrCofactors); enz.put("coenzymes", coenzymes); doc.put("enz_summary", enz); doc.put("is_abstract", r.getRxnDetailType().name()); if (r.getDataSource() != null) doc.put("datasource", r.getDataSource().name()); if (r.getMechanisticValidatorResult() != null) { doc.put("mechanistic_validator_result", MongoDBToJSON.conv(r.getMechanisticValidatorResult())); } BasicDBList refs = new BasicDBList(); for (P<Reaction.RefDataSource, String> ref : r.getReferences()) { BasicDBObject refEntry = new BasicDBObject(); refEntry.put("src", ref.fst().toString()); refEntry.put("val", ref.snd()); refs.add(refEntry); } doc.put("references", refs); BasicDBList proteins = new BasicDBList(); for (JSONObject proteinData : r.getProteinData()) { proteins.add(MongoDBToJSON.conv(proteinData)); } doc.put("proteins", proteins); ConversionDirectionType cd = r.getConversionDirection(); doc.put("conversion_direction", cd == null ? null : cd.toString()); StepDirection psd = r.getPathwayStepDirection(); doc.put("pathway_step_direction", psd == null ? null : psd.toString()); return doc; }
From source file:act.server.MongoDB.java
License:Open Source License
public void submitToPubmedDB(PubmedEntry entry) { List<String> xPath = new ArrayList<String>(); xPath.add("MedlineCitation"); xPath.add("PMID"); int pmid = Integer.parseInt(entry.getXPathString(xPath)); if (this.dbPubmed != null) { WriteResult result;//w ww . j a v a 2s . co m if (alreadyEntered(entry, pmid)) return; DBObject doc = (DBObject) JSON.parse(entry.toJSON()); doc.put("_id", pmid); this.dbPubmed.insert(doc); } else Logger.printf(0, "Pubmed Entry [%d]: %s\n", pmid, entry); // human readable... }
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);//from w w w . j av a 2 s . c o m 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 long getChemicalIDFromName(String chemName, boolean caseInsensitive) { BasicDBObject query = new BasicDBObject(); DBObject brenda = new BasicDBObject(); DBObject pubchem = new BasicDBObject(); DBObject synonyms = new BasicDBObject(); if (caseInsensitive) { String escapedName = Pattern.quote(chemName); Pattern regex = Pattern.compile("^" + escapedName + "$", Pattern.CASE_INSENSITIVE); brenda.put("names.brenda", regex); pubchem.put("names.pubchem.values", regex); synonyms.put("names.synonyms", regex); } else {/*from ww w. java2 s .co m*/ brenda.put("names.brenda", chemName); pubchem.put("names.pubchem.values", chemName); synonyms.put("names.synonyms", chemName); } BasicDBList ors = new BasicDBList(); ors.add(brenda); ors.add(pubchem); ors.add(synonyms); query.put("$or", ors); Long id; DBObject o = this.dbChemicals.findOne(query); if (o != null) id = (Long) o.get("_id"); // checked: db type IS Long else id = -1L; return id; }