org.mongodb.morphia.Datastore.update()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(137)

本文整理了Java中org.mongodb.morphia.Datastore.update()方法的一些代码示例,展示了Datastore.update()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Datastore.update()方法的具体详情如下:
包路径:org.mongodb.morphia.Datastore
类名称:Datastore
方法名:update

Datastore.update介绍

[英]Updates an entity with the operations; this is an atomic operation
[中]使用操作更新实体;这是一个原子操作

代码示例

代码示例来源:origin: de.mhus.lib/mhu-lib-persistence

public <T> UpdateResults update(Query<T> query, UpdateOperations<T> operations) {
  return datastore.update(query, operations);
}

代码示例来源:origin: protegeproject/webprotege

@Override
public void removeTag(@Nonnull OWLEntity entity, @Nonnull TagId tagId) {
  try {
    writeLock.lock();
    Query<EntityTags> query = tagWithProjectIdAndEntity(projectId, entity);
    UpdateOperations<EntityTags> updateOps = datastore.createUpdateOperations(EntityTags.class);
    updateOps.removeAll(TAGS, tagId);
    datastore.update(query, updateOps);
  } finally {
    writeLock.unlock();
  }
}

代码示例来源:origin: protegeproject/webprotege

@Override
public void addTag(@Nonnull OWLEntity entity, @Nonnull TagId tagId) {
  try {
    writeLock.lock();
    Query<EntityTags> query = tagWithProjectIdAndEntity(projectId, entity);
    UpdateOperations<EntityTags> updateOps = datastore.createUpdateOperations(EntityTags.class);
    updateOps.addToSet(TAGS, tagId);
    datastore.update(query, updateOps);
  } finally {
    writeLock.unlock();
  }
}

代码示例来源:origin: protegeproject/webprotege

public void addCommentToThread(@Nonnull ThreadId threadId,
                @Nonnull Comment comment) {
  Query<EntityDiscussionThread> query = createQueryForThread(threadId);
  UpdateOperations<EntityDiscussionThread> ops = getUpdateOperations().push(COMMENTS, comment);
  datastore.update(query, ops, false);
}

代码示例来源:origin: protegeproject/webprotege

@Override
public void setApiKeys(@Nonnull UserId userId, List<ApiKeyRecord> records) {
  Set<ApiKeyId> ids = new HashSet<>();
  List<ApiKeyRecord> nonDuplicates = records.stream()
                       .filter(r -> ids.add(r.getApiKeyId()))
                       .collect(Collectors.toList());
  UpdateOperations<UserApiKeys> ops = datastore.createUpdateOperations(UserApiKeys.class)
                         .set(API_KEYS, nonDuplicates);
  Query<UserApiKeys> query = datastore.createQuery(UserApiKeys.class)
                    .field(USER_ID).equal(userId);
  datastore.update(query, ops, new UpdateOptions().upsert(true));
}

代码示例来源:origin: protegeproject/webprotege

@Override
public void removeTag(@Nonnull TagId tagId) {
  try {
    writeLock.lock();
    Query<EntityTags> query = datastore.createQuery(EntityTags.class)
                      .field(PROJECT_ID).equal(projectId);
    UpdateOperations<EntityTags> updateOps = datastore.createUpdateOperations(EntityTags.class);
    updateOps.removeAll(TAGS, tagId);
    datastore.update(query, updateOps);
  } finally {
    writeLock.unlock();
  }
}

代码示例来源:origin: protegeproject/webprotege

public void setLastLogin(@Nonnull UserId userId, long lastLogin) {
  if(userId.isGuest()) {
    return;
  }
  getByUserId(userId);
  Query<UserActivityRecord> query = queryByUserId(userId);
  UpdateOperations<UserActivityRecord> operations = datastore.createUpdateOperations(UserActivityRecord.class)
                                .set(LAST_LOGIN, new Date(lastLogin));
  datastore.update(query, operations);
}

代码示例来源:origin: protegeproject/webprotege

public void setLastLogout(@Nonnull UserId userId, long lastLogout) {
  if(userId.isGuest()) {
    return;
  }
  getByUserId(userId);
  Query<UserActivityRecord> query = queryByUserId(userId);
  UpdateOperations<UserActivityRecord> operations = datastore.createUpdateOperations(UserActivityRecord.class)
                                .set(LAST_LOGOUT, new Date(lastLogout));
  datastore.update(query, operations);
}

代码示例来源:origin: BlackLabs/play-morphia

public <T> UpdateResults updateAll() {
  return ds().update((QueryImpl) ds().createQuery(c_), (UpdateOperations<T>)u_);
}

