List of usage examples for com.mongodb DBObject keySet
Set<String> keySet();
From source file:org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoDaoUtil.java
License:Apache License
/** * Specific method for recursive substitute the reserved $ and . characters * in the key names of the DBObject./*from w w w . j a v a 2 s. c om*/ * * @param profileBody the profileBody * @return encoded DBObject */ public static DBObject encodeReservedCharacteres(DBObject profileBody) { if (profileBody == null) { return null; } if (profileBody instanceof BasicDBList) { BasicDBList dbList = (BasicDBList) profileBody; BasicDBList modifiedList = new BasicDBList(); for (Object value : dbList) { if (value instanceof DBObject) { modifiedList.add(encodeReservedCharacteres((DBObject) value)); } else { modifiedList.add(value); } } return modifiedList; } else { Set<String> keySet = profileBody.keySet(); DBObject modifiedNode = new BasicDBObject(); if (keySet != null) { for (String key : keySet) { Object value = profileBody.get(key); for (char symbolToReplace : RESERVED_CHARACTERS.keySet()) { key = key.replace(symbolToReplace, RESERVED_CHARACTERS.get(symbolToReplace)); } if (value instanceof DBObject) { modifiedNode.put(key, encodeReservedCharacteres((DBObject) value)); } else { modifiedNode.put(key, value); } } } return modifiedNode; } }
From source file:org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoDaoUtil.java
License:Apache License
/** * Specific method for recursive decoding the reserved $ and . characters in the key names of the * DBObject.// w ww .jav a 2 s . co m * * @param profileBody the profileBody * @return decoded DBObject */ public static DBObject decodeReservedCharacteres(DBObject profileBody) { if (profileBody == null) { return null; } if (profileBody instanceof BasicDBList) { BasicDBList dbList = (BasicDBList) profileBody; BasicDBList modifiedList = new BasicDBList(); for (Object value : dbList) { if (value instanceof DBObject) { modifiedList.add(decodeReservedCharacteres((DBObject) value)); } else { modifiedList.add(value); } } return modifiedList; } else { Set<String> keySet = profileBody.keySet(); DBObject modifiedNode = new BasicDBObject(); if (keySet != null) { for (String key : keySet) { Object value = profileBody.get(key); for (char symbolToReplace : RESERVED_CHARACTERS.values()) { key = key.replace(symbolToReplace, RESERVED_CHARACTERS.inverse().get(symbolToReplace)); } if (value instanceof DBObject) { modifiedNode.put(key, decodeReservedCharacteres((DBObject) value)); } else { modifiedNode.put(key, value); } } } return modifiedNode; } }
From source file:org.mongolink.domain.updateStrategy.DiffStrategy.java
License:Open Source License
@Override public void update(DBObject initialValue, DBObject updatedValue, DBCollection collection) { final DBObject diff = new DbObjectDiff(initialValue).compareWith(updatedValue); final DBObject q = updateQuery(initialValue); executePushAndPull(collection, diff, q); if (!diff.keySet().isEmpty()) { LOGGER.debug("Updating : collection {} : query {} : modifiers : {}", collection.getName(), q, diff); collection.update(q, diff);/*ww w.jav a2 s. c o m*/ } }
From source file:org.mongolink.domain.updateStrategy.DocumentVisitor.java
License:Open Source License
@Override public void visit(final Object target) { final DBObject dbObject = (DBObject) target; for (String key : dbObject.keySet()) { getDbObjectDiff().pushKey(key);// ww w . j a va 2 s .co m visit(key, (DBObject) target); getDbObjectDiff().popKey(); } }
From source file:org.mule.module.mongo.api.DBObjects.java
License:Open Source License
private static void adaptAttributes(DBObject o) { for (String key : o.keySet()) { o.put(key, adapt(o.get(key)));/* w ww . j a va 2 s . c om*/ } }
From source file:org.netbeans.modules.mongodb.ui.windows.collectionview.flattable.DocumentsFlatTableModel.java
License:Open Source License
private void updateColumns(DBObject document) { for (String field : document.keySet()) { if (columns.contains(field) == false) { columns.add(field);/* w w w . j av a2 s. co m*/ } } }
From source file:org.nuxeo.ecm.core.storage.mongodb.MongoDBConverter.java
License:Apache License
public State bsonToState(DBObject ob) { if (ob == null) { return null; }//from www.j a v a 2 s. c o m State state = new State(ob.keySet().size()); for (String key : ob.keySet()) { if (useCustomId && MONGODB_ID.equals(key)) { // skip native id continue; } state.put(bsonToKey(key), bsonToValue(ob.get(key))); } return state; }
From source file:org.nuxeo.ecm.core.storage.mongodb.MongoDBQueryBuilder.java
License:Apache License
protected Object pushDownNot(Object object) { if (!(object instanceof DBObject)) { throw new QueryParseException("Cannot do NOT on: " + object); }/*from www .j av a2 s .c o m*/ DBObject ob = (DBObject) object; Set<String> keySet = ob.keySet(); if (keySet.size() != 1) { throw new QueryParseException("Cannot do NOT on: " + ob); } String key = keySet.iterator().next(); Object value = ob.get(key); if (!key.startsWith("$")) { if (value instanceof DBObject) { // push down inside dbobject return new BasicDBObject(key, pushDownNot(value)); } else { // k = v -> k != v return new BasicDBObject(key, new BasicDBObject(QueryOperators.NE, value)); } } if (QueryOperators.NE.equals(key)) { // NOT k != v -> k = v return value; } if (QueryOperators.NOT.equals(key)) { // NOT NOT v -> v return value; } if (QueryOperators.AND.equals(key) || QueryOperators.OR.equals(key)) { // boolean algebra // NOT (v1 AND v2) -> NOT v1 OR NOT v2 // NOT (v1 OR v2) -> NOT v1 AND NOT v2 String op = QueryOperators.AND.equals(key) ? QueryOperators.OR : QueryOperators.AND; List<Object> list = (List<Object>) value; for (int i = 0; i < list.size(); i++) { list.set(i, pushDownNot(list.get(i))); } return new BasicDBObject(op, list); } if (QueryOperators.IN.equals(key) || QueryOperators.NIN.equals(key)) { // boolean algebra // IN <-> NIN String op = QueryOperators.IN.equals(key) ? QueryOperators.NIN : QueryOperators.IN; return new BasicDBObject(op, value); } if (QueryOperators.LT.equals(key) || QueryOperators.GT.equals(key) || QueryOperators.LTE.equals(key) || QueryOperators.GTE.equals(key)) { // TODO use inverse operators? return new BasicDBObject(QueryOperators.NOT, ob); } throw new QueryParseException("Unknown operator for NOT: " + key); }
From source file:org.nuxeo.ecm.core.storage.mongodb.MongoDBRepository.java
License:Apache License
protected void markReferencedBinaries(DBObject ob, DocumentBlobManager blobManager) { for (String key : ob.keySet()) { Object value = ob.get(key); if (value instanceof List) { @SuppressWarnings("unchecked") List<Object> list = (List<Object>) value; for (Object v : list) { if (v instanceof DBObject) { markReferencedBinaries((DBObject) v, blobManager); } else { markReferencedBinary(v, blobManager); }//from w w w. j a va 2s . com } } else if (value instanceof Object[]) { for (Object v : (Object[]) value) { markReferencedBinary(v, blobManager); } } else if (value instanceof DBObject) { markReferencedBinaries((DBObject) value, blobManager); } else { markReferencedBinary(value, blobManager); } } }
From source file:org.opencb.opencga.catalog.db.mongodb.CatalogMongoDBUtils.java
License:Apache License
static <T> T replaceInKeys(T object, String target, String replacement) { if (object instanceof DBObject) { DBObject dbObject = (DBObject) object; List<String> keys = new ArrayList<>(); for (String s : dbObject.keySet()) { if (s.contains(target)) { keys.add(s);//from ww w . ja va2s . c om } replaceInKeys(dbObject.get(s), target, replacement); } for (String key : keys) { Object value = dbObject.removeField(key); key = key.replace(target, replacement); dbObject.put(key, value); } } else if (object instanceof List) { for (Object o : ((List) object)) { replaceInKeys(o, target, replacement); } } return object; }