当前位置: 首页>>代码示例>>Java>>正文


Java Updates类代码示例

本文整理汇总了Java中com.mongodb.client.model.Updates的典型用法代码示例。如果您正苦于以下问题:Java Updates类的具体用法?Java Updates怎么用?Java Updates使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Updates类属于com.mongodb.client.model包,在下文中一共展示了Updates类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getPendingDataLoader

import com.mongodb.client.model.Updates; //导入依赖的package包/类
public O2MSyncDataLoader getPendingDataLoader() {
	O2MSyncDataLoader loader = null;
	Document document = syncEventDoc.findOneAndUpdate(
			Filters.and(Filters.eq(SyncAttrs.STATUS, SyncStatus.PENDING),
					Filters.eq(SyncAttrs.EVENT_TYPE, String.valueOf(EventType.System))),
			Updates.set(SyncAttrs.STATUS, SyncStatus.IN_PROGRESS),
			new FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER)
					.projection(Projections.include(SyncAttrs.SOURCE_DB_NAME, SyncAttrs.SOURCE_USER_NAME)));
	if (document != null && !document.isEmpty()) {
		Object interval = document.get(SyncAttrs.INTERVAL);
		String appName = document.getString(SyncAttrs.APPLICATION_NAME);
		if(interval!=null && interval instanceof Long){
			loader = new O2MSyncDataLoader((Long)interval, appName);
		}else{
			loader = new O2MSyncDataLoader(120000, appName);
		}
		loader.setEventId(document.getObjectId(SyncAttrs.ID));
		loader.setDbName(document.getString(SyncAttrs.SOURCE_DB_NAME));
		loader.setDbUserName(document.getString(SyncAttrs.SOURCE_USER_NAME));
		loader.setStatus(document.getString(SyncAttrs.STATUS));
	}
	return loader;
}
 
开发者ID:gagoyal01,项目名称:mongodb-rdbms-sync,代码行数:24,代码来源:SyncEventDao.java

示例2: retryEvent

import com.mongodb.client.model.Updates; //导入依赖的package包/类
public SyncEvent retryEvent(ObjectId eventId, boolean retryFailed, boolean retryEntire, boolean dropCollection) {
	Document updateQuery = new Document();
	updateQuery.append("$set", new Document(SyncAttrs.STATUS, SyncStatus.PENDING).append(SyncAttrs.IS_RETRY, true))
			.append("$unset", new Document(SyncAttrs.ERRORS, true).append(SyncAttrs.MARKER, true));
	if (retryFailed) {
		syncEvents.updateMany(
				Filters.and(Filters.eq(SyncAttrs.PARENT_EVENT_ID, eventId),
						Filters.eq(SyncAttrs.STATUS, SyncStatus.FAILED), Filters.ne(SyncAttrs.ID, eventId)),
				updateQuery);
		syncEvents.updateOne(Filters.eq(SyncAttrs.ID, eventId),
				Updates.set(SyncAttrs.STATUS, SyncStatus.IN_PROGRESS));
	} else {
		if (retryEntire) {
			syncEvents.updateMany(Filters.eq(SyncAttrs.PARENT_EVENT_ID, eventId),
					Updates.set(SyncAttrs.STATUS, SyncStatus.CANCELLED));
			syncEvents.updateOne(Filters.eq(SyncAttrs.ID, eventId), updateQuery);
		}
	}
	return getEvent(eventId);
}
 
开发者ID:gagoyal01,项目名称:mongodb-rdbms-sync,代码行数:21,代码来源:SyncEventDao.java

示例3: resetRequest

import com.mongodb.client.model.Updates; //导入依赖的package包/类
@ExtDirectMethod(ExtDirectMethodType.FORM_POST)
public ExtDirectFormPostResult resetRequest(
		@RequestParam("email") String emailOrLoginName) {

	String token = UUID.randomUUID().toString();

	User user = this.mongoDb.getCollection(User.class).findOneAndUpdate(
			Filters.and(
					Filters.or(Filters.eq(CUser.email, emailOrLoginName),
							Filters.eq(CUser.loginName, emailOrLoginName)),
					Filters.eq(CUser.deleted, false)),
			Updates.combine(
					Updates.set(CUser.passwordResetTokenValidUntil,
							Date.from(ZonedDateTime.now(ZoneOffset.UTC).plusHours(4)
									.toInstant())),
					Updates.set(CUser.passwordResetToken, token)),
			new FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER)
					.upsert(false));

	if (user != null) {
		this.mailService.sendPasswortResetEmail(user);
	}

	return new ExtDirectFormPostResult();
}
 
