List of usage examples for com.mongodb BasicDBObject BasicDBObject
public BasicDBObject()
From source file:br.bireme.scl.BrokenLinks.java
License:Open Source License
/** * Creates the CC Fields Collection and insert a lilacs metadoc document. * @param coll CC Fields Collection// w ww.ja va 2 s . c o m * @return true if ok, false if error */ private static boolean createCcFieldsCollection(final DBCollection coll) { assert coll != null; final BasicDBObject doc = new BasicDBObject(); final BasicDBList lst = new BasicDBList(); lst.add(1); lst.add(920); lst.add(930); doc.put(MST_FIELD, "LILACS"); doc.put(ID_TAG_FIELD, 2); doc.put(URL_TAG_FIELD, 8); doc.put(CC_TAGS_FIELD, lst); final WriteResult ret = coll.save(doc, WriteConcern.ACKNOWLEDGED); return ret.getCachedLastError().ok(); }
From source file:br.bireme.scl.BrokenLinks.java
License:Open Source License
private static void createIndex(final DBCollection coll) { assert coll != null; final BasicDBObject flds = new BasicDBObject(); flds.append(CENTER_FIELD, 1);//from ww w . j a v a 2 s. co m flds.append(BROKEN_URL_FIELD, 1); //Btree::insert: key too large to index flds.append(MST_FIELD, 1); coll.ensureIndex(flds); }
From source file:br.bireme.scl.MongoOperations.java
License:Open Source License
public static SearchResult getDocuments(final DBCollection coll, final String docMast, final String docId, final String docUrl, final Set<String> centerIds, final boolean decreasingOrder, final int from, final int count) { if (coll == null) { throw new NullPointerException("coll"); }/*from ww w .j av a2 s.c o m*/ if (from < 1) { throw new IllegalArgumentException("from[" + from + "] < 1"); } if (count < 1) { throw new IllegalArgumentException("count[" + count + "] < 1"); } final List<IdUrl> lst = new ArrayList<IdUrl>(); final BasicDBObject query = new BasicDBObject(); if (docMast != null) { query.append(MST_FIELD, docMast); } if (docId != null) { final Pattern pat = Pattern.compile("^" + docId.trim() + "_\\d+"); query.append(ID_FIELD, pat); } if (docUrl != null) { query.append(BROKEN_URL_FIELD, docUrl.trim()); } if (centerIds != null) { final BasicDBList cclst = new BasicDBList(); for (String centerId : centerIds) { cclst.add(centerId); } final BasicDBObject in = new BasicDBObject("$in", cclst); query.append(CENTER_FIELD, in); } final BasicDBObject sort = new BasicDBObject(DATE_FIELD, decreasingOrder ? -1 : 1); final DBCursor cursor = coll.find(query).sort(sort).skip(from - 1).limit(count); final int size = cursor.count(); final SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy"); while (cursor.hasNext()) { final DBObject doc = cursor.next(); final BasicDBList ccsLst = (BasicDBList) doc.get(CENTER_FIELD); final Set<String> ccs = new TreeSet<String>(); for (Object cc : ccsLst) { ccs.add((String) cc); } final IdUrl iu = new IdUrl((String) doc.get(ID_FIELD), (String) doc.get(PRETTY_BROKEN_URL_FIELD), ccs, format.format((Date) (doc.get(DATE_FIELD))), (String) doc.get(MST_FIELD)); lst.add(iu); } cursor.close(); return new SearchResult(size, lst); }
From source file:br.bireme.scl.MongoOperations.java
License:Open Source License
public static SearchResult2 getHistoryDocuments(final DBCollection coll, final Element elem, final int from, final int count) throws IOException, ParseException { if (coll == null) { throw new NullPointerException("coll"); }/*from ww w. ja va 2 s .c o m*/ if (elem == null) { throw new NullPointerException("elem"); } if (from < 1) { throw new IllegalArgumentException("from[" + from + "] < 1"); } if (count < 1) { throw new IllegalArgumentException("count[" + count + "] < 1"); } final List<Element> lst = new ArrayList<Element>(); final BasicDBObject query = new BasicDBObject(); final String root = ELEM_LST_FIELD + ".0."; final String updated = root + LAST_UPDATE_FIELD; if (elem.getDbase() != null) { query.append(MST_FIELD, elem.getDbase().trim()); } if (elem.getId() != null) { final Pattern pat = Pattern.compile("^" + elem.getId().trim() + "_\\d+"); query.append(ID_FIELD, pat); } if (elem.getFurl() != null) { query.append(root + FIXED_URL_FIELD, elem.getFurl().trim()); } if (!elem.getCcs().isEmpty()) { final BasicDBList cclst = new BasicDBList(); for (String centerId : elem.getCcs()) { cclst.add(centerId.trim()); } final String cc = root + CENTER_FIELD; final BasicDBObject in = new BasicDBObject("$in", cclst); query.append(cc, in); } if (elem.getDate() != null) { final SimpleDateFormat simple = new SimpleDateFormat("dd-MM-yyyy"); final Date date = simple.parse(elem.getDate().trim()); final BasicDBObject qdate = new BasicDBObject("$gte", date); query.append(updated, qdate); } if (elem.getUser() != null) { final String user = root + USER_FIELD; query.append(user, elem.getUser().trim()); } final BasicDBObject sort = new BasicDBObject(updated, -1); final DBCursor cursor = coll.find(query).sort(sort).skip(from - 1).limit(count); final int size = cursor.count(); final SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy"); while (cursor.hasNext()) { final BasicDBObject hdoc = (BasicDBObject) cursor.next(); final BasicDBList elst = (BasicDBList) hdoc.get(ELEM_LST_FIELD); final BasicDBObject hcurdoc = (BasicDBObject) elst.get(0); if (hcurdoc == null) { throw new IOException("document last element found."); } final BasicDBList ccLst = (BasicDBList) hcurdoc.get(CENTER_FIELD); final List<String> ccs = Arrays.asList(ccLst.toArray(new String[0])); final Element elem2 = new Element(hdoc.getString(ID_FIELD), hcurdoc.getString(BROKEN_URL_FIELD), hcurdoc.getString(PRETTY_BROKEN_URL_FIELD), hcurdoc.getString(FIXED_URL_FIELD), hdoc.getString(MST_FIELD), format.format((Date) (hcurdoc.get(LAST_UPDATE_FIELD))), hcurdoc.getString(USER_FIELD), ccs, hcurdoc.getBoolean(EXPORTED_FIELD)); lst.add(elem2); } cursor.close(); return new SearchResult2(size, lst.size(), lst); }
From source file:br.com.binarti.simplesearchexpr.builders.mongodb.SimpleSearchMongoDBBuilder.java
License:Open Source License
@Override public DBObject build(SimpleSearchExpression searchExpression) { BasicDBObject root = new BasicDBObject(); if (searchExpression.getOperations().isEmpty()) { return root; }//from w w w. j ava 2 s . c o m for (SimpleSearchRelationalOperation op : searchExpression.getOperations()) { final String field = op.getField().getFieldExpr(); final Object value = op.getValue(); switch (op.getOperator()) { case EQUALS: root.put(field, value); break; case LIKE: root.put(field, new BasicDBObject("$regex", StringUtils.trim((String) value)).append("$options", "i")); break; case INTERVAL: Iterator<Object> it = op.getValueAsCollection().iterator(); Object value1 = it.next(); Object value2; if (it.hasNext()) { value2 = it.next(); } else { value2 = value1; } root.append(field, new BasicDBObject("$gte", value1).append("$lte", value2)); break; case LIST: root.append(field, new BasicDBObject("$in", mongoList(op.getValueAsCollection()))); break; default: throw new SimpleSearchExpressionException("Operator " + op.getOperator() + " not supported"); } } return root; }
From source file:br.com.ezequieljuliano.argos.template.StandardDAO.java
License:Apache License
private CommandResult executeFullTextSearch(String collectionName, String searchString, Criteria filterCriteria, long limit) { BasicDBObject textSearch = new BasicDBObject(); textSearch.put("text", collectionName); textSearch.put("search", searchString); if (filterCriteria != null) { textSearch.put("filter", Query.query(filterCriteria).getQueryObject()); }/* w w w .j av a2 s . c o m*/ if (limit > 0) { textSearch.put("limit", limit); } return getMongoOperations().executeCommand(textSearch); }
From source file:br.com.ifspsaocarlos.gastock.models.MCombustivel.java
@Override public int adicionar(Combustivel combustivel) { try {/*from w ww . j av a 2s . c o m*/ this.listar(); } catch (Exception ex) { } int cod = c.get(c.size() - 1).getCombustivel() + 1; combustivel.setCombustivel(cod); c.add(combustivel); BasicDBObject insert = new BasicDBObject(); insert.put("cod", combustivel.getCombustivel()); insert.put("nome", combustivel.getNome()); insert.put("preco", combustivel.getPreco()); this.banco.cadastraItem(insert); return combustivel.getCombustivel(); }
From source file:br.com.ifspsaocarlos.gastock.models.MCombustivel.java
@Override public void modificar(Combustivel combustivel) throws Exception { BasicDBObject set = new BasicDBObject(); int codigo = combustivel.getCombustivel(); set.put("nome", combustivel.getNome()); set.put("preco", combustivel.getPreco()); BasicDBObject update = new BasicDBObject("$set", set); this.banco.alterarItem(codigo, update); }
From source file:br.com.ifspsaocarlos.gastock.models.MCombustivel.java
@Override public void excluir(int combustivelId) throws Exception { BasicDBObject delete = new BasicDBObject(); delete.put("cod", combustivelId); this.banco.excluirItem(delete); }
From source file:br.com.ifspsaocarlos.gastock.models.MFrentista.java
@Override public int adicionar(Frentista frentista) { try {/* w ww . ja va 2 s. c o m*/ this.listar(); } catch (Exception ex) { } int cod = c.get(c.size() - 1).getFrentista() + 1; frentista.setFrentista(cod); c.add(frentista); BasicDBObject insert = new BasicDBObject(); insert.put("cod", frentista.getFrentista()); insert.put("nome", frentista.getNome()); insert.put("senha", frentista.getSenha()); insert.put("tipo", frentista.getTipo()); insert.put("salario", frentista.getSalario()); this.banco.cadastraItem(insert); return frentista.getFrentista(); }