List of usage examples for com.mongodb BasicDBObject BasicDBObject
public BasicDBObject(final String key, final Object value)
From source file:calliope.db.MongoConnection.java
License:Open Source License
/** * Test a Mongo connection by putting, deleting, getting a JSON * file and an image./*w w w . j a va 2 s . c om*/ * @return a String indicating how many tests succeeded */ @Override public String test() { StringBuilder sb = new StringBuilder(); try { byte[] imageData = Base64.decodeBase64(testImage); connect(); String response = putToDb("test", "data/text", testJson); if (checkResponse(response)) { response = getFromDb("test", "data/text"); if (!checkResponse(response)) sb.append("failed put/get test for plain json\n"); else { response = removeFromDb("test", "data/text"); if (!checkResponse(response)) sb.append("failed to remove plain json\n"); } } putImageToDb("corpix", "data/image", imageData); byte[] data = getImageFromDb("corpix", "data/image"); if (data == null || data.length != imageData.length) sb.append("failed put/get test for image\n"); else removeImageFromDb("corpix", "data/image"); DBObject query = new BasicDBObject(JSONKeys.DOCID, "data/image"); GridFS gfs = new GridFS(db, "corpix"); GridFSDBFile file = gfs.findOne(query); if (file != null) sb.append("removed failed for image\n"); } catch (Exception e) { e.printStackTrace(System.out); } return sb.toString(); }
From source file:carrental.beans.billing.BillingBean.java
private int generateInvoiceNumber() throws Exception { DBCursor dbCursor = mongoConfig.mongo().getDB("carrental").getCollection("invoice").find() .sort(new BasicDBObject("number", -1)).limit(1); if (dbCursor.hasNext()) return ((Integer) dbCursor.next().get("number")) + 1; return 1;/*from w ww.j a v a2 s. c om*/ }
From source file:cc.acs.mongofs.gridfs.GridFS.java
License:Apache License
/** * Returns a cursor for this filestore * * @return cursor of file objects/*from w ww . j a v a 2 s. c om*/ */ public DBCursor getFileList() { return _filesCollection.find().sort(new BasicDBObject("filename", 1)); }
From source file:cc.acs.mongofs.gridfs.GridFS.java
License:Apache License
/** * Returns a cursor for this filestore * * @param query filter to apply/* w w w . j a v a 2 s. co m*/ * @return cursor of file objects */ public DBCursor getFileList(DBObject query) { return _filesCollection.find(query).sort(new BasicDBObject("filename", 1)); }
From source file:cc.acs.mongofs.gridfs.GridFS.java
License:Apache License
public GridFSDBFile findOne(ObjectId id) { return findOne(new BasicDBObject("_id", id)); }
From source file:cc.acs.mongofs.gridfs.GridFS.java
License:Apache License
public GridFSDBFile findOne(String filename) { return findOne(new BasicDBObject("filename", filename)); }
From source file:cc.acs.mongofs.gridfs.GridFS.java
License:Apache License
public List<GridFSDBFile> find(String filename) { return find(new BasicDBObject("filename", filename)); }
From source file:cc.acs.mongofs.gridfs.GridFS.java
License:Apache License
public void remove(ObjectId id) { _filesCollection.remove(new BasicDBObject("_id", id)); _chunkCollection.remove(new BasicDBObject("files_id", id)); }
From source file:cc.acs.mongofs.gridfs.GridFS.java
License:Apache License
public void remove(String filename) { remove(new BasicDBObject("filename", filename)); }
From source file:cc.acs.mongofs.gridfs.GridFSDBFile.java
License:Apache License
void remove() { _fs._filesCollection.remove(new BasicDBObject("_id", _id)); _fs._chunkCollection.remove(new BasicDBObject("files_id", _id)); }