开发者ID:ralscha,项目名称:eds-starter6-mongodb,代码行数:26,代码来源:SecurityService.java

示例4: update1Person

import com.mongodb.client.model.Updates; //导入依赖的package包/类
/**
 * update a person documents in mongo server
 * <p>
 * using db {@link Params#TEST_MONGO} and collection {@link Params#PERSON}
 * </p>
 *
 * @param mongoIP       the ip of the mongo server
 * @param mongoPort     the port of the mongo server
 * @param mongoHttpPort the port for the rest api of the mongo server
 * @param oldName       the old name of the person to update
 * @param newName       the new name of the person to update
 */
public static void update1Person(String mongoIP, int mongoPort, int mongoHttpPort, int oldName, int newName) {

    MongoClient mongoClient = new MongoClient(mongoIP, mongoPort);
    MongoDatabase database = mongoClient.getDatabase(Params.TEST_MONGO);
    MongoCollection<Document> collection = database.getCollection(Params.PERSON);
    collection.updateOne(Filters.eq(Params.NAME, oldName), Updates
        .set(Params.NAME, newName));
    mongoClient.close();
    // verify
    // http://10.10.10.3:28017/testmongo/person/?filter_name=sadf
    String base_uri = Params.HTTP + mongoIP;

    // content type is not that precise from mongo-http interface
    RestAssured.registerParser(Params.MIME_TYPE_TEXT_PLAIN, Parser.JSON);
    RestAssured.given().log().path().contentType(ContentType.JSON).baseUri(base_uri).port(mongoHttpPort)
        .queryParam(Params.FILTER + Params.UNDERLINE + Params.NAME, newName)
        .get(Params.TEST_MONGO_PERSON_PATH).then().assertThat().statusCode(HttpStatus.SC_OK).
        //contentType(ContentType.JSON).
            body("total_rows", Matchers.equalTo(1));
    RestAssured.unregisterParser("text/plain");
}
 
开发者ID:ericssonITTEcicontrib,项目名称:mongo-connector-test,代码行数:34,代码来源:MongoUtil.java

示例5: getAuthUser

import com.mongodb.client.model.Updates; //导入依赖的package包/类
@ExtDirectMethod
public UserDetailDto getAuthUser(
		@AuthenticationPrincipal MongoUserDetails userDetails) {

	if (userDetails != null) {
		User user = userDetails.getUser(this.mongoDb);
		UserDetailDto userDetailDto = new UserDetailDto(userDetails, user, null);

		if (!userDetails.isPreAuth()) {
			this.mongoDb.getCollection(User.class).updateOne(
					Filters.eq(CUser.id, userDetails.getUserDbId()),
					Updates.set(CUser.lastAccess, new Date()));
		}

		return userDetailDto;
	}

	return null;
}
 
开发者ID:ralscha,项目名称:eds-starter6-mongodb,代码行数:20,代码来源:SecurityService.java

示例6: testUnkownIgnore

import com.mongodb.client.model.Updates; //导入依赖的package包/类
@Test
public void testUnkownIgnore() {
	MongoDatabase db = connect();

	UnknownIgnorePojo pojo = new UnknownIgnorePojo();
	pojo.setName("ralph");

	MongoCollection<UnknownIgnorePojo> coll = db.getCollection(COLL_NAME,
			UnknownIgnorePojo.class);
	coll.insertOne(pojo);

	db.getCollection(COLL_NAME).updateOne(Filters.eq("_id", pojo.getId()),
			Updates.set("newField", "new"));

	UnknownIgnorePojo readPojo = coll.find().first();
	assertThat(readPojo).isEqualToComparingFieldByField(pojo);

	Document doc = db.getCollection(COLL_NAME).find().first();
	assertThat(doc).hasSize(3);
	assertThat(doc.get("_id")).isEqualTo(pojo.getId());
	assertThat(doc.get("name")).isEqualTo("ralph");
	assertThat(doc.get("newField")).isEqualTo("new");
}
 
开发者ID:ralscha,项目名称:bsoncodec-apt,代码行数:24,代码来源:UnknownTest.java

