List of usage examples for com.mongodb.util JSON parse
public static Object parse(final String jsonString)
Parses a JSON string and returns a corresponding Java object.
From source file:applango.common.services.DB.mongo.mongoDB.java
public static int getPriceByLicenseType(DBCollection appInfoConnection, String licenseType) { String jsonCustomer = "{$and : [{'licenseType' : '" + licenseType + "'}, {'customerId': 'automationCustomer'} ]}"; DBObject dbObjectRecordQuery = (DBObject) JSON.parse(jsonCustomer); Object strPrice = appInfoConnection.find(dbObjectRecordQuery).next().get("price"); System.out.println("The price for " + licenseType + " is " + strPrice); return (Integer) strPrice; }
From source file:applango.common.services.DB.mongo.mongoDB.java
public static void updateLicensePrice(DBCollection appInfoConnection, String licenseType, int newPrice) { System.out.println("Updating license price of " + licenseType + " to " + newPrice); String jsonCustomer = "{$and : [{'licenseType' : '" + licenseType + "'}, {'customerId': 'automationCustomer'} ]}"; DBObject dbObjectRecordQuery = (DBObject) JSON.parse(jsonCustomer); BasicDBObject set = new BasicDBObject("$set", new BasicDBObject("price", newPrice)); appInfoConnection.update(dbObjectRecordQuery, set); System.out.println("The new price for " + licenseType + " is " + newPrice); }
From source file:applango.common.services.DB.mongo.mongoDB.java
public static void updateCustomerAppRankWeightSet(DBCollection appInfoConnection, String weightName, boolean defaultWeightSet) { System.out.println("Updating " + weightName + " to " + defaultWeightSet); String jsonCustomer = "{$and : [{'weightName' : '" + weightName + "'}, {'customerId': 'automationCustomer'} ]}"; DBObject dbObjectRecordQuery = (DBObject) JSON.parse(jsonCustomer); BasicDBObject set = new BasicDBObject("$set", new BasicDBObject("defaultWeightSet", defaultWeightSet)); appInfoConnection.update(dbObjectRecordQuery, set); System.out.println("CustomerAppRankWeightSet for " + weightName + " is " + defaultWeightSet); }
From source file:applango.common.services.DB.mongo.mongoDB.java
public static String getActivityWeight(DBCollection coll, String weightName) { String activityWeight;//from w ww .j ava 2 s .c om int maxWait = 10; try { String jsonCustomer = "{$and : [{'weightName' : '" + weightName + "'}, {'customerId': 'automationCustomer'} ]}"; DBObject dbObjectRecordQuery = (DBObject) JSON.parse(jsonCustomer); while ((coll.count(dbObjectRecordQuery) == 0) && maxWait > 0) { sleep(1000); maxWait--; } activityWeight = coll.find(dbObjectRecordQuery).next().get("activityWeight").toString(); } catch (Exception ex) { activityWeight = null; logger.error(ex.getMessage()); } return activityWeight; }
From source file:br.ufabc.impress.mongo.manager.DBHelper.java
@Override public String add(String tableName, String json) { if (tableName == null || tableName.equals("") || json == null || json.equals("")) { return "501"; }// w w w .j av a2s . c om DBCollection table = db.getCollection(tableName); DBObject dbObject = (DBObject) JSON.parse(json); WriteResult wRes = table.insert(dbObject); return ((ObjectId) dbObject.get("_id")).toString(); }
From source file:br.ufabc.impress.mongo.manager.DBHelper.java
@Override public String addDefault(String tableName, String json) { if (tableName == null || tableName.equals("") || json == null || json.equals("")) { return "501"; }//from w w w. ja v a2 s.co m DBCollection table = db.getCollection(tableName); DBObject dbObject = (DBObject) JSON.parse(json); dbObject.put("status", "active"); dbObject.put("createDate", System.currentTimeMillis() + ""); dbObject.put("updateDate", System.currentTimeMillis() + ""); WriteResult wRes = table.insert(dbObject); return ((ObjectId) dbObject.get("_id")).toString(); }
From source file:br.ufabc.impress.mongo.manager.DBHelper.java
@Override public boolean modify(String tableName, String json, String _id) { if (tableName == null || tableName.equals("") || json == null || json.equals("") || _id == null || _id.equals("")) { return false; }//from www . j a va 2s . com DBCollection table = db.getCollection(tableName); BasicDBObject searchQuery = new BasicDBObject(); searchQuery.put("_id", new ObjectId(_id)); DBObject dbObject = (DBObject) JSON.parse(json); dbObject.put("update", System.currentTimeMillis() + ""); WriteResult result = table.update(searchQuery, dbObject); return result.isUpdateOfExisting(); }
From source file:br.ufabc.impress.mongo.manager.DBHelper.java
@Override public boolean modifyByCondition(String tableName, String json, Map condition) { if (tableName == null || tableName.equals("") || json == null || json.equals("") || condition == null || condition.isEmpty()) {/*from w w w . ja v a 2 s . co m*/ return false; } DBCollection table = db.getCollection(tableName); BasicDBObject searchQuery = new BasicDBObject(condition); DBObject dbObject = (DBObject) JSON.parse(json); dbObject.put("update", System.currentTimeMillis() + ""); WriteResult result = table.update(searchQuery, dbObject); return result.isUpdateOfExisting(); }
From source file:br.ufabc.impress.mongo.manager.DBHelper.java
@Override public List<Boolean> modifyNotOveride(String tableName, String json, String _id) { if (tableName == null || tableName.equals("") || json == null || json.equals("") || _id == null || _id.equals("")) { return null; }// w w w .ja va 2 s . c o m List<Boolean> resList = new ArrayList(); DBCollection table = db.getCollection(tableName); DBCursor cursor = table.find(); while (cursor.hasNext()) { DBObject updateDocument = cursor.next(); DBObject searchQuery = cursor.next(); DBObject dbObject = (DBObject) JSON.parse(json); updateDocument.putAll(dbObject.toMap()); updateDocument.removeField("_id"); WriteResult result = table.update(searchQuery, updateDocument); resList.add(result.isUpdateOfExisting()); } return resList; }
From source file:calliope.core.database.MongoConnection.java
License:Open Source License
/** * PUT a json file to the database//from www . jav a 2s . com * @param collName the name of the collection * @param docID the docid of the resource * @param json the json to put there * @return the server response */ @Override public String putToDb(String collName, String docID, String json) throws DbException { try { DBObject doc = (DBObject) JSON.parse(json); doc.put(JSONKeys.DOCID, docID); connect(); DBCollection coll = getCollectionFromName(collName); DBObject query = new BasicDBObject(JSONKeys.DOCID, docID); WriteResult result = coll.update(query, doc, true, false); //return removeFromDb( path ); return result.toString(); } catch (Exception e) { throw new DbException(e); } }