org.springframework.data.mongodb.core.MongoTemplate.findAndRemove()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(7.4k)|赞(0)|评价(0)|浏览(130)

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

MongoTemplate.findAndRemove介绍

暂无

代码示例

代码示例来源:origin: spring-projects/spring-data-mongodb

@Nullable
@Override
public <T> T findAndRemove(Query query, Class<T> entityClass) {
  return findAndRemove(query, entityClass, operations.determineCollectionName(entityClass));
}

代码示例来源:origin: org.springframework.data/spring-data-mongodb

@Nullable
@Override
public <T> T findAndRemove(Query query, Class<T> entityClass) {
  return findAndRemove(query, entityClass, operations.determineCollectionName(entityClass));
}

代码示例来源:origin: spring-projects/spring-integration

@Override
public Message<?> removeMessage(UUID id) {
  Assert.notNull(id, "'id' must not be null");
  MessageWrapper messageWrapper =
      this.template.findAndRemove(whereMessageIdIs(id), MessageWrapper.class, this.collectionName);
  return (messageWrapper != null ? messageWrapper.getMessage() : null);
}

代码示例来源:origin: spring-projects/spring-integration

@Override
public Message<?> removeMessage(UUID id) {
  Assert.notNull(id, "'id' must not be null");
  Query query = Query.query(Criteria.where(MessageDocumentFields.MESSAGE_ID).is(id));
  MessageDocument document = this.mongoTemplate.findAndRemove(query, MessageDocument.class, this.collectionName);
  return (document != null) ? document.getMessage() : null;
}

代码示例来源:origin: spring-projects/spring-integration

/**
 * Remove the metadata entry for the provided {@code key} and return its {@code value}, if any,
 * using {@code findAndRemove} MongoDB operation.
 * @param key the metadata entry key
 * @return the metadata entry value or null if doesn't exist.
 * @see MongoTemplate#findAndRemove(Query, Class, String)
 */
@Override
public String remove(String key) {
  Assert.hasText(key, "'key' must not be empty.");
  Query query = new Query(Criteria.where(ID_FIELD).is(key));
  query.fields().exclude(ID_FIELD);
  @SuppressWarnings("unchecked")
  Map<String, String> result = this.template.findAndRemove(query, Map.class, this.collectionName);
  return result == null ? null : result.get(VALUE);
}

代码示例来源:origin: spring-projects/spring-integration

@Override
public Message<?> pollMessageFromGroup(final Object groupId) {
  Assert.notNull(groupId, "'groupId' must not be null");
  Query query = whereGroupIdIs(groupId).with(Sort.by(GROUP_UPDATE_TIMESTAMP_KEY, SEQUENCE));
  MessageWrapper messageWrapper = this.template.findAndRemove(query, MessageWrapper.class, this.collectionName);
  Message<?> message = null;
  if (messageWrapper != null) {
    message = messageWrapper.getMessage();
  }
  updateGroup(groupId, lastModifiedUpdate());
  return message;
}

代码示例来源:origin: spring-projects/spring-integration

@Override
public Message<?> pollMessageFromGroup(final Object groupId) {
  Assert.notNull(groupId, "'groupId' must not be null");
  Sort sort = Sort.by(MessageDocumentFields.LAST_MODIFIED_TIME, MessageDocumentFields.SEQUENCE);
  Query query = groupIdQuery(groupId).with(sort);
  MessageDocument document = mongoTemplate.findAndRemove(query, MessageDocument.class, collectionName);
  Message<?> message = null;
  if (document != null) {
    message = document.getMessage();
    updateGroup(groupId, lastModifiedUpdate());
  }
  return message;
}

代码示例来源:origin: spring-projects/spring-integration

@Override
public Message<?> pollMessageFromGroup(Object groupId) {
  Assert.notNull(groupId, "'groupId' must not be null");
  Sort sort = Sort.by(MessageDocumentFields.LAST_MODIFIED_TIME, MessageDocumentFields.SEQUENCE);
  if (this.priorityEnabled) {
    sort = Sort.by(Sort.Direction.DESC, MessageDocumentFields.PRIORITY).and(sort);
  }
  Query query = groupIdQuery(groupId).with(sort);
  MessageDocument document = this.mongoTemplate.findAndRemove(query, MessageDocument.class, this.collectionName);
  Message<?> message = null;
  if (document != null) {
    message = document.getMessage();
  }
  return message;
}

