本文整理了Java中com.mongodb.client.model.Updates.combine()
方法的一些代码示例,展示了Updates.combine()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Updates.combine()
方法的具体详情如下:
包路径:com.mongodb.client.model.Updates
类名称:Updates
方法名:combine
[英]Combine a list of updates into a single update.
[中]将更新列表合并到单个更新中。
代码示例来源:origin: org.mongodb/mongo-java-driver
/**
* Combine a list of updates into a single update.
*
* @param updates the list of updates
* @return a combined update
*/
public static Bson combine(final Bson... updates) {
return combine(asList(updates));
}
代码示例来源:origin: pippo-java/pippo
@Override
public void save(SessionData sessionData) {
String sessionId = sessionData.getId();
this.sessions.updateOne(
eq(SESSION_ID, sessionId),
combine(
set(SESSION_ID, sessionId),
set(SESSION_TTL, new Date()),
set(SESSION_DATA, transcoder.encode(sessionData))),
new UpdateOptions().upsert(true));
}
代码示例来源:origin: org.mongodb/mongodb-driver-core
/**
* Combine a list of updates into a single update.
*
* @param updates the list of updates
* @return a combined update
*/
public static Bson combine(final Bson... updates) {
return combine(asList(updates));
}
代码示例来源:origin: com.cybermkd/MongodbPlugin
public long update() {
return MongoKit.INSTANCE.update(collectionName, and(query), Updates.combine(data));
}
代码示例来源:origin: T-baby/MongoDB-Plugin
public boolean updateOne() {
return MongoKit.INSTANCE.updateOne(collectionName, and(query), Updates.combine(data)) > 0;
}
代码示例来源:origin: T-baby/MongoDB-Plugin
public long update() {
return MongoKit.INSTANCE.update(collectionName, and(query), Updates.combine(data));
}
代码示例来源:origin: com.cybermkd/MongodbPlugin
public boolean updateOne() {
return MongoKit.INSTANCE.updateOne(collectionName, and(query), Updates.combine(data)) > 0;
}
代码示例来源:origin: opencb/opencga
@Override
public QueryResult updateProjectMetadata(ProjectMetadata projectMetadata, boolean updateCounters) {
Document mongo = new GenericDocumentComplexConverter<>(ProjectMetadata.class).convertToStorageType(projectMetadata);
// Update field by field, instead of replacing the whole object to preserve existing fields like "_lock"
List<Bson> updates = new ArrayList<>(mongo.size());
mongo.forEach((s, o) -> {
// Do not update counters
if (updateCounters || !s.equals(COUNTERS_FIELD)) {
updates.add(new Document("$set", new Document(s, o)));
}
});
return collection.update(QUERY, Updates.combine(updates), new QueryOptions(UPSERT, true));
}
代码示例来源:origin: opencb/opencga
@Override
public QueryResult updateStudyConfiguration(StudyConfiguration studyConfiguration, QueryOptions options) {
Document studyMongo = new DocumentToStudyConfigurationConverter().convertToStorageType(studyConfiguration);
// Update field by field, instead of replacing the whole object to preserve existing fields like "_lock"
Document query = new Document("_id", studyConfiguration.getStudyId());
List<Bson> updates = new ArrayList<>(studyMongo.size());
studyMongo.forEach((s, o) -> updates.add(new Document("$set", new Document(s, o))));
QueryResult<UpdateResult> queryResult = collection.update(query, Updates.combine(updates), new QueryOptions(UPSERT, true));
// studyConfigurationMap.put(studyConfiguration.getStudyId(), studyConfiguration);
return queryResult;
}
代码示例来源:origin: lukas-krecan/ShedLock
@Override
public void unlock() {
// Set lockUtil to now or lockAtLeastUntil whichever is later
getCollection().findOneAndUpdate(
eq(ID, lockConfiguration.getName()),
combine(set(LOCK_UNTIL, Date.from(lockConfiguration.getUnlockTime())))
);
}
}
代码示例来源:origin: opencb/opencga
private void addPrivateVariableMap(long entryId, Map<String, String> variableMap, boolean isVersioned) throws CatalogDBException {
Document queryDocument = new Document(PRIVATE_UID, entryId);
if (isVersioned) {
queryDocument.append(LAST_OF_VERSION, true);
}
List<Bson> setMap = new ArrayList<>(variableMap.size());
for (Map.Entry<String, String> entry : variableMap.entrySet()) {
setMap.add(Updates.set(AnnotationSetParams.PRIVATE_VARIABLE_SET_MAP.key() + "." + entry.getKey(), entry.getValue()));
}
QueryResult<UpdateResult> update = getCollection().update(queryDocument, Updates.combine(setMap), new QueryOptions("multi", true));
if (update.first().getModifiedCount() < 1 && update.first().getMatchedCount() == 0) {
throw new CatalogDBException("Could not add new private map information");
}
}
代码示例来源:origin: protegeproject/webprotege
public static Bson updateModified(UserId userId, long timestamp) {
return Updates.combine(
Updates.set(MODIFIED_AT, TimestampSerializer.toIsoDateTime(timestamp)),
Updates.set(MODIFIED_BY, userId.getUserName())
);
}
代码示例来源:origin: creactiviti/piper
@Override
public void set(String aCounterName, long aValue) {
collection
.findOneAndUpdate(
eq("_id", aCounterName),
combine(
Updates.set(DSL.VALUE, aValue),
setOnInsert("_id", aCounterName),
setOnInsert(DSL.CREATE_TIME, new Date())
),
new FindOneAndUpdateOptions()
.upsert(true)
);
}
代码示例来源:origin: opencb/opencga
@Override
public QueryResult updateCustomAnnotations(Query query, String name, AdditionalAttribute attribute, long timeStamp,
QueryOptions options) {
Document queryDocument = queryParser.parseQuery(query);
Document updateDocument = DocumentToVariantAnnotationConverter.convertToStorageType(attribute);
return variantsCollection.update(queryDocument,
combine(set(DocumentToVariantConverter.CUSTOM_ANNOTATION_FIELD + '.' + name, updateDocument),
getSetIndexNotSynchronized(timeStamp)),
new QueryOptions(MULTI, true));
}
代码示例来源:origin: opencb/opencga
private QueryResult<UpdateResult> removeStudyFromVariants(int studyId, Bson query, long timestamp) {
// { $pull : { files : { sid : <studyId> } } }
Bson update = combine(
pull(DocumentToVariantConverter.STUDIES_FIELD, eq(STUDYID_FIELD, studyId)),
pull(DocumentToVariantConverter.STATS_FIELD, eq(DocumentToVariantStatsConverter.STUDY_ID, studyId)),
getSetIndexNotSynchronized(timestamp)
);
logger.debug("removeStudy: query = {}", query.toBsonDocument(Document.class, MongoClient.getDefaultCodecRegistry()));
logger.debug("removeStudy: update = {}", update.toBsonDocument(Document.class, MongoClient.getDefaultCodecRegistry()));
QueryResult<UpdateResult> result = variantsCollection.update(query, update, new QueryOptions(MULTI, true));
logger.debug("removeStudy: matched = {}", result.first().getMatchedCount());
logger.debug("removeStudy: modified = {}", result.first().getModifiedCount());
return result;
}
代码示例来源:origin: opencb/opencga
private void removeAllAnnotationSets(long entryId, boolean isVersioned) throws CatalogDBException {
Document queryDocument = new Document(PRIVATE_UID, entryId);
if (isVersioned) {
queryDocument.append(LAST_OF_VERSION, true);
}
// We empty the annotation sets list and the private map
Bson bsonUpdate = Updates.combine(
Updates.set(AnnotationSetParams.ANNOTATION_SETS.key(), Collections.emptyList()),
Updates.set(AnnotationSetParams.PRIVATE_VARIABLE_SET_MAP.key(), Collections.emptyMap())
);
QueryResult<UpdateResult> update = getCollection().update(queryDocument, bsonUpdate, new QueryOptions());
if (update.first().getModifiedCount() < 1 && update.first().getMatchedCount() == 0) {
throw new CatalogDBException("Could not remove all annotationSets");
}
}
代码示例来源:origin: otto-de/edison-microservice
@Override
public void appendMessage(final String jobId, final JobMessage jobMessage) {
collectionWithWriteTimeout(mongoProperties.getDefaultWriteTimeout(), TimeUnit.MILLISECONDS).updateOne(eq(ID, jobId), combine(push(JobStructure.MESSAGES.key(), encodeJobMessage(jobMessage)), set(JobStructure.LAST_UPDATED.key(), Date.from(jobMessage.getTimestamp().toInstant()))));
}
代码示例来源:origin: opencb/opencga
public static long cleanStageCollection(MongoDBCollection stageCollection, int studyId, int fileId) {
//Delete those studies that have duplicated variants. Those are not inserted, so they are not new variants.
long modifiedCount = stageCollection.update(
and(exists(studyId + "." + fileId + ".1"), exists(studyId + "." + NEW_STUDY_FIELD, false)),
unset(Integer.toString(studyId)),
new QueryOptions(MongoDBCollection.MULTI, true)).first().getModifiedCount();
modifiedCount += stageCollection.update(
exists(studyId + "." + fileId),
combine(
// unset(studyId + "." + fileId),
set(studyId + "." + fileId, null),
set(studyId + "." + NEW_STUDY_FIELD, false)
), new QueryOptions(MongoDBCollection.MULTI, true)).first().getModifiedCount();
return modifiedCount;
}
代码示例来源:origin: atlanmod/NeoEMF
@Override
public void containerFor(Id id, SingleFeatureBean container) {
checkNotNull(id, "id");
checkNotNull(container, "container");
final String ownerId = idConverter.convert(id);
final ContainerDocument newContainer = ContainerDocument.fromBean(container);
final Bson filter = eq(ModelDocument.F_ID, ownerId);
final Bson update = combine(
set(concat(ModelDocument.F_CONTAINER, ContainerDocument.F_OWNER), newContainer.getOwner()),
set(concat(ModelDocument.F_CONTAINER, ContainerDocument.F_ID), newContainer.getId())
);
documents.updateOne(filter, update, new UpdateOptions().upsert(true));
}
代码示例来源:origin: atlanmod/NeoEMF
@Override
public boolean metaClassFor(Id id, ClassBean metaClass) {
checkNotNull(id, "id");
checkNotNull(metaClass, "metaClass");
final String ownerId = idConverter.convert(id);
final ClassDocument newMetaClass = ClassDocument.fromBean(metaClass);
final Bson filter = eq(ModelDocument.F_ID, ownerId);
final Bson existsFilter = and(filter, exists(ModelDocument.F_METACLASS));
final boolean notExists = documents.countDocuments(existsFilter, new CountOptions().limit(1)) == 0;
if (notExists) {
final Bson update = combine(
setOnInsert(concat(ModelDocument.F_METACLASS, ClassDocument.F_NAME), newMetaClass.getName()),
setOnInsert(concat(ModelDocument.F_METACLASS, ClassDocument.F_URI), newMetaClass.getUri())
);
documents.updateOne(filter, update, new UpdateOptions().upsert(true));
}
return notExists;
}
内容来源于网络,如有侵权,请联系作者删除!