List of usage examples for com.mongodb.util JSON JSON
JSON
From source file:br.ufabc.impress.mongo.manager.DBHelper.java
@Override public String getAll(String tableName) { if (tableName == null || tableName.equals("")) { return "501"; }// w w w .j a va2 s.c o m String row = ""; DBCollection table = db.getCollection(tableName); BasicDBObject searchQuery = new BasicDBObject(); searchQuery.put("status", "active"); DBCursor cursor = table.find(searchQuery); if (cursor.size() > 0) { JSON json = new JSON(); row = json.serialize(cursor); cursor.close(); return row; } else { cursor.close(); return null; } }
From source file:br.ufabc.impress.mongo.manager.DBHelper.java
@Override public String getByKey(String tableName, String _id) { if (tableName == null || tableName.equals("") || _id == null || _id.equals("")) { return "501"; }//from w ww. ja v a 2 s . com String row = null; DBCursor cursor = null; DBCollection table = db.getCollection(tableName); BasicDBObject searchQuery = new BasicDBObject(); searchQuery.put("_id", new ObjectId(_id)); cursor = table.find(searchQuery); if (cursor.size() > 0) { JSON json = new JSON(); row = json.serialize(cursor); cursor.close(); return row; } else { cursor.close(); return null; } }
From source file:br.ufabc.impress.mongo.manager.DBHelper.java
@Override public String getByCondition(String tableName, Map condition) { if (tableName == null || tableName.equals("") || condition == null || condition.equals("")) { return "501"; }//from www . j a va 2 s.c o m String row = ""; DBCollection table = db.getCollection(tableName); BasicDBObject searchQuery = new BasicDBObject(condition); BasicDBObject andQuery = new BasicDBObject(); andQuery.put("$and", searchQuery); DBCursor cursor = table.find(searchQuery); if (cursor.size() > 0) { JSON json = new JSON(); row = json.serialize(cursor); cursor.close(); return row; } else { cursor.close(); return null; } }
From source file:eu.artist.cloud.auditors.AbstractedAvailabilityLogger.java
License:Open Source License
/** * @param args/* ww w.ja v a 2 s. com*/ */ public void logAvailability(ArrayList<String> TemplateIDs, String DBuser, String DBpass, String databaseIP) throws UnknownHostException, MongoException { // TODO Auto-generated method stub //needs to be periodic - but periodicity may be on the previous level-> Availability Auditor //better on the Availability Auditor level, since it will have refreshed also the state //needs to raise one thread per node, concurrent requests for all nodes? //sla is per template id? logically yes, so thread must be per template id //mongodb connection //we need to pass an object that will be the DB record and will contain all necessary information //this object will be transformed to json //more efficient to pass an arraylist of these objects (for all template IDs in one sample) and make once //the connection to the DB (for needed in the basic operation) for (String record : TemplateIDs) { Mongo mongoClient = new Mongo(databaseIP); DB db = mongoClient.getDB("3alib"); System.out.println("Host address for Backend DB:" + databaseIP); Set<String> colls = db.getCollectionNames(); for (String s : colls) { System.out.println("These are the collections... " + s); } DBCollection coll = db.getCollection("log_samples"); //log sample /*BasicDBObject doc = new BasicDBObject("name1", "MongoDB2"). append("type", "database"). append("count", 1). append("info", new BasicDBObject("x", 203).append("y", 102)); */ //DBObject obj=new DBObject(); JSON jsonObj = new JSON(); DBObject obj = (DBObject) jsonObj.parse(record); //BasicDBObject doc=new BasicDBObject(record); ObjectId obid = new ObjectId(); //System.out.println("This is the id:"+obj.get("_id")); coll.insert(obj); DBObject myDoc = coll.findOne(); //System.out.println(myDoc); //coll. mongoClient.close(); //log file must be per template ID so that it can be appended each time, if we start stop the auditing action //ideally templateID_month_year //return 0; } System.out.println("Records included"); }
From source file:nosqltools.DBConnection.java
/** * This method returns JSON data found in the collection to be loaded in Panel_Text * /* ww w. j av a2 s .c o m*/ */ public StringBuilder getCollectionData(String coll) { StringBuilder res = new StringBuilder(); if (checkSystemColl(coll)) { collection = db.getCollection(coll); DBCursor cursor = collection.find(); //Reference: http://www.codeconfuse.com/2014/03/mongodb-convert-data-getting-from.html JSON json = new JSON(); String serialize = json.serialize(cursor); System.out.println(serialize); res.append(serialize); } else { res = null; } return res; }
From source file:org.uom.fit.level2.datavis.repository.ChatServicesImpl.java
@Override public JSONArray getAll() { try {/* www. j a v a2s .co m*/ Mongo mongo = new Mongo("localhost", 27017); DB db = mongo.getDB("datarepo"); DBCollection collection = db.getCollection("user"); DBCursor cursor = collection.find(); JSON json = new JSON(); String dataUser = json.serialize(cursor); JSONParser parser = new JSONParser(); Object obj = parser.parse(dataUser); JSONArray jsonarray = (JSONArray) obj; return jsonarray; } catch (Exception e) { System.out.println("Exception Error getAll"); return null; } }
From source file:org.uom.fit.level2.datavis.repository.ChatServicesImpl.java
@Override public JSONArray getAllChatData(String message) { try {/* w w w . j ava 2 s.com*/ Mongo mongo = new Mongo("localhost", 27017); DB db = mongo.getDB("chat"); DBCollection collection = db.getCollection("message"); BasicDBObject whereQuery = new BasicDBObject(); BasicDBObject field = new BasicDBObject(); BasicDBObject sortQuery = new BasicDBObject(); whereQuery.put("message", message); field.put("senderName", 1); field.put("message", 1); field.put("receiverName", 1); field.put("imageData", 1); field.put("discription", 1); sortQuery.put("DateTime", 1); DBCursor cursor = collection.find(whereQuery, field).sort(sortQuery); JSON json = new JSON(); String dataUser = json.serialize(cursor); JSONParser parser = new JSONParser(); Object obj = parser.parse(dataUser); JSONArray jsonarray = (JSONArray) obj; return jsonarray; } catch (Exception e) { System.out.println("Exception Error getAll"); return null; } }