本文整理汇总了Java中com.mongodb.client.model.FindOneAndUpdateOptions类的典型用法代码示例。如果您正苦于以下问题:Java FindOneAndUpdateOptions类的具体用法?Java FindOneAndUpdateOptions怎么用?Java FindOneAndUpdateOptions使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FindOneAndUpdateOptions类属于com.mongodb.client.model包,在下文中一共展示了FindOneAndUpdateOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPendingDataLoader
import com.mongodb.client.model.FindOneAndUpdateOptions; //导入依赖的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;
}
示例2: resetRequest
import com.mongodb.client.model.FindOneAndUpdateOptions; //导入依赖的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();
}
示例3: doModify
import com.mongodb.client.model.FindOneAndUpdateOptions; //导入依赖的package包/类
protected final FluentFuture<Optional<T>> doModify(
final Constraints.ConstraintHost criteria,
final Constraints.Constraint update,
final FindOneAndUpdateOptions options) {
checkNotNull(criteria, "criteria");
checkNotNull(update, "update");
return submit(new Callable<Optional<T>>() {
@Override
public Optional<T> call() throws Exception {
@Nullable T result = collection().findOneAndUpdate(
convertToBson(criteria),
convertToBson(update),
options);
return Optional.fromNullable(result);
}
});
}
示例4: doUpdateFirst
import com.mongodb.client.model.FindOneAndUpdateOptions; //导入依赖的package包/类
protected final FluentFuture<Integer> doUpdateFirst(
final Constraints.ConstraintHost criteria,
final Constraints.Constraint update,
final FindOneAndUpdateOptions options
) {
checkNotNull(criteria, "criteria");
checkNotNull(update, "update");
checkNotNull(options, "options");
return submit(new Callable<Integer>() {
@Override
public Integer call() {
T result = collection().findOneAndUpdate(
convertToBson(criteria),
convertToBson(update),
options);
return result == null ? 0 : 1;
}
});
}
示例5: peek
import com.mongodb.client.model.FindOneAndUpdateOptions; //导入依赖的package包/类
@Override
public Optional<T> peek() {
final Bson peekQuery = QueryUtil.generatePeekQuery(defaultHeartbeatExpirationMillis);
final Document update = new Document();
update.put("heartbeat", new Date());
update.put("status", OkraStatus.PROCESSING.name());
final FindOneAndUpdateOptions options = new FindOneAndUpdateOptions();
options.returnDocument(ReturnDocument.AFTER);
final Document document = client
.getDatabase(getDatabase())
.getCollection(getCollection())
.findOneAndUpdate(peekQuery, new Document("$set", update), options);
if (document == null) {
return Optional.empty();
}
return Optional.ofNullable(serializer.fromDocument(scheduleItemClass, document));
}
示例6: updatePojoTest
import com.mongodb.client.model.FindOneAndUpdateOptions; //导入依赖的package包/类
@Test
public void updatePojoTest() {
Bson update = combine(set("user", "Jim"),
set("action", Action.DELETE),
// unfortunately at this point we need to provide a non generic class, so the codec is able to determine all types
// remember: type erasure makes it impossible to retrieve type argument values at runtime
// @todo provide a mechanism to generate non-generic class on the fly. Is that even possible ?
// set("listOfPolymorphicTypes", buildNonGenericClassOnTheFly(Arrays.asList(new A(123), new B(456f)), List.class, Type.class),
set("listOfPolymorphicTypes", new PolymorphicTypeList(Arrays.asList(new A(123), new B(456f)))),
currentDate("creationDate"),
currentTimestamp("_id"));
FindOneAndUpdateOptions findOptions = new FindOneAndUpdateOptions();
findOptions.upsert(true);
findOptions.returnDocument(ReturnDocument.AFTER);
MongoCollection<Pojo> pojoMongoCollection = mongoClient.getDatabase("test").getCollection("documents").withDocumentClass(Pojo.class);
Pojo pojo = pojoMongoCollection.findOneAndUpdate(Filters.and(Filters.lt(DBCollection.ID_FIELD_NAME, 0),
Filters.gt(DBCollection.ID_FIELD_NAME, 0)), update, findOptions);
assertNotNull(pojo.id);
}
示例7: findOneAndUpdate
import com.mongodb.client.model.FindOneAndUpdateOptions; //导入依赖的package包/类
@Override
public TDocument findOneAndUpdate(Bson filter, Bson arg1, FindOneAndUpdateOptions arg2)
{
OperationMetric metric = null;
if (MongoLogger.GATHERER.isEnabled())
{
List<String> keyValuePairs = MongoUtilities.getKeyValuePairs(filter);
keyValuePairs.add("update");
keyValuePairs.add(CacheUtilities.safeToString(arg1));
String operationName = "Mongo : " + getNamespace().getCollectionName() + " : findOneAndUpdate " +
MongoUtilities.filterParameters(filter).toString();
metric = startMetric(operationName, keyValuePairs);
if (MongoLogger.isRequestSizeMeasured())
{
metric.setProperty(CommonMetricProperties.REQUEST_SIZE_BYTES, Integer.toString(measureDocumentSize(arg1)));
}
addWriteConcern(metric);
addReadConcernAndPreference(metric);
}
TDocument retVal = collection.findOneAndUpdate(filter, arg1, arg2);
stopMetric(metric, measureDocumentSizeIfResultSizeEnabled(retVal));
return retVal;
}
示例8: getNextIdGen
import com.mongodb.client.model.FindOneAndUpdateOptions; //导入依赖的package包/类
@Override
public Long getNextIdGen(Long interval) {
Document realUpdate = getIncUpdateObject(getUpdateObject(interval));
FindOneAndUpdateOptions options = new FindOneAndUpdateOptions()
.upsert(true)
.returnDocument(ReturnDocument.AFTER);
Document ret = getIdGenCollection().findOneAndUpdate(getQueryObject(), realUpdate, options);
if (ret == null) return null;
Boolean valid = (Boolean) ret.get(VALID);
if (valid != null && !valid) {
throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_BAD_REQUEST,
mongoMsgCatalog.getMessage("IdGenerator"));
}
return (Long) ret.get(SEQ);
}
示例9: updateRow
import com.mongodb.client.model.FindOneAndUpdateOptions; //导入依赖的package包/类
@Override
public void updateRow(String rowId, Map<String, Object> recordValues) {
String key = getKey(rowId); // stupid key is row id plus "l/" prepended
// to it
MongoCollection<Document> collection = MongoDBFactory.getCollection(instanceName, tableName);
Document query = new Document();
query.put(KEY, key);
Document toPut = new Document();
toPut.put(KEY, key);
toPut.put(ROWID, rowId);
toPut.put(EPOCH, EpochManager.nextEpoch(collection));
toPut.putAll(recordValues);
FindOneAndUpdateOptions options = new FindOneAndUpdateOptions().upsert(true).returnDocument(ReturnDocument.AFTER);
@SuppressWarnings("unused")
Document ret = collection.findOneAndUpdate(query, new Document($SET, toPut), options);
}
示例10: insertRecord
import com.mongodb.client.model.FindOneAndUpdateOptions; //导入依赖的package包/类
@Override
public boolean insertRecord(LockConfiguration lockConfiguration) {
Bson update = combine(
setOnInsert(LOCK_UNTIL, Date.from(lockConfiguration.getLockAtMostUntil())),
setOnInsert(LOCKED_AT, now()),
setOnInsert(LOCKED_BY, hostname)
);
try {
Document result = getCollection().findOneAndUpdate(
eq(ID, lockConfiguration.getName()),
update,
new FindOneAndUpdateOptions().upsert(true)
);
return result == null;
} catch (MongoCommandException e) {
if (e.getErrorCode() == 11000) { // duplicate key
// this should not normally happen, but it happened once in tests
return false;
} else {
throw e;
}
}
}
示例11: saveAll
import com.mongodb.client.model.FindOneAndUpdateOptions; //导入依赖的package包/类
/**
* Saves a set of {@link ProtectedRegion} for the specified world to database.
*
* @param world The name of the world
* @param set The {@link Set} of regions
* @throws StorageException Thrown if something goes wrong during database query
*/
public void saveAll(final String world, Set<ProtectedRegion> set) throws StorageException {
MongoCollection<ProcessingProtectedRegion> collection = getCollection();
final AtomicReference<Throwable> lastError = new AtomicReference<>();
final CountDownLatch waiter = new CountDownLatch(set.size());
for (final ProtectedRegion region : set) {
if (listener != null)
listener.beforeDatabaseUpdate(world, region);
collection.findOneAndUpdate(
Filters.and(Filters.eq("name", region.getId()), Filters.eq("world", world)),
new Document("$set", new ProcessingProtectedRegion(region, world)),
new FindOneAndUpdateOptions().upsert(true).returnDocument(ReturnDocument.AFTER),
OperationResultCallback.create(lastError, waiter, new UpdateCallback(world))
);
}
ConcurrentUtils.safeAwait(waiter);
Throwable realLastError = lastError.get();
if (realLastError != null)
throw new StorageException("An error occurred while saving or updating in MongoDB.", realLastError);
}
示例12: findOneAndUpdateWithOptions
import com.mongodb.client.model.FindOneAndUpdateOptions; //导入依赖的package包/类
@Override
public io.vertx.ext.mongo.MongoClient findOneAndUpdateWithOptions(String collection, JsonObject query, JsonObject update, FindOptions findOptions, UpdateOptions updateOptions, Handler<AsyncResult<JsonObject>> resultHandler) {
requireNonNull(collection, "collection cannot be null");
requireNonNull(query, "query cannot be null");
requireNonNull(update, "update cannot be null");
requireNonNull(findOptions, "find options cannot be null");
requireNonNull(updateOptions, "update options cannot be null");
requireNonNull(resultHandler, "resultHandler cannot be null");
JsonObject encodedQuery = encodeKeyWhenUseObjectId(query);
Bson bquery = wrap(encodedQuery);
Bson bupdate = wrap(update);
FindOneAndUpdateOptions foauOptions = new FindOneAndUpdateOptions();
foauOptions.sort(wrap(findOptions.getSort()));
foauOptions.projection(wrap(findOptions.getFields()));
foauOptions.upsert(updateOptions.isUpsert());
foauOptions.returnDocument(updateOptions.isReturningNewDocument() ? ReturnDocument.AFTER : ReturnDocument.BEFORE);
MongoCollection<JsonObject> coll = getCollection(collection);
coll.findOneAndUpdate(bquery, bupdate, foauOptions, wrapCallback(resultHandler));
return this;
}
示例13: reschedule
import com.mongodb.client.model.FindOneAndUpdateOptions; //导入依赖的package包/类
@Override
public Optional<T> reschedule(final T item) {
validateReschedule(item);
final Document query = new Document();
query.put("_id", new ObjectId(item.getId()));
query.put("heartbeat", DateUtil.toDate(item.getHeartbeat()));
final Document setDoc = new Document();
setDoc.put("heartbeat", null);
setDoc.put("runDate", DateUtil.toDate(item.getRunDate()));
setDoc.put("status", OkraStatus.PENDING.name());
final Document update = new Document();
update.put("$set", setDoc);
final FindOneAndUpdateOptions options = new FindOneAndUpdateOptions();
options.returnDocument(ReturnDocument.AFTER);
final Document document = client
.getDatabase(getDatabase())
.getCollection(getCollection())
.findOneAndUpdate(query, update, options);
if (document == null) {
return Optional.empty();
}
return Optional.ofNullable(serializer.fromDocument(scheduleItemClass, document));
}
示例14: heartbeatAndUpdateCustomAttrs
import com.mongodb.client.model.FindOneAndUpdateOptions; //导入依赖的package包/类
@Override
public Optional<T> heartbeatAndUpdateCustomAttrs(final T item, final Map<String, Object> attrs) {
validateHeartbeat(item);
final Document query = new Document();
query.put("_id", new ObjectId(item.getId()));
query.put("status", OkraStatus.PROCESSING.name());
query.put("heartbeat", DateUtil.toDate(item.getHeartbeat()));
final Document update = new Document();
update.put("$set", new Document("heartbeat", new Date()));
if (attrs != null && !attrs.isEmpty()) {
attrs.forEach((key, value) -> update.append("$set", new Document(key, value)));
}
final FindOneAndUpdateOptions options = new FindOneAndUpdateOptions();
options.returnDocument(ReturnDocument.AFTER);
final Document result = client
.getDatabase(getDatabase())
.getCollection(getCollection())
.findOneAndUpdate(query, update, options);
if (result == null) {
return Optional.empty();
}
return Optional.ofNullable(serializer.fromDocument(scheduleItemClass, result));
}
示例15: getPendingEvent
import com.mongodb.client.model.FindOneAndUpdateOptions; //导入依赖的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));
}