List of usage examples for com.mongodb DBObject put
Object put(String key, Object v);
From source file:com.jive.myco.seyren.mongo.MongoStore.java
License:Apache License
@Override public SeyrenResponse<Check> getChecksByState(Set<String> states, Boolean enabled) { List<Check> checks = new ArrayList<Check>(); DBObject query = new BasicDBObject(); query.put("state", NiceDBObject.object("$in", states.toArray())); if (enabled != null) { query.put("enabled", enabled); }//w ww. j a v a 2 s.com DBCursor dbc = getChecksCollection().find(query); while (dbc.hasNext()) { checks.add(mapper.checkFrom(dbc.next())); } dbc.close(); return new SeyrenResponse<Check>().withValues(checks).withTotal(dbc.count()); }
From source file:com.jive.myco.seyren.mongo.MongoStore.java
License:Apache License
@Override public void deleteAlerts(String checkId, DateTime before) { DBObject query = NiceDBObject.object("checkId", checkId); if (before != null) { query.put("timestamp", NiceDBObject.object("$lt", new Date(before.getMillis()))); }//from www . j a v a 2 s. c o m getAlertsCollection().remove(query); }
From source file:com.joyfulmongo.db.javadriver.JFDBCollection.java
License:Apache License
public void delete(JSONObject obj) { String objectId = (String) obj.get(Constants.Props.objectId.toString()); if (objectId == null || objectId.length() == 0) { throw new IllegalArgumentException("ObjectId can not be null or empty."); } else {//from w w w . ja va 2 s .c o m DBObject queryCondition = new BasicDBObject(); queryCondition.put(Constants.Props.objectId.toString(), objectId); WriteResult result = dbCollection.remove(queryCondition, WriteConcern.SAFE); recordWriteResult("delete", result); } }
From source file:com.joyfulmongo.db.javadriver.JFDBCollection.java
License:Apache License
private void ensure2DIndexIfExist(JSONObject payload) { Object geoPoint = payload.opt(ContainerObjectGeoPoint.S_GEO_POINT); if (geoPoint != null) { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("create EnsureIndex " + ContainerObjectGeoPoint.S_GEO_POINT); }//w ww . jav a2s . c o m DBObject indexObj = new BasicDBObject(); indexObj.put(ContainerObjectGeoPoint.S_GEO_POINT, "2d"); dbCollection.ensureIndex(indexObj); } }
From source file:com.kurento.kmf.repository.internal.repoimpl.mongo.MongoRepositoryItem.java
License:Open Source License
@Override public OutputStream createOutputStreamToWrite() { checkState(State.NEW);//from w ww .ja va2s. c om storingOutputStream = new FilterOutputStream(((GridFSInputFile) dbFile).getOutputStream()) { @Override public void close() throws IOException { putMetadataInGridFS(); super.close(); refreshAttributesOnClose(); } // TODO Optimise this to use the GridFS metadata private void putMetadataInGridFS() { DBObject metadataDBO = new BasicDBObject(); for (Entry<String, String> entry : metadata.entrySet()) { metadataDBO.put(entry.getKey(), entry.getValue()); } dbFile.setMetaData(metadataDBO); } }; return storingOutputStream; }
From source file:com.kurniakue.trxreader.data.TransactionD.java
public void fixAmount(String dateStr) { DBCursor cursor;//from ww w. j a va2 s.co m if (dateStr == null || "".equals(dateStr)) { cursor = transactions.find(); } else { cursor = transactions.find(new BasicDBObject(F.Date.name(), dateStr)); } while (cursor.hasNext()) { DBObject query = cursor.next(); DBObject update = new BasicDBObject(); update.putAll(query); update.put(F.Amount.name(), Tool.tint(query.get(F.Price.name())) * Tool.tint(query.get(F.Count.name()))); transactions.update(query, update); } }
From source file:com.kurniakue.trxreader.data.TransactionD.java
public void addCreditFlag(String dateStr) { DBCursor cursor;// w w w. j a va 2 s. c o m if (dateStr == null || "".equals(dateStr)) { cursor = transactions.find(); } else { cursor = transactions.find(new BasicDBObject(F.Date.name(), dateStr)); } while (cursor.hasNext()) { DBObject query = cursor.next(); DBObject update = new BasicDBObject(); update.putAll(query); int dcflag = -1; if (CASH.equals(update.get(F.ItemNo.name()))) { dcflag = 1; } update.put(F.DCFlag.name(), dcflag); transactions.update(query, update); } }
From source file:com.kurniakue.trxreader.data.TransactionD.java
public void fixRkapField(String dateStr) { DBCursor cursor;/*from ww w .j av a 2 s. co m*/ if (dateStr == null || "".equals(dateStr)) { cursor = transactions.find(); } else { cursor = transactions.find(new BasicDBObject(F.Date.name(), dateStr)); } while (cursor.hasNext()) { DBObject query = cursor.next(); DBObject update = new BasicDBObject(); update.putAll(query); Record record = Record.r(update); if (!RKAP.equals(record.get(F.ItemNo))) { continue; } if (!record.getString(F.ItemName).startsWith("Saldo")) { continue; } if (record.getInt(F.Amount) < 0) { update.put(F.Amount.name(), record.getInt(F.Amount) * -1); } if (record.getInt(F.DCFlag) < 0) { update.put(F.DCFlag.name(), record.getInt(F.DCFlag) * -1); } // uncomment to actually update DB // and comment it back to prevent accidental update DB // transactions.update(query, update); } }
From source file:com.liferay.mongodb.hook.service.impl.MongoExpandoValueLocalServiceImpl.java
License:Open Source License
@Override public ExpandoValue addValue(long classNameId, long tableId, long columnId, long classPK, String data) throws PortalException { ExpandoTable expandoTable = ExpandoTableLocalServiceUtil.getTable(tableId); ExpandoColumn expandoColumn = ExpandoColumnLocalServiceUtil.getColumn(columnId); ExpandoValue expandoValue = ExpandoValueUtil.create(0); expandoValue.setCompanyId(expandoTable.getCompanyId()); expandoValue.setTableId(tableId);/*from www .j a va 2 s . co m*/ expandoValue.setColumnId(columnId); expandoValue.setRowId(classPK); expandoValue.setClassNameId(classNameId); expandoValue.setClassPK(classPK); expandoValue.setData(data); DBCollection dbCollection = MongoDBUtil.getCollection(expandoTable); DBObject queryDBObject = new BasicDBObject(); queryDBObject.put("companyId", expandoTable.getCompanyId()); queryDBObject.put("tableId", tableId); queryDBObject.put("rowId", classPK); queryDBObject.put("classNameId", classNameId); queryDBObject.put("classPK", classPK); BasicDBObject expandoValueDBObject = (BasicDBObject) dbCollection.findOne(queryDBObject); if (expandoValueDBObject != null) { expandoValue.setValueId(expandoValueDBObject.getLong("valueId")); DBObject operatorDBObject = new BasicDBObject(); DBObject updateExpandoValueDBObject = new BasicDBObject(expandoColumn.getName(), getData(expandoColumn, expandoValue)); operatorDBObject.put(MongoOperator.SET, updateExpandoValueDBObject); dbCollection.update(expandoValueDBObject, operatorDBObject); } else { long valueId = CounterLocalServiceUtil.increment(); expandoValue.setValueId(valueId); queryDBObject.put("valueId", valueId); queryDBObject.put(expandoColumn.getName(), getData(expandoColumn, expandoValue)); dbCollection.insert(queryDBObject); } return expandoValue; }
From source file:com.liferay.mongodb.hook.service.impl.MongoExpandoValueLocalServiceImpl.java
License:Open Source License
@Override public void addValues(long classNameId, long tableId, List<ExpandoColumn> expandoColumns, long classPK, Map<String, String> data) throws PortalException { ExpandoTable expandoTable = ExpandoTableLocalServiceUtil.getTable(tableId); ExpandoValue expandoValue = ExpandoValueUtil.create(0); expandoValue.setCompanyId(expandoTable.getCompanyId()); expandoValue.setTableId(tableId);/*from www . jav a 2 s. co m*/ expandoValue.setRowId(classPK); expandoValue.setClassNameId(classNameId); expandoValue.setClassPK(classPK); DBCollection dbCollection = MongoDBUtil.getCollection(expandoTable); DBObject queryDBObject = new BasicDBObject(); queryDBObject.put("companyId", expandoTable.getCompanyId()); queryDBObject.put("tableId", tableId); queryDBObject.put("rowId", classPK); queryDBObject.put("classNameId", classNameId); queryDBObject.put("classPK", classPK); BasicDBObject expandoValueDBObject = (BasicDBObject) dbCollection.findOne(queryDBObject); if (expandoValueDBObject != null) { expandoValue.setValueId(expandoValueDBObject.getLong("valueId")); DBObject operatorDBObject = new BasicDBObject(); DBObject updateExpandoValueDBObject = new BasicDBObject(); updateExpandoValueDBObject(updateExpandoValueDBObject, expandoColumns, data, expandoValue); operatorDBObject.put(MongoOperator.SET, updateExpandoValueDBObject); dbCollection.update(expandoValueDBObject, operatorDBObject); } else { long valueId = CounterLocalServiceUtil.increment(); expandoValue.setValueId(valueId); queryDBObject.put("valueId", valueId); updateExpandoValueDBObject(queryDBObject, expandoColumns, data, expandoValue); dbCollection.insert(queryDBObject); } }