List of usage examples for org.springframework.data.mongodb.core.query Update getUpdateObject
public Document getUpdateObject()
From source file:org.objectrepository.instruction.dao.InstructionMongoDBImpl.java
@Override public void removetasks(InstructionType instruction) { final DBObject query = new BasicDBObject("fileSet", Normalizers.normalize(instruction.getFileSet())); final Update update = new Update().set("workflow", new ArrayList(0)); mongoTemplate.getCollection(stagingfile).updateMulti(query, update.getUpdateObject()); }
From source file:org.slc.sli.ingestion.tenant.TenantMongoDATest.java
@SuppressWarnings("unchecked") @Test//from w ww. j a v a2 s .co m public void testGetAutoLoadFiles() throws UnknownHostException { Map<String, Object> tenantsForPreloading = new HashMap<String, Object>(); tenantsForPreloading.put(lzPath1, Arrays.asList("smallDataSet.xml", "mediumDataSet.xml")); Entity tenant = createTenantEntity(); List<Map<String, Object>> landingZone = (List<Map<String, Object>>) tenant.getBody() .get(TenantMongoDA.LANDING_ZONE); Map<String, Object> preloadDef = new HashMap<String, Object>(); preloadDef.put(TenantMongoDA.PRELOAD_STATUS, "ready"); preloadDef.put(TenantMongoDA.PRELOAD_FILES, Arrays.asList("smallDataSet.xml", "mediumDataSet.xml")); landingZone.get(0).put(TenantMongoDA.PRELOAD_DATA, preloadDef); when(mockRepository.findAll(eq("tenant"), any(NeutralQuery.class))).thenReturn(Arrays.asList(tenant)); when(mockRepository.doUpdate(eq("tenant"), any(NeutralQuery.class), any(Update.class))).thenReturn(true); assertEquals(tenantsForPreloading, tenantDA.getPreloadFiles("ingestion_server_host")); verify(mockRepository).doUpdate(eq("tenant"), any(NeutralQuery.class), argThat(new ArgumentMatcher<Update>() { @Override public boolean matches(Object argument) { Update expectedUpdate = Update.update("body." + TenantMongoDA.LANDING_ZONE + ".$." + TenantMongoDA.PRELOAD_DATA + "." + TenantMongoDA.PRELOAD_STATUS, "started"); return ((Update) argument).getUpdateObject().equals(expectedUpdate.getUpdateObject()); } })); }
From source file:org.springframework.data.mongodb.core.MongoTemplate.java
protected WriteResult doUpdate(final String collectionName, final Query query, final Update update, final Class<?> entityClass, final boolean upsert, final boolean multi) { return execute(collectionName, new CollectionCallback<WriteResult>() { public WriteResult doInCollection(DBCollection collection) throws MongoException, DataAccessException { MongoPersistentEntity<?> entity = entityClass == null ? null : getPersistentEntity(entityClass); DBObject queryObj = query == null ? new BasicDBObject() : mapper.getMappedObject(query.getQueryObject(), entity); DBObject updateObj = update.getUpdateObject(); for (String key : updateObj.keySet()) { updateObj.put(key, mongoConverter.convertToMongoType(updateObj.get(key))); }/*w w w . ja v a2s. c o m*/ if (LOGGER.isDebugEnabled()) { LOGGER.debug("calling update using query: " + queryObj + " and update: " + updateObj + " in collection: " + collectionName); } WriteResult wr; MongoAction mongoAction = new MongoAction(writeConcern, MongoActionOperation.UPDATE, collectionName, entityClass, updateObj, queryObj); WriteConcern writeConcernToUse = prepareWriteConcern(mongoAction); if (writeConcernToUse == null) { wr = collection.update(queryObj, updateObj, upsert, multi); } else { wr = collection.update(queryObj, updateObj, upsert, multi, writeConcernToUse); } handleAnyWriteResultErrors(wr, queryObj, "update with '" + updateObj + "'"); return wr; } }); }
From source file:org.springframework.data.mongodb.core.MongoTemplate.java
protected <T> T doFindAndModify(String collectionName, DBObject query, DBObject fields, DBObject sort, Class<T> entityClass, Update update, FindAndModifyOptions options) { EntityReader<? super T, DBObject> readerToUse = this.mongoConverter; if (options == null) { options = new FindAndModifyOptions(); }/*from w w w .ja v a 2 s . com*/ MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(entityClass); DBObject updateObj = update.getUpdateObject(); for (String key : updateObj.keySet()) { updateObj.put(key, mongoConverter.convertToMongoType(updateObj.get(key))); } DBObject mappedQuery = mapper.getMappedObject(query, entity); if (LOGGER.isDebugEnabled()) { LOGGER.debug("findAndModify using query: " + mappedQuery + " fields: " + fields + " sort: " + sort + " for class: " + entityClass + " and update: " + updateObj + " in collection: " + collectionName); } return executeFindOneInternal(new FindAndModifyCallback(mappedQuery, fields, sort, updateObj, options), new ReadDbObjectCallback<T>(readerToUse, entityClass), collectionName); }