Java Code Examples for com.mongodb.DBObject#putAll()
The following examples show how to use
com.mongodb.DBObject#putAll() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PrivateStorageRepository.java From konker-platform with Apache License 2.0 | 6 votes |
public PrivateStorage update(String collectionName, Map<String, Object> content) throws JsonProcessingException { DBObject queryById = new BasicDBObject().append(ID, content.get(ID)); DBCollection collectionFor = mongoPrivateStorageTemplate.getCollection(collectionName); DBObject dbObject = collectionFor.findOne(queryById); if (!Optional.ofNullable(dbObject).isPresent()) { return null; } content.remove("_id"); dbObject.putAll(content); DBObject query = new BasicDBObject().append(ID, dbObject.get(ID)); DBCollection collection = mongoPrivateStorageTemplate.getCollection(collectionName); collection.update(query, dbObject); return PrivateStorage.builder() .collectionName(collectionName) .collectionContent(jsonParsingService.toJsonString(dbObject.toMap())) .build(); }
Example 2
Source File: PluginFactory.java From hvdf with Apache License 2.0 | 6 votes |
public static <T> T loadPlugin(Class<T> pluginType, PluginConfiguration config, Map<String, Object> injectedConfig) { // If the config item is not a document, return nothing String className = config.get(TYPE_KEY, String.class); if(registeredPlugins.containsKey(className)){ className = registeredPlugins.get(className); } // Get the plugin config and inject anything passed DBObject rawPluginConf = config.get(CONFIG_KEY, DBObject.class, new BasicDBObject()); if(injectedConfig != null) rawPluginConf.putAll(injectedConfig); // Get the plugin instance T plugin = createPlugin(pluginType, className, rawPluginConf); return plugin; }
Example 3
Source File: SubDocAccessor.java From secure-data-service with Apache License 2.0 | 6 votes |
private boolean doPush(DBObject parentQuery, List<Entity> subEntities) { DBObject query = new BasicDBObject(parentQuery.toMap()); query.putAll(new Query(Criteria.where(subField + "._id").nin(getSubDocDids(subEntities))).getQueryObject()); if (template.getCollection(collection) .update(query, buildPushObject(subEntities), false, false, WriteConcern.SAFE).getN() == 1) { return true; } else { if (subEntities.size() > 1) { // try each subentity on its own before failing for (Entity entity : subEntities) { doPush(parentQuery, Arrays.asList(entity)); } } return false; } }
Example 4
Source File: ContainerDocumentAccessorTest.java From secure-data-service with Apache License 2.0 | 5 votes |
@Test public void testUpdateContainerFields() { Query query = Mockito.mock(Query.class); DBObject queryObject = Mockito.mock(DBObject.class); Map<String, Object> body = entity.getBody(); Map<String, Object> fields = new HashMap<String, Object>(); for (Map.Entry<String, Object> entry : body.entrySet()) { if(!entry.getKey().equals("attendanceEvent")) { fields.put("body." + entry.getKey(), entry.getValue()); } } final Map<String, Object> attendanceEvent = new HashMap<String, Object>(); final List<Map<String, Object>> attendanceEvents = new ArrayList<Map<String, Object>>(); attendanceEvent.put("event", "Tardy"); attendanceEvents.add(attendanceEvent); DBObject docsToPersist = BasicDBObjectBuilder.start().push("$pushAll").add("body.attendanceEvent", attendanceEvents).get(); DBObject bodyFields = new BasicDBObject("$set", new BasicDBObject(fields)); docsToPersist.putAll(bodyFields); when(query.getQueryObject()).thenReturn(queryObject); when(mongoTemplate.getCollection(ATTENDANCE)).thenReturn(mockCollection); when(mockCollection.update(Mockito.eq(queryObject), Mockito.eq(docsToPersist), Mockito.eq(true), Mockito.eq(false), Mockito.eq(WriteConcern.SAFE))).thenReturn(writeResult); boolean result = testAccessor.updateContainerDoc(query, body, ATTENDANCE, ATTENDANCE); assertTrue(result); Mockito.verify(mockCollection, Mockito.times(1)).update(Mockito.eq(queryObject), Mockito.eq(docsToPersist), Mockito.eq(true), Mockito.eq(false), Mockito.eq(WriteConcern.SAFE)); }
Example 5
Source File: MongoAggWriter.java From secure-data-service with Apache License 2.0 | 5 votes |
@Override public void write(EmittableKey key, BSONWritable value) throws IOException { DBObject k = new BasicDBObject(); k.putAll(key.toBSON()); DBObject v = new BasicDBObject(); v.put("$set", value); output.findAndModify(k, v); }