代码示例来源:origin: BlackLabs/play-morphia

public <T> UpdateResults update(String query, Object... params) {
  MorphiaQuery q = new MorphiaQuery(c_).findBy(query, params);
  return ds().update((Query<T>)q.getMorphiaQuery(), (UpdateOperations<T>)u_);
}

代码示例来源:origin: protegeproject/webprotege

@Override
public void save(CollectionItemData data) {
  Query<CollectionItemData> query = createQuery(data.getCollectionId())
      .field(ITEM).equal(data.getItem());
  UpdateOperations<CollectionItemData> updateOperations = datastore.createUpdateOperations(
      CollectionItemData.class);
  Optional<FormData> formData = data.getFormData();
  if (formData.isPresent()) {
    updateOperations.set(FORM_DATA, formData.get());
  }
  else {
    updateOperations.unset(FORM_DATA);
  }
  datastore.update(query, updateOperations, new UpdateOptions().upsert(true));
}

代码示例来源:origin: protegeproject/webprotege

public void replaceEntity(ProjectId projectId, OWLEntity entity, OWLEntity withEntity) {
  Query<EntityDiscussionThread> query = datastore.find(EntityDiscussionThread.class)
                          .field(PROJECT_ID).equal(projectId)
                          .field(ENTITY).equal(entity);
  UpdateOperations<EntityDiscussionThread> updateOperations = datastore.createUpdateOperations(EntityDiscussionThread.class);
  updateOperations.set("entity", withEntity);
  datastore.update(query, updateOperations);
}

代码示例来源:origin: NationalSecurityAgency/lemongrenade

public void updatePush(String jobId, String var, String value) {
  Query<LGJob> query = createQuery().field("_id").equal(jobId);
  UpdateOperations<LGJob> ops = getDatastore().createUpdateOperations(LGJob.class).add(var, value);
  getDatastore().update(query, ops);
}

代码示例来源:origin: NationalSecurityAgency/lemongrenade

public void update(String taskId, String var, String value) {
  Query<LGTask> query = createQuery().field("_id").equal(taskId);
  UpdateOperations<LGTask> ops = getDatastore().createUpdateOperations(LGTask.class).set(var, value);
  getDatastore().update(query, ops);
}

代码示例来源:origin: NationalSecurityAgency/lemongrenade

public void update(String taskId, String var, long value) {
  Query<LGTask> query = createQuery().field("_id").equal(taskId);
  UpdateOperations<LGTask> ops = getDatastore().createUpdateOperations(LGTask.class).set(var, value);
  getDatastore().update(query, ops);
}

代码示例来源:origin: NationalSecurityAgency/lemongrenade

public void update(String taskId, String var, boolean value) {
  Query<LGTask> query = createQuery().field("_id").equal(taskId);
  UpdateOperations<LGTask> ops = getDatastore().createUpdateOperations(LGTask.class).set(var, value);
  getDatastore().update(query, ops);
}

代码示例来源:origin: NationalSecurityAgency/lemongrenade

public void update(String jobId, String var, String value) {
  Query<LGJob> query = createQuery().field("_id").equal(jobId);
  UpdateOperations<LGJob> ops = getDatastore().createUpdateOperations(LGJob.class).set(var, value);
  getDatastore().update(query, ops);
}

代码示例来源:origin: NationalSecurityAgency/lemongrenade

public void updateInt(String jobId, String var, int value) {
  Query<LGJob> query = createQuery().field("_id").equal(jobId);
  UpdateOperations<LGJob> ops = getDatastore().createUpdateOperations(LGJob.class).set(var, value);
  getDatastore().update(query, ops);
}

代码示例来源:origin: NationalSecurityAgency/lemongrenade

public void updateInt(String taskId, String var, int value) {
  Query<LGTask> query = createQuery().field("_id").equal(taskId);
  UpdateOperations<LGTask> ops = getDatastore().createUpdateOperations(LGTask.class).set(var, value);
  getDatastore().update(query.disableValidation(), ops);
}

代码示例来源:origin: protegeproject/webprotege

public void store(ProjectId projectId, CollectionId collectionId, FormId formId, OWLEntity entity, FormData formData) {
  Query<FormDataRecord> query = datastore.createQuery(FormDataRecord.class)
                      .field("projectId").equal(projectId)
                      .field("collectionId").equal(collectionId)
                      .field("formId").equal(formId)
                      .field("subjectId").equal(entity.toString());
  UpdateOperations<FormDataRecord> update = datastore.createUpdateOperations(FormDataRecord.class);
  update.set("data", formData);
  datastore.update(query, update, new UpdateOptions().upsert(true));
}

相关文章