org.springframework.data.mongodb.core.query.Criteria类的使用及代码示例

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

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

Criteria介绍

[英]Central class for creating queries. It follows a fluent API style so that you can easily chain together multiple criteria. Static import of the 'Criteria.where' method will improve readability.
[中]用于创建查询的中心类。它遵循流畅的API风格,因此您可以轻松地将多个条件链接在一起。“条件”的静态导入。where'方法将提高可读性。

代码示例

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

@Override
public boolean exists(String scriptName) {
  Assert.hasText(scriptName, "ScriptName must not be null or empty!");
  return mongoOperations.exists(query(where("_id").is(scriptName)), NamedMongoScript.class, SCRIPT_COLLECTION_NAME);
}

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

@Override
public <S extends T> long count(Example<S> example) {
  Assert.notNull(example, "Sample must not be null!");
  Query q = new Query(new Criteria().alike(example));
  return mongoOperations.count(q, example.getProbeType(), entityInformation.getCollectionName());
}

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

@Override
public Flux<T> findAllById(Iterable<ID> ids) {
  Assert.notNull(ids, "The given Iterable of Id's must not be null!");
  return findAll(new Query(new Criteria(entityInformation.getIdAttribute())
      .in(Streamable.of(ids).stream().collect(StreamUtils.toUnmodifiableList()))));
}

代码示例来源:origin: ityouknow/spring-boot-examples

/**
 * 根据用户名查询对象
 * @param userName
 * @return
 */
@Override
public UserEntity findUserByUserName(String userName) {
  Query query=new Query(Criteria.where("userName").is(userName));
  UserEntity user =  mongoTemplate.findOne(query , UserEntity.class);
  return user;
}

代码示例来源:origin: ityouknow/spring-boot-examples

/**
   * 删除对象
   * @param id
   */
  @Override
  public void deleteUserById(Long id) {
    Query query=new Query(Criteria.where("id").is(id));
    mongoTemplate.remove(query,UserEntity.class);
  }
}

代码示例来源:origin: roncoo/spring-boot-demo

public void deleteById(int id) {
  Criteria criteria = Criteria.where("id").in(id);
  Query query = new Query(criteria);
  mongoTemplate.remove(query, RoncooUser.class);
}

代码示例来源:origin: com.bq.oss.lib/mongodb

private boolean doUpdate(Object id, DBObject data, String... fieldsToDelete) {
  Assert.notNull(id);
  data.removeField("_id");
  Update update = new Update();
  setField("", data, update);
  for (String field : fieldsToDelete) {
    update.unset(field);
  }
  WriteResult result = mongoOperations.updateFirst(Query.query(Criteria.where("_id").is(id)), update,
      metadata.getCollectionName());
  return result.getN() != 0;
}

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

/**
 * Creates a criterion ({@code $jsonSchema}) matching documents against a given structure defined by the
 * {@link MongoJsonSchema}. <br />
 * <strong>NOTE:</strong> {@code $jsonSchema} cannot be used on field/property level but defines the whole document
 * structure. Please use
 * {@link org.springframework.data.mongodb.core.schema.MongoJsonSchema.MongoJsonSchemaBuilder#properties(JsonSchemaProperty...)}
 * to specify nested fields or query them using the {@link #type(Type...) $type} operator.
 *
 * @param schema must not be {@literal null}.
 * @return this
 * @since 2.1
 * @see <a href="https://docs.mongodb.com/manual/reference/operator/query/jsonSchema/">MongoDB Query operator:
 *      $jsonSchema</a>
 */
public Criteria andDocumentStructureMatches(MongoJsonSchema schema) {
  Assert.notNull(schema, "Schema must not be null!");
  Criteria schemaCriteria = new Criteria();
  schemaCriteria.criteria.putAll(schema.toDocument());
  return registerCriteriaChainElement(schemaCriteria);
}

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

@Override
@ManagedAttribute
public int getMessageCountForAllMessageGroups() {
  Query query = Query.query(Criteria.where(MessageDocumentFields.MESSAGE_ID).exists(true)
      .and(MessageDocumentFields.GROUP_ID).exists(true));
  long count = this.mongoTemplate.count(query, this.collectionName);
  Assert.isTrue(count <= Integer.MAX_VALUE, "Message count is out of Integer's range");
  return (int) count;
}

代码示例来源:origin: kaaproject/kaa

@Override
public void removeByEndpointKeyHashAndConfigurationVersion(byte[] endpointKeyHash, Integer confSchemaVersion) {
 LOG.debug("Remove endpoint specific configuration by endpoint key hash [{}] ", endpointKeyHash);
 mongoTemplate.remove(
   query(where(EP_SPECIFIC_CONFIGURATION_KEY_HASH).is(endpointKeyHash)
     .and(EP_CONFIGURATION_VERSION).is(confSchemaVersion)), getCollectionName());
}

代码示例来源:origin: yu199195/hmily

