org.springframework.data.mongodb.core.query.Criteria.andOperator()方法的使用及代码示例

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

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

Criteria.andOperator介绍

[英]Creates an 'and' criteria using the $and operator for all of the provided criteria.

Note that mongodb doesn't support an $and operator to be wrapped in a $not operator.
[中]使用$and运算符为所有提供的条件创建“and”条件。
请注意,mongodb不支持将$and运算符包装在$not运算符中。

代码示例

代码示例来源:origin: pl.edu.icm.polindex/polindex-tools

private static Criteria andOperatorSafe(Criteria criteria1, Criteria criteria2) {
  if(criteria1 == null && criteria2 == null) {
    return null;
  }
  if(criteria1 == null) {
    return criteria2;
  }
  if(criteria2 == null) {
    return criteria1;
  }
  return criteria1.andOperator(criteria2);
}

代码示例来源:origin: pl.edu.icm.polindex/polindex-core

private Criteria andSafeCriterion(Criteria crit_1, Criteria crit_2) {
  if(crit_1 == null) {
    return crit_2;
  } else if(crit_2 == null) {
    return crit_1;
  } else {
    return new Criteria().andOperator(crit_1, crit_2);
  }
}

代码示例来源:origin: com.github.rutledgepaulv/q-builders

@Override
protected Criteria visit(AndNode node) {
  Criteria criteria = new Criteria();
  List<Criteria> children = node.getChildren().stream()
      .map(this::visitAny).collect(Collectors.toList());
  return criteria.andOperator(children.toArray(new Criteria[children.size()]));
}

代码示例来源:origin: de.adorsys.smartanalytics/smartanalytics-persistence

@Override
  public Iterable<RuleEntity> search(String search) {
    Collection<String> terms = new HashSet<>(Arrays.asList(search.split(" ")));

    Criteria[] criterias = terms
        .stream()
        .map(s -> Criteria.where("searchIndex").regex(s.toLowerCase(), "iu"))
        .toArray(Criteria[]::new);

    return mongoTemplate.find(Query.query(new Criteria().andOperator(criterias)).with(Sort.by("order")), RuleEntity.class);
  }
}

代码示例来源:origin: com.epam.reportportal/commons-dao

@Override
public List<String> findBinaryIdsByLogRefs(List<String> ids) {
  Aggregation aggregation = newAggregation(match(where("id").in(ids).andOperator(where("binaryContent").exists(true))),
      group("binaryContent.binaryDataId", "binaryContent.thumbnailId"));
  AggregationResults<Map> results = mongoTemplate.aggregate(aggregation, Log.class, Map.class);
  return results.getMappedResults().stream().flatMap(it -> (Stream<String>) it.values().stream()).collect(toList());
}

代码示例来源:origin: com.epam.reportportal/commons-dao

@Override
public List<String> findBinaryIdsByItemRefs(List<String> ids) {
  Aggregation aggregation = newAggregation(match(where("testItemRef").in(ids).andOperator(where("binaryContent").exists(true))),
      group("binaryContent.binaryDataId", "binaryContent.thumbnailId"));
  AggregationResults<Map> results = mongoTemplate.aggregate(aggregation, Log.class, Map.class);
  return results.getMappedResults().stream().flatMap(it -> (Stream<String>) it.values().stream()).collect(toList());
}

代码示例来源:origin: sentilo/sentilo

protected Query buildQuery(final String paramName, final Collection<String> values, final Map<String, Object> filterParams) {
 Criteria queryCriteria = Criteria.where(paramName).in(values);
 if (!CollectionUtils.isEmpty(filterParams)) {
  final Criteria[] aCriteria = buildAndParamsCriteria(filterParams);
  queryCriteria = queryCriteria.andOperator(aCriteria);
 }
 return new Query(queryCriteria);
}

代码示例来源:origin: sentilo/sentilo

