List of usage examples for com.mongodb BasicDBObject putAll
@SuppressWarnings("unchecked") @Override public void putAll(final Map m)
From source file:fr.gouv.vitam.mdbes.ResultMongodb.java
License:Open Source License
@SuppressWarnings("unchecked") protected boolean updated(final MongoDbAccess dbvitam) { if (getId() == null) { return false; }//from w w w . ja va 2s. c o m final ResultMongodb vt = (ResultMongodb) dbvitam.requests.collection.findOne(getId()); if (vt != null) { final List<DBObject> list = new ArrayList<DBObject>(); final Object obj = vt.obj.get(CURRENTDAIP); final Set<String> vtset = new HashSet<String>(); if (obj instanceof BasicDBList) { for (Object string : (BasicDBList) obj) { vtset.add((String) string); } } else { vtset.addAll((Set<String>) obj); } if (!vtset.isEmpty()) { final Set<String> newset = new HashSet<String>(currentDaip); newset.removeAll(vtset); if (!newset.isEmpty()) { list.add(new BasicDBObject(CURRENTDAIP, new BasicDBObject("$each", newset))); } } if (!list.isEmpty()) { final BasicDBObject updset = new BasicDBObject(); for (final DBObject dbObject : list) { updset.putAll(dbObject); } final BasicDBObject upd = new BasicDBObject(); upd.append(MINLEVEL, minLevel); upd.append(MAXLEVEL, maxLevel); upd.append(NBSUBNODES, nbSubNodes); upd.append(TTL, ttl); final BasicDBObject update = new BasicDBObject("$addToSet", updset).append("$set", upd); dbvitam.requests.collection.update(new BasicDBObject(ID, this.obj.get(ID)), update); } if (GlobalDatas.PRINT_REQUEST) { LOGGER.warn("UPDATE: " + this); } } else if (obj.containsField(ID)) { // not in DB but got already an ID => Save it if (GlobalDatas.PRINT_REQUEST) { LOGGER.warn("SAVE: " + this); } this.forceSave(dbvitam.requests); return true; } return false; }
From source file:fr.gouv.vitam.mdbes.ResultMongodbBak.java
License:Open Source License
@SuppressWarnings("unchecked") @Override/*from w ww .jav a 2 s . c o m*/ protected boolean updated(final MongoDbAccess dbvitam) { final ResultMongodbBak vt = (ResultMongodbBak) dbvitam.requests.collection.findOne(getId()); if (vt != null) { final List<DBObject> list = new ArrayList<DBObject>(); final Object obj = vt.get(CURRENTDAIP); final Set<String> vtset = new HashSet<String>(); if (obj instanceof BasicDBList) { for (Object string : (BasicDBList) obj) { vtset.add((String) string); } } else { vtset.addAll((Set<String>) obj); } if (!vtset.isEmpty()) { final Set<String> newset = new HashSet<String>(currentDaip); newset.removeAll(vtset); if (!newset.isEmpty()) { list.add(new BasicDBObject(CURRENTDAIP, new BasicDBObject("$each", newset))); } } if (!list.isEmpty()) { final BasicDBObject updset = new BasicDBObject(); for (final DBObject dbObject : list) { updset.putAll(dbObject); } final BasicDBObject upd = new BasicDBObject(); upd.append(MINLEVEL, minLevel); upd.append(MAXLEVEL, maxLevel); upd.append(NBSUBNODES, nbSubNodes); upd.append(TTL, ttl); final BasicDBObject update = new BasicDBObject("$addToSet", updset).append("$set", upd); dbvitam.requests.collection.update(new BasicDBObject(ID, this.get(ID)), update); } if (GlobalDatas.PRINT_REQUEST) { LOGGER.warn("UPDATE: " + this); } } else if (containsField(ID)) { // not in DB but got already an ID => Save it if (GlobalDatas.PRINT_REQUEST) { LOGGER.warn("SAVE: " + this); } this.forceSave(dbvitam.requests); return true; } return false; }
From source file:it.wami.map.mongodeploy.OsmToMongoDB.java
License:Apache License
/** * /*from w ww . ja v a 2 s.co m*/ * @return */ private static BasicDBObject getTextIndex() { BasicDBObject text = new BasicDBObject(); DBObject name = new BasicDBObject("tags.name", "text"); DBObject city = new BasicDBObject("tags.addr:city", "text"); DBObject street = new BasicDBObject("tags.addr:street", "text"); DBObject house = new BasicDBObject("tags.addr:housename", "text"); text.putAll(name); text.putAll(city); text.putAll(street); text.putAll(house); return text; }
From source file:mx.org.cedn.avisosconagua.mongo.MongoInterface.java
License:Open Source License
/** * Makes a deep clone of an existing advice object. * @param originAdviceID source object/*w ww .j a va 2 s . c om*/ * @param currentAdviceId ID for the cloned advice object */ public void copyFromAdvice(String originAdviceID, String currentAdviceId) { BasicDBObject origen = getAdvice(originAdviceID); BasicDBObject destino = getAdvice(currentAdviceId); destino.putAll(origen.toMap()); destino.put(INTERNAL_FORM_ID, currentAdviceId); origen = getAdvice(currentAdviceId); mongoDB.getCollection(CAPTURA_COL).update(origen, destino); }
From source file:net.onrc.openvirtex.db.DBManager.java
License:Apache License
/** * Save persistable object obj/*from w ww. j a v a 2s . c o m*/ * @param obj * @param coll */ public void save(Persistable obj) { BasicDBObject query = new BasicDBObject(); query.putAll(obj.getDBIndex()); BasicDBObject update = new BasicDBObject("$addToSet", new BasicDBObject(obj.getDBKey(), obj.getDBObject())); PrintStream ps = System.err; System.setErr(null); try { DBCollection collection = this.collections.get(obj.getDBName()); collection.update(query, update, true, false); } catch (Exception e) { log.error("Failed to update database: {}", e.getMessage()); } finally { System.setErr(ps); } }
From source file:net.onrc.openvirtex.db.DBManager.java
License:Apache License
/** * Remove persistable object obj/*from w w w . ja v a2 s .co m*/ * @param obj * @param coll */ public void remove(Persistable obj) { BasicDBObject query = new BasicDBObject(); query.putAll(obj.getDBIndex()); BasicDBObject update = new BasicDBObject("$pull", new BasicDBObject(obj.getDBKey(), obj.getDBObject())); PrintStream ps = System.err; System.setErr(null); try { DBCollection collection = this.collections.get(obj.getDBName()); collection.update(query, update); } catch (Exception e) { log.error("Failed to remove from db: {}", e.getMessage()); } finally { System.setErr(ps); } }
From source file:net.ymate.platform.persistence.mongodb.AbstractOperator.java
License:Apache License
protected void __doPutOperator(String opt, Map object) { BasicDBObject _dbObj = (BasicDBObject) __operation.get(opt); if (_dbObj == null) { _dbObj = new BasicDBObject(); _dbObj.putAll(object); __doAddOperator(opt, _dbObj);/*from ww w . j a v a 2 s .c o m*/ } else { _dbObj.putAll(object); } }
From source file:net.ymate.platform.persistence.mongodb.expression.ArrayExp.java
License:Apache License
public static ArrayExp elemMatch(IOperator... operators) { ArrayExp _exp = new ArrayExp(); BasicDBObject _dbObj = new BasicDBObject(); for (IOperator _opt : operators) { _dbObj.putAll((BSONObject) _opt.toBson()); }/*www .ja v a 2 s . co m*/ _exp.__doAddOperator(IMongo.OPT.ELEM_MATCH, _dbObj); return _exp; }
From source file:net.ymate.platform.persistence.mongodb.expression.ArrayExp.java
License:Apache License
public static ArrayExp elemMatch(Query... queries) { ArrayExp _exp = new ArrayExp(); BasicDBObject _dbObj = new BasicDBObject(); for (Query _query : queries) { _dbObj.putAll((BSONObject) _query.toBson()); }/*from w ww. jav a2 s.com*/ _exp.__doAddOperator(IMongo.OPT.ELEM_MATCH, _dbObj); return _exp; }
From source file:net.ymate.platform.persistence.mongodb.expression.ProjectionExp.java
License:Apache License
public static ProjectionExp elemMatch(IOperator... operators) { ProjectionExp _exp = new ProjectionExp(); BasicDBObject _dbObj = new BasicDBObject(); for (IOperator _opt : operators) { _dbObj.putAll((BSONObject) _opt.toBson()); }/*from w w w.j a va2s. co m*/ _exp.__doAddOperator(IMongo.OPT.ELEM_MATCH, _dbObj); return _exp; }