@Override
public List<HmilyTransaction> listAllByDelay(final Date date) {
  Query query = new Query();
  query.addCriteria(Criteria.where("lastTime").lt(date));
  final List<MongoAdapter> mongoBeans =
      template.find(query, MongoAdapter.class, collectionName);
  if (CollectionUtils.isNotEmpty(mongoBeans)) {
    return mongoBeans.stream().map(this::buildByCache).collect(Collectors.toList());
  }
  return Collections.emptyList();
}

代码示例来源:origin: yu199195/hmily

final PageParameter pageParameter = query.getPageParameter();
final int pageSize = pageParameter.getPageSize();
Query baseQuery = new Query();
if (StringUtils.isNoneBlank(query.getTransId())) {
  baseQuery.addCriteria(new Criteria("transId").is(query.getTransId()));
  baseQuery.addCriteria(new Criteria("retriedCount").lt(query.getRetry()));
final long totalCount = mongoTemplate.count(baseQuery, mongoTableName);
if (totalCount <= 0) {
  return voCommonPager;
baseQuery.skip(start).limit(pageSize);
final List<MongoAdapter> mongoAdapters =
    mongoTemplate.find(baseQuery, MongoAdapter.class, mongoTableName);
if (CollectionUtils.isNotEmpty(mongoAdapters)) {
  final List<HmilyCompensationVO> recoverVOS =

代码示例来源:origin: roncoo/spring-boot-demo

public void updateById(RoncooUser roncooUser) {
  Criteria criteria = Criteria.where("id").in(roncooUser.getId());
  Query query = new Query(criteria);
  Update update = new Update();
  update.set("name", roncooUser.getName());
  update.set("createTime", roncooUser.getCreateTime());
  mongoTemplate.updateMulti(query, update, RoncooUser.class);
}

代码示例来源:origin: yu199195/hmily

@Override
public int remove(final String id) {
  AssertUtils.notNull(id);
  Query query = new Query();
  query.addCriteria(new Criteria("transId").is(id));
  template.remove(query, collectionName);
  return ROWS;
}

代码示例来源:origin: yu199195/Raincat

@Override
public List<TransactionRecover> listAllByDelay(final Date date) {
  Query query = new Query();
  query.addCriteria(new Criteria("status")
      .in(TransactionStatusEnum.BEGIN.getCode(),
          TransactionStatusEnum.FAILURE.getCode(),
          TransactionStatusEnum.ROLLBACK.getCode()))
      .addCriteria(Criteria.where("lastTime").lt(date));
  final List<MongoAdapter> mongoBeans =
      template.find(query, MongoAdapter.class, collectionName);
  if (CollectionUtils.isNotEmpty(mongoBeans)) {
    return mongoBeans.stream().map(this::buildByCache).collect(Collectors.toList());
  }
  return null;
}

代码示例来源:origin: roncoo/spring-boot-demo

public RoncooUser selectById(int id) {
    Criteria criteria = Criteria.where("id").in(id);
    Query query = new Query(criteria);
    return mongoTemplate.findOne(query, RoncooUser.class);
  }
}

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

@Override
public Query getQueryForVersion() {
  MongoPersistentProperty idProperty = entity.getRequiredIdProperty();
  MongoPersistentProperty property = entity.getRequiredVersionProperty();
  return new Query(Criteria.where(idProperty.getName()).is(getId())//
      .and(property.getName()).is(getVersion()));
}

代码示例来源:origin: yu199195/hmily

@Override
public HmilyTransaction findById(final String id) {
  Query query = new Query();
  query.addCriteria(new Criteria("transId").is(id));
  MongoAdapter cache = template.findOne(query, MongoAdapter.class, collectionName);
  return buildByCache(Objects.requireNonNull(cache));
}

代码示例来源:origin: yu199195/hmily

@Override
public int updateStatus(final String id, final Integer status) {
  Query query = new Query();
  query.addCriteria(new Criteria("transId").is(id));
  Update update = new Update();
  update.set("status", status);
  final UpdateResult updateResult = template.updateFirst(query, update, MongoAdapter.class, collectionName);
  if (updateResult.getModifiedCount() <= 0) {
    throw new HmilyRuntimeException("update data exception!");
  }
  return ROWS;
}

代码示例来源:origin: kaaproject/kaa

@Override
public List<MongoNotification>
  findNotificationsByTopicIdAndVersionAndStartSecNum(
    String topicId,
    int seqNumber,
    int sysNfVersion,
    int userNfVersion
) {
 LOG.debug("Find notifications by topic id [{}], sequence number start [{}], "
     + "system schema version [{}], user schema version [{}]",
   topicId, seqNumber, sysNfVersion, userNfVersion);
 return find(query(where(NF_TOPIC_ID)
   .is(topicId)
   .and(NF_SEQ_NUM)
   .gt(seqNumber)
   .orOperator(where(NF_VERSION)
       .is(sysNfVersion)
       .and(NF_TYPE)
       .is(SYSTEM),
     where(NF_VERSION)
       .is(userNfVersion)
       .and(NF_TYPE)
       .is(USER))));
}

相关文章