private List<InternalAlert> getInternalAlerts() {
 LOGGER.debug("Searching active internal alerts ....");
 final Criteria typeCriteria = Criteria.where("type").is(AlertType.INTERNAL.name());
 final Criteria activeCriteria = Criteria.where("active").is(Boolean.TRUE);
 final Query query = new Query(typeCriteria.andOperator(activeCriteria));
 final List<InternalAlert> content = mongoOps.find(query, InternalAlert.class, "alert");
 LOGGER.debug("... and found {} alerts to monitor.", content.size());
 return content;
}

代码示例来源:origin: pl.edu.icm.synat/synat-business-services-impl

@Override
public long countNewNotifications(String userId) {
  if (userId == null) {
    throw new ObservationException("User identifier cannot be null.");
  }
  Criteria criteria = Criteria.where(QUERY_PARAM_NOTIFICATION_USER_ID).is(userId);
  criteria.andOperator(Criteria.where(QUERY_PARAM_NOTIFICATION_IS_NEW).is(true));
  Query query = new Query(criteria);
  long count = mongoTemplate.count(query, mongoCollectionName);
  return count;
}

代码示例来源:origin: com.epam.reportportal/commons-dao

/**
   * Create criteria for loading owned entities and shared to specified project entities
   *
   * @param projectName
   * @param userName
   * @return
   */
  private Criteria getAllEntitiesCriteria(String projectName, String userName) {
    return new Criteria().orOperator(new Criteria().andOperator(Criteria.where("acl.entries.projectId").is(projectName),
        Criteria.where("acl.entries.permissions").is(AclPermissions.READ.name())
    ), new Criteria().andOperator(Criteria.where("acl.ownerUserId").is(userName), Criteria.where("projectName").is(projectName)));
  }
}

代码示例来源:origin: com.epam.reportportal/commons-dao

@Override
public List<TestItem> findTestItemWithIssues(String launchId) {
  Criteria externalIssues = new Criteria().andOperator(where(LAUNCH_REFERENCE).is(launchId), where(ISSUE).exists(true));
  Query query = query(externalIssues);
  return mongoTemplate.find(query, TestItem.class);
}

代码示例来源:origin: pl.edu.icm.synat/synat-business-services-impl

private ElementCollection getElementCollectionForUser(String collectionId, String userId) {
  checkElementCollection(collectionId);
  Criteria criteriaForPublic = Criteria.where(F_COLLECTION_ID).is(collectionId)
      .andOperator(Criteria.where(F_COLLECTION_VISIBILITY).is(CollectionVisibility.PUBLIC.name()));
  Query query = new Query(criteriaForPublic);
  ElementCollection item = mongoTemplate.findOne(query, ElementCollection.class, mongoCollectionName);
  if (item == null && userId != null) {
    Criteria criteriaForUser = Criteria.where(F_COLLECTION_ID).is(collectionId)
        .andOperator(Criteria.where(F_USERS_ID).is(userId));
    query = new Query(criteriaForUser);
    item = mongoTemplate.findOne(query, ElementCollection.class, mongoCollectionName);
  }
  return item;
}

代码示例来源:origin: pl.edu.icm.synat/synat-business-services-impl

@Override
@RequiresServiceRole(roleName="READ")
public CollectionData fetchSpecialCollection(String userId, String type) {
  Query query = new Query(Criteria.where(F_USERS_ID).is(userId).andOperator(Criteria.where(F_COLLECTION_TYPE).is(type)));
  ElementCollection elementCollection = mongoTemplate.findOne(query, ElementCollection.class, mongoCollectionName);
  return convertToCollectionData(elementCollection);
}

代码示例来源:origin: pl.edu.icm.synat/synat-business-services-impl