示例7: optionalSet

import com.mongodb.client.model.Updates; //导入依赖的package包/类
public static <TItem> Bson optionalSet(final String fieldName, final TItem value) {
    if (value == null) {
        return null;
    } else {
        return Updates.set(fieldName, value);
    }
}
 
开发者ID:drakeet,项目名称:rebase-server,代码行数:8,代码来源:MongoDBs.java

示例8: getPendingEvent

import com.mongodb.client.model.Updates; //导入依赖的package包/类
public SyncEvent getPendingEvent(List<String> eventTypes) {
	return syncEvents.findOneAndUpdate(
			Filters.and(Filters.eq(SyncAttrs.STATUS, SyncStatus.PENDING),
					Filters.in(SyncAttrs.EVENT_TYPE, eventTypes)),
			Updates.set(SyncAttrs.STATUS, SyncStatus.IN_PROGRESS),
			new FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER));
}
 
开发者ID:gagoyal01,项目名称:mongodb-rdbms-sync,代码行数:8,代码来源:SyncEventDao.java

示例9: getFailedNode

import com.mongodb.client.model.Updates; //导入依赖的package包/类
public SyncNode getFailedNode(long lastPingTime) {
	SyncNode failedNode = syncNodeMapping.findOneAndUpdate(
			Filters.and(Filters.lte(SyncAttrs.LAST_PING_TIME, lastPingTime),
					Filters.eq(SyncAttrs.LIFE_CYCLE, SyncConfig.INSTANCE.getDbProperty(SyncConstants.LIFE))),
			Updates.set(SyncAttrs.LAST_PING_TIME, System.currentTimeMillis()),
			new FindOneAndUpdateOptions().upsert(false).returnDocument(ReturnDocument.BEFORE));
	if (failedNode != null && failedNode.getFailureTime() == 0) {
		syncNodeMapping.findOneAndUpdate(Filters.eq(SyncAttrs.ID, failedNode.getId()),
				Updates.set(SyncAttrs.FAILURE_TIME, failedNode.getLastPingTime()));
	}
	return failedNode;
}
 
开发者ID:gagoyal01,项目名称:mongodb-rdbms-sync,代码行数:13,代码来源:SyncNodeDao.java

示例10: processEventLogFlow

import com.mongodb.client.model.Updates; //导入依赖的package包/类
private void processEventLogFlow() throws InterruptedException {
	FindIterable<O2MSyncEventLog> it = getCursor();
	retryCount = 0;
	it.forEach(new Block<O2MSyncEventLog>() {
		@Override
		public void apply(O2MSyncEventLog eventLog) {
			try {
				if (marker.isFailed()) {
					releaseReources();
					return;
				}
				logCollection.findOneAndUpdate(Filters.eq(SyncAttrs.ID, eventLog.getLogId()),
						Updates.set(O2MSyncEventLogCodec.STATUS, O2MSyncEventLogCodec.RUNNING));
				logger.info("Processing filter : "+eventLog.getEventFilters());
				if (eventLog.getOperation().equals(SyncConstants.DELETE)) {
					processDeletedDoc(eventLog);
				}else{
					processMongoObject(map.getMapObject(), true, null, map.getMapObject().getCollectionName(),
							eventLog);	
				}					
				logCollection.findOneAndUpdate(Filters.eq(SyncAttrs.ID, eventLog.getLogId()),
						Updates.set(O2MSyncEventLogCodec.STATUS, O2MSyncEventLogCodec.COMPLETE));
				logger.info("Processed filter : "+eventLog.getEventFilters());
			} catch (SyncError e) {
				logger.error("Error in O2M replication", e);
				Mailer.sendmail(eventId, null, e, Mailer.FAILURE);
			}
		}
	});
}
 
开发者ID:gagoyal01,项目名称:mongodb-rdbms-sync,代码行数:31,代码来源:OrclToMngSyncReader.java

示例11: putIfAbsent

