List of usage examples for com.mongodb BasicDBObject BasicDBObject
public BasicDBObject()
From source file:be.datablend.blueprints.impls.mongodb.MongoDBQuery.java
@Override public GraphQuery has(String key, Object value) { super.has(key, value); String mongoKey = MongoDBUtil.createPropertyKey(key); if (query.containsField(mongoKey)) { List<DBObject> andValues = null; if (query.containsField("$and")) { andValues = (List<DBObject>) query.get("$and"); } else {/* ww w . j a v a 2s. c o m*/ andValues = new ArrayList<DBObject>(); } andValues.add(new BasicDBObject().append(mongoKey, value)); andValues.add(new BasicDBObject().append(mongoKey, query.remove(mongoKey))); query.append("$and", andValues); } else { query.append(MongoDBUtil.createPropertyKey(key), value); } return this; }
From source file:be.datablend.blueprints.impls.mongodb.MongoDBQuery.java
@Override public <T extends Comparable<?>> GraphQuery interval(String key, T startValue, T endValue) { BasicDBObject queryObj = new BasicDBObject().append("$gte", startValue).append("$lt", endValue); this.query.append(MongoDBUtil.createPropertyKey(key), queryObj); return this; // return super.interval(key, startValue, endValue); //To change body of generated methods, choose Tools | Templates. }
From source file:bhl.pages.database.MongoConnection.java
License:Open Source License
/** * List all the documents in a Mongo collection * @param collName the name of the collection * @param key the document key to retrieve by * @return a String array of document keys * @throws DbException //from ww w . j av a 2s. c o m */ @Override public String[] listCollectionByKey(String collName, String key) throws DbException { try { connect(); } catch (Exception e) { throw new DbException(e); } DBCollection coll = getCollectionFromName(collName); BasicDBObject keys = new BasicDBObject(); keys.put(key, 1); DBCursor cursor = coll.find(new BasicDBObject(), keys); if (cursor.length() > 0) { String[] docs = new String[cursor.length()]; Iterator<DBObject> iter = cursor.iterator(); int i = 0; while (iter.hasNext()) { Object obj = iter.next().get(key); docs[i++] = obj.toString(); } return docs; } else throw new DbException("no docs in collection " + collName); }
From source file:bhl.pages.database.MongoConnection.java
License:Open Source License
/** * Get the content of the given page and document * @param docid the document identifier (an integer in BHL) * @param pageid the page identifier (NOT page_sequence) also an int * @return the textual content as a String * @throws Exception /*www .jav a 2s . co m*/ */ public String getPageContent(String docid, String pageid) throws DbException { try { if (docid != null && pageid != null) { connect(); DBCollection coll = db.getCollection(Database.PAGES); BasicDBObject ref = new BasicDBObject(); ref.put(JSONKeys.IA_IDENTIFIER, docid); ref.put(JSONKeys.BHL_PAGE_ID, Integer.parseInt(pageid)); BasicDBObject key = new BasicDBObject(); key.put(JSONKeys.PAGE_SEQUENCE, 1); DBObject obj = coll.findOne(ref, key); if (obj != null) { Object pobj = obj.get(JSONKeys.PAGE_SEQUENCE); int pageNo = ((Number) pobj).intValue(); DBCollection coll2 = db.getCollection(Database.DOCUMENTS); BasicDBObject ref2 = new BasicDBObject(); ref2.put(JSONKeys.IA_IDENTIFIER, docid); ref2.put(JSONKeys.PAGE_SEQUENCE, pageNo); BasicDBObject key2 = new BasicDBObject(); key2.put(JSONKeys.CONTENT, 1); Object obj2 = coll2.findOne(ref2, key2); if (obj2 != null) return (String) ((DBObject) obj2).get(JSONKeys.CONTENT); else throw new Exception("could not find content for docid=" + docid + ", pageid=" + pageid); } else throw new Exception("could not find docid=" + docid + ", pageid=" + pageid); } else throw new Exception("Missing docid or pageid"); } catch (Exception e) { throw new DbException(e); } }
From source file:biopolis.headless.BiopolisSegmentationManagement.java
public void clean() { dbcol.remove(new BasicDBObject()); }
From source file:biopolis.headless.BiopolisSegmentationManagement.java
public void initialPhase() throws SQLException { this.occurs = 0; BasicDBObject master = new BasicDBObject(); master.put("master", "master"); master.put("biopolisttl", new java.util.Date()); dbcol.insert(master);// w w w .j a v a 2s . co m id = (ObjectId) master.get("_id"); byte[] bytes = id.toByteArray(); biopiolisid = Base64.encodeBase64String(bytes); }
From source file:biopolis.headless.BiopolisSegmentationManagement.java
public void iterationPhase(ResultSet resultSet) throws SQLException, BiopolisGeneralException { java.util.Date date = this.updateTTL(); while (resultSet.next()) { long ll = resultSet.getLong(1); BasicDBObject place = new BasicDBObject(); place.put("biopolishandle", this.biopiolisid); place.put("biopolisdata", ll); place.put("biopolisttl", date); dbcol.insert(place);//from www . j a v a 2 s .co m } this.occurs++; }
From source file:biopolis.headless.BiopolisSegmentationManagement.java
public void iterationPhase(DBCursor cur) throws SQLException, BiopolisGeneralException { java.util.Date date = this.updateTTL(); while (cur.hasNext()) { Long name = (Long) cur.next().get("biopolisdata"); BasicDBObject place = new BasicDBObject(); place.put("biopolishandle", this.biopiolisid); place.put("biopolisdata", name); place.put("biopolisttl", date); dbcol.insert(place);/*w w w . j a va 2 s. co m*/ } this.occurs++; }
From source file:booklistmanager.TablefrontController.java
public void search() { if (searchField.getText().isEmpty()) { errorhandle("Search Field is empty"); return;// w w w .j a va 2 s .c o m } String text = searchField.getText(); searchField.clear(); Connector con = new Connector(); con.connect(); MongoCollection<Document> col = con.getData(); BasicDBObject q = new BasicDBObject(); q.put("Name", Pattern.compile("^" + text, Pattern.UNIX_LINES)); forChooser.getItems().add("Search Result for " + text); forChooser.getSelectionModel().clearAndSelect(forChooser.getItems().size() - 1); table.setItems(getBook(col.find(q))); }
From source file:br.bireme.scl.BrokenLinks.java
License:Open Source License
public static int createLinks(final String outCheckFile, final String outEncoding, final String mstName, final String mstEncoding, final String host, final int port, final String user, final String password, final boolean clearCol, final String[] allowedMessages) throws BrumaException, IOException { if (outCheckFile == null) { throw new NullPointerException("outCheckFile"); }//from www . j a v a2 s .c o m if (outEncoding == null) { throw new NullPointerException("outEncoding"); } if (mstName == null) { throw new NullPointerException("mstName"); } if (mstEncoding == null) { throw new NullPointerException("mstEncoding"); } if (host == null) { throw new NullPointerException("host"); } if (port <= 0) { throw new IllegalArgumentException("port <= 0"); } if (allowedMessages == null) { throw new NullPointerException("allowedMessages"); } final Master mst = MasterFactory.getInstance(mstName).setEncoding(mstEncoding).open(); final String mName = new File(mst.getMasterName()).getName(); final BufferedReader in = new BufferedReader( new InputStreamReader(new FileInputStream(outCheckFile), outEncoding)); final MongoClient mongoClient = new MongoClient(host, port); final DB db = mongoClient.getDB(SOCIAL_CHECK_DB); // map -> mfn -> url,occ final Map<Integer, Map<String, Integer>> occMap = new HashMap<Integer, Map<String, Integer>>(); final boolean checkPassword = false; if (checkPassword) { final boolean auth = db.authenticate(user, password.toCharArray()); if (!auth) { throw new IllegalArgumentException("invalid user/password"); } } final DBCollection coll = db.getCollection(BROKEN_LINKS_COL); final DBCollection ccColl = db.getCollection(CC_FIELDS_COL); final DBCollection hColl = db.getCollection(HISTORY_COL); if (ccColl.findOne() == null) { if (!createCcFieldsCollection(ccColl)) { throw new IOException("CC fields collection creation failed"); } } final int idTag = getIsisIdField(mName, ccColl); final int urlTag = getIsisUrlFields(mName, ccColl); if (urlTag <= 0) { throw new IOException("Missing Isis url fields"); } final List<Integer> tags = getIsisCcFields(mName, ccColl); final Set<String> allowedMess = new HashSet<String>(Arrays.asList(allowedMessages)); final Map<String, Integer> idMap = getIdMfn(mst, idTag); int tell = 0; int tot = 0; if (clearCol) { coll.dropIndexes(); coll.remove(new BasicDBObject()); } System.out.println("Saving documents ..."); while (true) { final String line = in.readLine(); if (line == null) { break; } final String lineT = line.trim(); if (!lineT.isEmpty()) { final String[] split = lineT.split(" *\\| *", 4); //id|url|msg|master if (split.length < 4) { throw new IOException("Wrong line format: " + line); } final int openPos = split[2].indexOf('('); // cut extra data final String prefix = (openPos > 0) ? split[2].substring(0, openPos) : split[2]; if (allowedMess.contains(prefix.trim())) { final Integer id = idMap.get(split[0]); if (id == null) { throw new IOException("id[" + split[0] + "] not found"); } final String url_e = EncDecUrl.encodeUrl(split[1], outEncoding, false); saveRecord(mName, id, url_e, split[2], urlTag, tags, mst, coll, hColl, occMap); tot++; } if (++tell % 5000 == 0) { System.out.println("++" + tell); } } } System.out.print("\nFixing urls that do not start with http:// ... "); MongoOperations.fixMissingHttp(coll, hColl); System.out.println(" - OK"); //removeOldDocs(coll); if (clearCol) { createIndex(coll); } in.close(); mst.close(); return tot; }