本文整理了Java中org.mongodb.morphia.Datastore.updateFirst()
方法的一些代码示例,展示了Datastore.updateFirst()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Datastore.updateFirst()
方法的具体详情如下:
包路径:org.mongodb.morphia.Datastore
类名称:Datastore
方法名:updateFirst
[英]updates the first entity found using the entity as a template, if nothing is found insert the update as an entity if "createIfMissing" is true. If the entity is a versioned entity, an UnsupportedOperationException is thrown.
[中]
代码示例来源:origin: stackoverflow.com
public boolean checkIfExistsAndInsertOtherwise(short id){
Datastore datastore = getDatastore();
Query<OrganizationId> updateQuery = datastore.createQuery(OrganizationId.class).field("identificationNumber").equal(id);
//Bogus operation, just set id to itself
UpdateOperations<OrganizationId> ops = datastore.createUpdateOperations(OrganizationId.class).set("identificationNumber", id);
UpdateResults<OrganizationId> result = datastore.updateFirst(updateQuery, ops, true,WriteConcern.SAFE);
return result.getInsertedCount() == 0;
}
代码示例来源:origin: protegeproject/webprotege
public Optional<EntityDiscussionThread> setThreadStatus(@Nonnull ThreadId threadId,
@Nonnull Status status) {
datastore.updateFirst(createQueryForThread(threadId), getUpdateOperations().set(STATUS, status));
return Optional.ofNullable(datastore.get(EntityDiscussionThread.class, threadId));
}
代码示例来源:origin: stackoverflow.com
Datastore ds = ...;
//get/change/save
Settings s = ds.find(Settings.class).get(); //like findOne in the shell/driver
s.showFriendsList = true;
ds.save(s);
//or update
ds.updateFirst(ds.find(Settings.class), ds.creatUpdateOperations(Settings.class).set("showFiendsList", true));
代码示例来源:origin: protegeproject/webprotege
public boolean deleteComment(CommentId commentId) {
Query<EntityDiscussionThread> query = datastore.createQuery(EntityDiscussionThread.class)
.field(COMMENTS_ID).equal(commentId);
UpdateOperations<EntityDiscussionThread> update = getUpdateOperations()
.removeAll(COMMENTS, new BasicDBObject("_id", commentId.getId()));
UpdateResults updateResults = datastore.updateFirst(query, update);
return updateResults.getUpdatedCount() == 1;
}
代码示例来源:origin: protegeproject/webprotege
public void updateComment(ThreadId id, Comment comment) {
Query<EntityDiscussionThread> query = createQueryForThread(id)
.field(COMMENTS_ID).equal(comment.getId());
UpdateOperations<EntityDiscussionThread> update = getUpdateOperations()
.set(MATCHED_COMMENT_PATH, comment);
datastore.updateFirst(query, update);
}
内容来源于网络,如有侵权,请联系作者删除!