import com.mongodb.client.model.Updates; //导入依赖的package包/类
@Override
public boolean putIfAbsent(String key, V value) {
  try {
    Bson query = Filters.eq(DrillMongoConstants.ID, key);
    Bson update = Updates.set(pKey, bytes(value));
    UpdateResult updateResult = collection.updateOne(query, update, new UpdateOptions().upsert(true));
    return updateResult.getModifiedCount() == 1;
  } catch (Exception e) {
    logger.error(e.getMessage(), e);
    throw new DrillRuntimeException(e.getMessage(), e);
  }
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:13,代码来源:MongoPersistentStore.java

示例12: update

import com.mongodb.client.model.Updates; //导入依赖的package包/类
@Test
void update() {
    List<TestMongoEntity> entities = testEntities();
    collection.bulkInsert(entities);

    long updatedCount = collection.update(Filters.eq("string_field", entities.get(0).stringField), Updates.set("enum_field", TestMongoEntity.TestEnum.VALUE2));
    assertThat(updatedCount).isEqualTo(1);
    assertThat(collection.get(entities.get(0).id)).get().satisfies(loadedEntity -> assertThat(loadedEntity.enumField).isEqualTo(TestMongoEntity.TestEnum.VALUE2));
}
 
开发者ID:neowu,项目名称:core-ng-project,代码行数:10,代码来源:MongoIntegrationTest.java

示例13: doCleanup

import com.mongodb.client.model.Updates; //导入依赖的package包/类
@Scheduled(cron = "0 0 5 * * *")
public void doCleanup() {
	// Inactivate users that have a lastAccess timestamp that is older than one year
	ZonedDateTime oneYearAgo = ZonedDateTime.now(ZoneOffset.UTC).minusYears(1);
	this.mongoDb.getCollection(User.class).updateMany(
			Filters.lte(CUser.lastAccess, Date.from(oneYearAgo.toInstant())),
			Updates.set(CUser.enabled, false));
}
 
开发者ID:ralscha,项目名称:eds-starter6-mongodb,代码行数:9,代码来源:DisableInactiveUser.java

示例14: enable2f

import com.mongodb.client.model.Updates; //导入依赖的package包/类
@ExtDirectMethod
public String enable2f(@AuthenticationPrincipal MongoUserDetails userDetails) {
	String randomSecret = TotpAuthUtil.randomSecret();

	this.mongoDb.getCollection(User.class).updateOne(
			Filters.eq(CUser.id, userDetails.getUserDbId()),
			Updates.set(CUser.secret, randomSecret));

	return randomSecret;
}
 
开发者ID:ralscha,项目名称:eds-starter6-mongodb,代码行数:11,代码来源:UserConfigService.java

示例15: update

import com.mongodb.client.model.Updates; //导入依赖的package包/类
@ExtDirectMethod(STORE_MODIFY)
public ValidationMessagesResult<User> update(User updatedEntity, Locale locale) {
	List<ValidationMessages> violations = validateEntity(updatedEntity, locale);
	violations.addAll(checkIfLastAdmin(updatedEntity, locale));

	if (violations.isEmpty()) {

		List<Bson> updates = new ArrayList<>();
		updates.add(Updates.set(CUser.loginName, updatedEntity.getLoginName()));
		updates.add(Updates.set(CUser.email, updatedEntity.getEmail()));
		updates.add(Updates.set(CUser.firstName, updatedEntity.getFirstName()));
		updates.add(Updates.set(CUser.lastName, updatedEntity.getLastName()));
		updates.add(Updates.set(CUser.locale, updatedEntity.getLocale()));
		updates.add(Updates.set(CUser.enabled, updatedEntity.isEnabled()));
		if (updatedEntity.getAuthorities() != null
				&& !updatedEntity.getAuthorities().isEmpty()) {
			updates.add(
					Updates.set(CUser.authorities, updatedEntity.getAuthorities()));
		}
		else {
			updates.add(Updates.unset(CUser.authorities));
		}
		updates.add(Updates.setOnInsert(CUser.deleted, false));

		this.mongoDb.getCollection(User.class).updateOne(
				Filters.eq(CUser.id, updatedEntity.getId()), Updates.combine(updates),
				new UpdateOptions().upsert(true));

		if (!updatedEntity.isEnabled()) {
			deletePersistentLogins(updatedEntity.getId());
		}

		return new ValidationMessagesResult<>(updatedEntity);
	}

	ValidationMessagesResult<User> result = new ValidationMessagesResult<>(
			updatedEntity);
	result.setValidations(violations);
	return result;
}
 
开发者ID:ralscha,项目名称:eds-starter6-mongodb,代码行数:41,代码来源:UserService.java


注:本文中的com.mongodb.client.model.Updates类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。