@Override
public void removeCriteriaByObjectId(String userId, String objectId) {
  if (userId == null) {
    throw new ObservationException("User identifier cannot be null.");
  }
  if (objectId == null) {
    throw new ObservationException("Object identifier cannot be null.");
  }
  Criteria criteria = Criteria.where(QUERY_PARAM_USER_ID).is(userId);
  criteria.andOperator(Criteria.where(QUERY_PARAM_OBJECT_ID).is(objectId));
  Query query = new Query(criteria);
  mongoTemplate.remove(query, mongoCollectionName);
}

代码示例来源:origin: pl.edu.icm.polindex/polindex-core

private Criteria precedingByModificationDateAndIdCriterion(Date date, String id) {
  Criteria criteria = new Criteria()
      .orOperator(
          Criteria.where(PROPERTY_MODIFICATION_DATE).lt(date),
          new Criteria().andOperator(
              Criteria.where(PROPERTY_MODIFICATION_DATE).is(date),
              Criteria.where(F_ID).lt(id)
          )
      );
  return criteria;
}

代码示例来源:origin: pl.edu.icm.synat/synat-business-services-impl

@Override
@RequiresServiceRole(roleName="READ")
public List<CollectionWithDocumentData> listPublicCollectionsWithElement(String elementId) {
  Criteria criteria = Criteria.where(F_ATTACHED_DOCUMENT_ID).is(elementId).andOperator(
      Criteria.where(F_COLLECTION_VISIBILITY).is(CollectionVisibility.PUBLIC.name()));
  
  Query query = new Query(criteria);
  List<ElementCollection> items = mongoTemplate.find(query, ElementCollection.class, mongoCollectionName);
  return convertWithDocument(items, elementId);
}

代码示例来源:origin: pl.edu.icm.polindex/polindex-core

private Criteria followingByModificationDateAndIdCriterion(Date date, String id) {
  Criteria criteria = new Criteria()
      .orOperator(
          Criteria.where(PROPERTY_MODIFICATION_DATE).gt(date),
          new Criteria().andOperator(
              Criteria.where(PROPERTY_MODIFICATION_DATE).is(date),
              Criteria.where(F_ID).gt(id)
          )
      );
  return criteria;
}

代码示例来源:origin: com.epam.reportportal/commons-dao

@Override
  public List<UserFilter> findAvailableFilters(String projectName, String[] ids, String userName) {
    //where ID from provided array AND it's shared on project
    Query q = Query.query(where(ID).in(Arrays.asList(ids))
        .andOperator(new Criteria()
            .orOperator(
                where(OWNER).is(userName),
                where(PROJECT).is(projectName),
                where(ENTRIES).elemMatch(where("projectId").is(projectName)))));
    return mongoTemplate.find(q, UserFilter.class);
  }
}

代码示例来源:origin: pl.edu.icm.synat/synat-business-services-impl

private ElementCollection getElementCollectionForEditor(String collectionId, String userId) {
  checkElementCollection(collectionId);
  Query query = new Query(Criteria
      .where(F_COLLECTION_ID)
      .is(collectionId)
      .andOperator(Criteria.where(F_USERS_ID).is(userId),
          Criteria.where(F_USERS_ROLE).in(CollectionRole.EDITOR.name(), CollectionRole.CREATOR.name())));
  
  ElementCollection collection = mongoTemplate.findOne(query, ElementCollection.class, mongoCollectionName);
  return collection;
}

代码示例来源:origin: sentilo/sentilo

public String getSensorType(final String provider, final String sensor) {
 final String cacheKey = provider + "#" + sensor;
 if (sensorTypesCache.get(cacheKey) == null) {
  final Criteria queryCriteria = Criteria.where("sensorId").is(sensor);
  queryCriteria.andOperator(Criteria.where("providerId").is(provider));
  final Query query = new Query(queryCriteria);
  query.fields().include("type");
  sensorTypesCache.put(cacheKey, mongoOperations.findOne(query, CatalogAdditionalFields.class, "sensor").getType());
 }
 return sensorTypesCache.get(cacheKey);
}

相关文章