代码示例来源:origin: stackoverflow.com

@Repository
public class AppointmentCustomRepository {
  @Autowired
  MongoTemplate mongoTemplate;

  public Appointment getAppointmentAndDelete(String id) {
    return mongoTemplate.findAndRemove(Query.query(Criteria.where("id").is(id)), Appointment.class);
  }
}

代码示例来源:origin: org.springframework.integration/spring-integration-mongodb

@Override
public Message<?> removeMessage(UUID id) {
  Assert.notNull(id, "'id' must not be null");
  MessageWrapper messageWrapper =
      this.template.findAndRemove(whereMessageIdIs(id), MessageWrapper.class, this.collectionName);
  return (messageWrapper != null ? messageWrapper.getMessage() : null);
}

代码示例来源:origin: org.springframework.integration/spring-integration-mongodb

@Override
public Message<?> removeMessage(UUID id) {
  Assert.notNull(id, "'id' must not be null");
  Query query = Query.query(Criteria.where(MessageDocumentFields.MESSAGE_ID).is(id));
  MessageDocument document = this.mongoTemplate.findAndRemove(query, MessageDocument.class, this.collectionName);
  return (document != null) ? document.getMessage() : null;
}

代码示例来源:origin: org.springframework.integration/spring-integration-mongodb

/**
 * Remove the metadata entry for the provided {@code key} and return its {@code value}, if any,
 * using {@code findAndRemove} MongoDB operation.
 * @param key the metadata entry key
 * @return the metadata entry value or null if doesn't exist.
 * @see MongoTemplate#findAndRemove(Query, Class, String)
 */
@Override
public String remove(String key) {
  Assert.hasText(key, "'key' must not be empty.");
  Query query = new Query(Criteria.where(ID_FIELD).is(key));
  query.fields().exclude(ID_FIELD);
  @SuppressWarnings("unchecked")
  Map<String, String> result = this.template.findAndRemove(query, Map.class, this.collectionName);
  return result == null ? null : result.get(VALUE);
}

代码示例来源:origin: org.springframework.integration/spring-integration-mongodb

@Override
public Message<?> pollMessageFromGroup(final Object groupId) {
  Assert.notNull(groupId, "'groupId' must not be null");
  Sort sort = Sort.by(MessageDocumentFields.LAST_MODIFIED_TIME, MessageDocumentFields.SEQUENCE);
  Query query = groupIdQuery(groupId).with(sort);
  MessageDocument document = mongoTemplate.findAndRemove(query, MessageDocument.class, collectionName);
  Message<?> message = null;
  if (document != null) {
    message = document.getMessage();
    updateGroup(groupId, lastModifiedUpdate());
  }
  return message;
}

代码示例来源:origin: org.springframework.integration/spring-integration-mongodb

@Override
public Message<?> pollMessageFromGroup(final Object groupId) {
  Assert.notNull(groupId, "'groupId' must not be null");
  Query query = whereGroupIdIs(groupId).with(Sort.by(GROUP_UPDATE_TIMESTAMP_KEY, SEQUENCE));
  MessageWrapper messageWrapper = this.template.findAndRemove(query, MessageWrapper.class, this.collectionName);
  Message<?> message = null;
  if (messageWrapper != null) {
    message = messageWrapper.getMessage();
  }
  updateGroup(groupId, lastModifiedUpdate());
  return message;
}

代码示例来源:origin: org.springframework.integration/spring-integration-mongodb

@Override
public Message<?> pollMessageFromGroup(Object groupId) {
  Assert.notNull(groupId, "'groupId' must not be null");
  Sort sort = Sort.by(MessageDocumentFields.LAST_MODIFIED_TIME, MessageDocumentFields.SEQUENCE);
  if (this.priorityEnabled) {
    sort = Sort.by(Sort.Direction.DESC, MessageDocumentFields.PRIORITY).and(sort);
  }
  Query query = groupIdQuery(groupId).with(sort);
  MessageDocument document = this.mongoTemplate.findAndRemove(query, MessageDocument.class, this.collectionName);
  Message<?> message = null;
  if (document != null) {
    message = document.getMessage();
  }
  return message;
}

相关文章