List of usage examples for com.mongodb BasicDBObject get
public Object get(final String key)
From source file:org.wikidata.couchbase.ClaimProcessor.java
License:Open Source License
/** * @param path/* ww w .j a v a 2 s .c om*/ */ private void insertClaim(JsonNode claim) { long itemId = -1; if (claim != null && claim.path("value") != null && claim.path("value").path("numeric-id") != null) { itemId = claim.path("value").path("numeric-id").asLong(); } if (LOG.isDebugEnabled()) { LOG.debug("Inserting claim: " + itemId); } BasicDBObject doc = new BasicDBObject("property", propertyName).append("itemid", itemId); doc.put("_id", createId(itemId)); BasicDBObject query = new BasicDBObject("_id", MongoPersistHandler.buildDocumentKey((int) itemId)); DBCursor cursor = getPersistService().find(query); if (cursor.hasNext()) { DBObject labels = (DBObject) ((DBObject) cursor.next().get("item")).get("labels"); List<Object> labelList = new ArrayList<Object>(); for (String lan : languages) { if (labels.get(lan) != null) { labelList.add(labels.get(lan)); } } doc.put("labels", labelList); if (LOG.isDebugEnabled()) { LOG.debug("Labels added to claim: " + doc.get("labels")); } } getPersistService().save(doc); }
From source file:org.zeus.HealthEnhancements.ProviderInfo.java
private ProviderInfo(BasicDBObject dbObject) { m_id = ((ObjectId) dbObject.get("_id")).toString(); m_szUserName = dbObject.getString("m_szUserName"); m_szHashUserPassword = dbObject.getString("m_szHashUserPassword"); m_szProviderType = dbObject.getString("m_szProviderType"); m_szFirstName = dbObject.getString("m_szFirstName"); m_szLastName = dbObject.getString("m_szLastName"); m_szMiddleName = dbObject.getString("m_szMiddleName"); m_szSocialSecurity = dbObject.getString("m_szSocialSecurity"); m_szLicenseNumber = dbObject.getString("m_szLicenseNumber"); m_szPersonnelType = dbObject.getString("m_szPersonnelType"); m_szSpecialization = dbObject.getString("m_szSpecialization"); m_szAffiliation = dbObject.getString("m_szAffiliation"); m_szAddress = dbObject.getString("m_szAddress"); m_szPhoneNumber = dbObject.getString("m_szPhoneNumber"); m_szEmail = dbObject.getString("m_szEmail"); }
From source file:partha.mongodb.manager.DBHelper.java
@Override public String addDefaultMap(String tableName, Map columns) { if (tableName == null || tableName.equals("") || columns == null || columns.equals("")) { return "501"; }//from w w w. j a v a 2 s . c o m columns.put("status", "active"); columns.put("createdate", System.currentTimeMillis() + ""); columns.put("updatedate", System.currentTimeMillis() + ""); DBCollection table = db.getCollection(tableName); BasicDBObject document = new BasicDBObject(columns); WriteResult wRes = table.insert(document); return ((ObjectId) document.get("_id")).toString(); }
From source file:pl.nask.hsn2.os.ObjectStore.java
License:Open Source License
private Builder getBuilder(String key, BasicDBObject objectFound) { Object value = objectFound.get(key); Builder builder = Attribute.newBuilder().setName(key); if (value instanceof Integer || key.equalsIgnoreCase("depth")) { builder.setType(Type.INT).setDataInt(objectFound.getInt(key)); } else if (value instanceof Long) { builder.setType(Type.OBJECT).setDataObject(objectFound.getLong(key)); } else if (value instanceof BasicDBObject) { BasicDBObject mongoObj = (BasicDBObject) value; if (mongoObj.get("type").equals("TIME")) { builder.setType(Type.TIME).setDataTime(mongoObj.getLong("time")); } else if (mongoObj.get("type").equals("BYTES")) { builder.setType(Type.BYTES).setDataBytes(Reference.newBuilder().setKey(mongoObj.getLong("key")) .setStore(mongoObj.getInt("store")).build()); }/*from w w w . java 2 s .c o m*/ } else if (value instanceof Boolean) { builder.setType(Type.BOOL).setDataBool(objectFound.getBoolean(key)); } else { builder.setType(Type.STRING).setDataString(objectFound.getString(key)); } return builder; }
From source file:pl.nask.hsn2.os.ObjectStore.java
License:Open Source License
public ObjectStoreResponse getObject(ObjectRequest objectRequest) { Iterable<Long> ids = objectRequest.getObjectsList(); ArrayList<BasicDBObject> result = mongoConnector.getObjById(objectRequest.getJob(), ids); ObjectStoreResponse response = new ObjectStoreResponse(ResponseType.SUCCESS_GET); ObjectData od;/* w w w . jav a 2 s . co m*/ ArrayList<Long> helpList = new ArrayList<Long>(); for (Long id : ids) helpList.add(id); List<Attribute> attrs; for (BasicDBObject objectFound : result) { attrs = new ArrayList<Attribute>(); for (String key : objectFound.keySet()) { attrs.add(this.getBuilder(key, objectFound).build()); } od = ObjectData.newBuilder().setId(Long.parseLong(objectFound.get("_id").toString())).addAllAttrs(attrs) .build(); response.addData(od); helpList.remove(objectFound.get("_id")); } for (Long id : helpList) { response.addMissing(id); response.setType(ResponseType.PARTIAL_GET); } return response; }
From source file:project.ac.mongoservice.MongoDB.java
/** * * @param className/*from ww w.j a va 2 s . c o m*/ * @param data * @return */ //<editor-fold defaultstate="collapsed" desc="private Metodo :: create(String, String)"> private static BasicDBObject create(String className, String data) { BasicDBObject o = null; try { Class clase = Class.forName(className); if (clase != null) { o = (BasicDBObject) clase.newInstance(); if (o != null) { BasicDBObject obj = (BasicDBObject) JSON.parse(data); Set<String> keys = obj.keySet(); for (String key : keys) { Object val = obj.get(key); ((BasicDBObject) o).put(key, val); } } } } catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) { } return o; }
From source file:project.ac.mongoserviceclient.app.App.java
private static BasicDBObject create(String className, String data) { BasicDBObject o = null;//from ww w . j a v a 2 s . com try { Class clase = Class.forName(className); if (clase != null) { o = (BasicDBObject) clase.newInstance(); if (o != null) { System.out.println(data); BasicDBObject obj = (BasicDBObject) JSON.parse(data); Set<String> keys = obj.keySet(); for (String key : keys) { Object val = obj.get(key); ((BasicDBObject) o).put(key, val); } } } } catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) { System.out.println("error create()"); } return o; }
From source file:pt.tiago.mongodbteste.MongoDB.java
private void queries() { DBCollection coll = db.getCollection("Purchase"); //find the sum group by category DBObject group = new BasicDBObject("$group", new BasicDBObject("_id", "$categoryID").append("total", new BasicDBObject("$sum", "$price"))); DBObject sort = new BasicDBObject("$sort", new BasicDBObject("price", 1)); AggregationOutput output = coll.aggregate(group, sort); for (DBObject result : output.results()) { System.out.println(result); }//ww w.j a v a 2 s. c om System.out.println("////////////////////////////////"); //find the year of date //SELECT DISTINCT(YEAR(DateOfPurchase)) AS ano FROM Purchase // $group : {_id : { year : {$year : "$birth_date"}}, total : {$sum : 1} System.out.println("SELECT DISTINCT(YEAR(DateOfPurchase)) AS ano FROM Purchase"); DBCollection collection2 = db.getCollection("Purchase"); group = new BasicDBObject("$group", new BasicDBObject("_id", new BasicDBObject("year", new BasicDBObject("$year", "$dateOfPurchase"))) .append("total", new BasicDBObject("$sum", 1))); output = collection2.aggregate(group); BasicDBObject basicObj; for (DBObject result : output.results()) { basicObj = (BasicDBObject) result; basicObj = (BasicDBObject) basicObj.get("_id"); System.out.println(basicObj.get("year")); ; } System.out.println("////////////////////////////////"); //find the sum with year and categoryID // SELECT SUM(Price) AS Sumatorio FROM Purchase WHERE CategoryID = ? AND Year(DateOfPurchase) = ? System.out.println( "SELECT SUM(Price) AS Sumatorio FROM Purchase WHERE CategoryID = ? AND Year(DateOfPurchase) = ?"); int year = 2014; Calendar cal = Calendar.getInstance(); cal.set(year, 0, 0); Calendar cal2 = Calendar.getInstance(); cal2.set(year, 11, 31); BasicDBObject match = new BasicDBObject("$match", new BasicDBObject("categoryID", new ObjectId("548089fc46e68338719aa1f8"))); match.put("$match", new BasicDBObject("dateOfPurchase", new BasicDBObject("$gte", cal.getTime()).append("$lt", cal2.getTime()))); group = new BasicDBObject("$group", new BasicDBObject("_id", null).append("total", new BasicDBObject("$sum", "$price"))); output = coll.aggregate(match, group); for (DBObject result : output.results()) { basicObj = (BasicDBObject) result; System.out.println(basicObj.getDouble("total")); } System.out.println("////////////////////////////////"); System.out.println("SELECT SUM(Price) , MONTH(DateOfPurchase)" + " FROM Purchase WHERE PersonID = ? AND CategoryID = ? " + "AND Price <= ? GROUP BY MONTH(DateOfPurchase)"); coll = db.getCollection("Purchase"); BasicDBObject cateObj = new BasicDBObject("categoryID", new ObjectId("548089fc46e68338719aa1f8")); BasicDBObject personObj = new BasicDBObject("personID", new ObjectId("548079fa46e68338719aa1f6")); BasicDBList and = new BasicDBList(); and.add(cateObj); and.add(personObj); DBObject andCriteria = new BasicDBObject("$and", and); DBObject matchCriteria = new BasicDBObject("$match", andCriteria); group = new BasicDBObject("$group", new BasicDBObject("_id", null).append("total", new BasicDBObject("$sum", "$price"))); group.put("$group", new BasicDBObject("_id", new BasicDBObject("month", new BasicDBObject("$month", "$dateOfPurchase"))) .append("total", new BasicDBObject("$sum", "$price"))); output = coll.aggregate(matchCriteria, group); for (DBObject result : output.results()) { basicObj = (BasicDBObject) result; System.out.println(basicObj.toString()); } System.out.println("////////////////////////////////"); System.out.println("SELECT SUM(Price) , PersonID FROM Purchase WHERE " + "YEAR(DateOfPurchase) = ? AND Price <= ? GROUP BY PersonID"); coll = db.getCollection("Purchase"); year = 2014; cal = Calendar.getInstance(); cal.set(year, 0, 0); cal2 = Calendar.getInstance(); cal2.set(year, 11, 31); BasicDBObject priceObj = new BasicDBObject("price", new BasicDBObject("$lte", 2000)); BasicDBObject dateObj = new BasicDBObject("dateOfPurchase", new BasicDBObject("$gte", cal.getTime()).append("$lt", cal2.getTime())); and = new BasicDBList(); and.add(priceObj); and.add(dateObj); andCriteria = new BasicDBObject("$and", and); matchCriteria = new BasicDBObject("$match", andCriteria); group = new BasicDBObject("$group", new BasicDBObject("_id", "$personID").append("total", new BasicDBObject("$sum", "$price"))); output = coll.aggregate(matchCriteria, group); for (DBObject result : output.results()) { basicObj = (BasicDBObject) result; System.out.println(basicObj.toString()); } }
From source file:rapture.sheet.mongodb.MongoCellStore.java
License:Open Source License
public String getCell(String sheetName, int row, int column, int dimension) { DBCollection collection = MongoDBFactory.getDB(instanceName).getCollection(tableName); BasicDBObject query = new BasicDBObject(); query.put(KEY, sheetName);/*from www .j ava2 s. c o m*/ query.put(ROW, row); query.put(COL, column); query.put(DIM, dimension); BasicDBObject obj = (BasicDBObject) collection.findOne(query); if (obj != null) { Object v = obj.get(VALUE); return v.toString(); } return null; }