List of usage examples for com.mongodb DBObject keySet
Set<String> keySet();
From source file:de.fhg.igd.mongomvcc.impl.internal.Tree.java
License:Open Source License
/** * Deserializes a database object to a commit * @param o the object//from w w w .j av a2s . c o m * @return the commit */ public static Commit deserializeCommit(DBObject o) { long cid = (Long) o.get(MongoDBConstants.ID); Long timestampL = (Long) o.get(MongoDBConstants.TIMESTAMP); long timestamp = timestampL != null ? timestampL : 0; long parentCID = (Long) o.get(PARENT_CID); long rootCID = (Long) o.get(ROOT_CID); DBObject objs = (DBObject) o.get(OBJECTS); Map<String, IdMap> objects = new HashMap<String, IdMap>(); for (String k : objs.keySet()) { if (!k.equals(MongoDBConstants.ID)) { objects.put(k, resolveCollectionObjects((DBObject) objs.get(k))); } } return new Commit(cid, timestamp, parentCID, rootCID, objects); }
From source file:de.fhg.igd.mongomvcc.impl.internal.Tree.java
License:Open Source License
private static IdMap resolveCollectionObjects(DBObject o) { Set<String> keys = o.keySet(); IdMap r = new IdHashMap(keys.size()); for (String k : keys) { r.put(Long.parseLong(k), (Long) o.get(k)); }/*from w w w . ja v a 2 s . c o m*/ return r; }
From source file:de.otto.mongodb.profiler.op.Explanation.java
License:Apache License
private static Collection<ExplanationIssue> findIssuesInExplanation(final DBObject explanationResult, final QueryProfile profile) { final List<ExplanationIssue> result = new ArrayList<>(1); final String cursor = ((String) explanationResult.get("cursor")); if (cursor != null && !cursor.toLowerCase(Locale.ENGLISH).startsWith("btreecursor ")) { final DBObject query = query(profile); // Does the query simply finds all documents if (query.keySet().isEmpty()) { // If it is a count, it will just ask for the document number without a scan if (profile instanceof CountProfile == false) { result.add(ExplanationIssue.FULL_TABLE_SCAN); }//from ww w . j a v a 2s. c om } // ...or is the index missing else { result.add(ExplanationIssue.MISSING_INDEX); } } final Boolean scanAndOrder = ((Boolean) explanationResult.get("scanAndOrder")); if (scanAndOrder != null && scanAndOrder.booleanValue()) { result.add(ExplanationIssue.RESULTS_ORDERED_AFTER_SCAN); } return Collections.unmodifiableList(result); }
From source file:eu.cassandra.server.mongo.util.JSONValidator.java
License:Apache License
private DBObject removeKeyFromInternalFields(DBObject obj, String key) { String[] keys = obj.keySet().toArray(new String[0]); for (String k : keys) { if (k.equalsIgnoreCase(key) && obj.get(k) instanceof Boolean && !(Boolean) obj.get(k)) { obj.put(k, true);/*from ww w. j ava 2s . c o m*/ } else if (obj.get(k) instanceof BasicDBObject) { DBObject intObj = (DBObject) obj.get(k); removeKeyFromInternalFields(intObj, key); } } return obj; }
From source file:eu.cassandra.server.mongo.util.MongoDBQueries.java
License:Apache License
/** * // w ww .j av a2s. com * @param qKey * @param qValue * @param jsonToUpdate * @param collection * @param successMsg * @param refColl * @param refKeyName * @param intDocKey * @return */ public DBObject updateDocument(String qKey, String qValue, String jsonToUpdate, String collection, String successMsg, String refColl, String refKeyName, String intDocKey, int schemaType) { Vector<String> keysUpdated = new Vector<String>(); try { DBObject dbObject = (DBObject) JSON.parse(jsonToUpdate); if (dbObject.containsField("_id")) { dbObject.removeField("_id"); jsonToUpdate = dbObject.toString(); } new JSONValidator().isValid(jsonToUpdate, schemaType, true); if (intDocKey != null && refKeyName != null && dbObject.containsField(refKeyName)) { ensureThatRefKeysMatch(dbObject, collection, refKeyName, intDocKey, qValue); } else if ((refColl != null || refKeyName != null) && dbObject.get(refKeyName) != null) { ensureThatRefKeyExists(dbObject, refColl, refKeyName, false); } for (String key : dbObject.keySet()) { if (!key.equalsIgnoreCase("id")) { keysUpdated.add(key); BasicDBObject keyToUpdate; if (qKey.equalsIgnoreCase("_id") || qKey.endsWith(".cid")) { keyToUpdate = new BasicDBObject().append(qKey, new ObjectId(qValue)); } else { keyToUpdate = new BasicDBObject().append(qKey, qValue); } String keyName = key; if (intDocKey != null) keyName = intDocKey + "." + key; DBConn.getConn().getCollection(collection).update(keyToUpdate, new BasicDBObject().append("$set", new BasicDBObject(keyName, dbObject.get(key)))); } } } catch (Exception e) { return jSON2Rrn.createJSONError("Update Failed for " + jsonToUpdate, e); } return getEntity(null, collection, qKey, qValue, successMsg, false, keysUpdated.toArray(new String[keysUpdated.size()])); }
From source file:eu.cassandra.server.mongo.util.MongoDBQueries.java
License:Apache License
/** * // www . java 2 s. co m * db.installations.update({"appliances.cid":ObjectId("4ff16606e4b0f2b1e00c4d49")},{ $set : {"appliances.$.description":"ff"} }) * * @param coll * @param refColl * @param cid * @param jsonToUpdate * @param successMsg * @return */ public DBObject updateArrayDocument(String coll, String entityName, String cid, String refColl, String refKeyName, String jsonToUpdate) { Vector<String> keysUpdated = new Vector<String>(); try { DBObject dbObject = (DBObject) JSON.parse(jsonToUpdate); if ((refColl != null || refKeyName != null) && dbObject.get(refKeyName) != null) { ensureThatRefKeyExists(dbObject, refColl, refKeyName, false); } DBObject q = new BasicDBObject(entityName + ".cid", new ObjectId(cid)); for (String key : dbObject.keySet()) { if (!key.equalsIgnoreCase("cid")) { keysUpdated.add(key); DBObject o = new BasicDBObject("$set", new BasicDBObject(entityName + ".$." + key, dbObject.get(key))); DBConn.getConn().getCollection(coll).update(q, o); } } } catch (Exception e) { return jSON2Rrn.createJSONError("Update Failed for " + jsonToUpdate, e); } return getInternalEntity(null, coll, entityName, cid, "Internal document " + coll + "." + entityName + " with cid=" + cid + " was successfullylly updated"); }
From source file:eu.delving.core.util.MessageSourceRepo.java
License:EUPL
public Map<String, Map<String, String>> getMessageFileMaps() { Map<String, Map<String, String>> fileMap = new TreeMap<String, Map<String, String>>(); DBCursor cursor = messages().find(); while (cursor.hasNext()) { DBObject object = cursor.next(); String messsageKey = (String) object.get(KEY); for (String contentKey : object.keySet()) { if (contentKey.startsWith(CONTENT)) { String fileName = String.format("messages%s.properties", contentKey.substring(CONTENT.length())); Map<String, String> map = fileMap.get(fileName); if (map == null) { map = new TreeMap<String, String>(); fileMap.put(fileName, map); }/*from w ww.j a v a 2s . co m*/ map.put(messsageKey, (String) object.get(contentKey)); } } } return fileMap; }
From source file:eu.delving.services.core.impl.DataSetImpl.java
License:EUPL
@Override public Map<String, MetaRepo.Mapping> mappings() { Map<String, MetaRepo.Mapping> mappingMap = new TreeMap<String, MetaRepo.Mapping>(); DBObject mappingsObject = (DBObject) object.get(MAPPINGS); if (mappingsObject != null) { for (String prefix : mappingsObject.keySet()) { mappingMap.put(prefix, implFactory.createMapping(this, (DBObject) mappingsObject.get(prefix))); }/* ww w . ja v a 2 s .co m*/ } return mappingMap; }
From source file:eu.delving.services.core.impl.DataSetImpl.java
License:EUPL
@Override public MetaRepo.Record getRecord(ObjectId id, String prefix, String accessKey) throws MappingNotFoundException, AccessKeyException, MappingException { // if prefix is passed in, mapping can be done DBObject rawRecord = records().findOne(mob(MetaRepo.MONGO_ID, id)); if (rawRecord != null) { MetaRepo.Mapping mapping = getMapping(prefix, accessKey); List<RecordImpl> list = new ArrayList<RecordImpl>(); RecordImpl rec = new RecordImpl(records(), rawRecord, getDetails().getMetadataFormat().getPrefix(), getNamespaces());//from ww w .j av a 2 s. c o m System.out.println("Fingerprint {"); for (Map.Entry<String, Integer> entry : rec.getFingerprint().entrySet()) { System.out.println(" " + entry.getKey() + " => " + entry.getValue()); } System.out.println("}"); list.add(rec); if (mapping != null) { Map<String, String> namespaces = new TreeMap<String, String>(); DBObject namespacesObject = getNamespaces(); for (String nsPrefix : namespacesObject.keySet()) { namespaces.put(nsPrefix, (String) namespacesObject.get(nsPrefix)); } ((MappingInternal) mapping).executeMapping(list, namespaces); } return list.isEmpty() ? null : list.get(0); } return null; }
From source file:eu.delving.services.core.impl.DataSetImpl.java
License:EUPL
@Override public RecordFetch getRecords(String prefix, int count, Date from, ObjectId afterId, Date until, String accessKey) throws MappingNotFoundException, AccessKeyException, MappingException { MetaRepo.Mapping mapping = getMapping(prefix, accessKey); final List<RecordImpl> list = new ArrayList<RecordImpl>(); DBCursor cursor = createCursor(from, afterId, until).limit(count).sort(mob(MetaRepo.MONGO_ID, 1)); while (cursor.hasNext()) { DBObject object = cursor.next(); list.add(new RecordImpl(records(), object, getDetails().getMetadataFormat().getPrefix(), getNamespaces()));/*from www .j av a 2 s .c o m*/ } if (list.isEmpty()) { return null; } else { final ObjectId nextAfterId = list.get(list.size() - 1).getId(); if (mapping != null) { Map<String, String> namespaces = new TreeMap<String, String>(); DBObject namespacesObject = (DBObject) object.get(NAMESPACES); for (String nsPrefix : namespacesObject.keySet()) { namespaces.put(nsPrefix, (String) namespacesObject.get(nsPrefix)); } ((MappingInternal) mapping).executeMapping(list, namespaces); // can remove members when records don't validate } return new RecordFetch() { @Override public List<? extends MetaRepo.Record> getRecords() { return list; } @Override public ObjectId getAfterId() { return nextAfterId; } }; } }