org.mongodb.morphia.query.Query.criteria()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(5.8k)|赞(0)|评价(0)|浏览(199)

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

Query.criteria介绍

[英]Creates a criteria to apply against a field
[中]创建要应用于字段的条件

代码示例

代码示例来源:origin: org.actframework/act-morphia

public FieldEnd<? extends CriteriaContainerImpl> criteria(
    String field) {
  return mq.criteria(field);
}

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

public <T extends Model> FieldEnd<? extends CriteriaContainerImpl> criteria(
    String field) {
  return q_.criteria(field);
}

代码示例来源:origin: lievendoclo/cleanarch

@Override
public List<Building> findByNameStartingWith(String name) {
  final Query<BuildingDocument> query = datastore.createQuery(BuildingDocument.class);
  query.criteria("name").startsWith(name);
  return query.asList().stream().map(this::toDomain).collect(toList());
}

代码示例来源:origin: getheimdall/heimdall

private <T> Query<T> prepareQuery(Object criteria, Datastore dataStore) {
  Query<T> query = (Query<T>) dataStore.createQuery(criteria.getClass());
  List<Field> fields = this.getAllModelFields(criteria.getClass());
  for (Field field : fields) {
     field.setAccessible(true);
     Object value = null;
     try {
       value = field.get(criteria);
     } catch (IllegalArgumentException | IllegalAccessException e) {
       log.error(e.getMessage(), e);
     }
     if (value != null) {
       query.criteria(field.getName()).equal(value);
     }
  }
  return query;
}

代码示例来源:origin: getheimdall/heimdall

private <T> Query<T> prepareQuery(Object criteria, Datastore dataStore) {
  Query<T> query = (Query<T>) dataStore.createQuery(criteria.getClass());
  List<Field> fields = this.getAllModelFields(criteria.getClass());
  for (Field field : fields) {
    field.setAccessible(true);
    Object value = null;
    try {
      value = field.get(criteria);
    } catch (IllegalArgumentException | IllegalAccessException ignored) {}
    if (value != null) {
      query.criteria(field.getName()).equal(value);
    }
  }
  return query;
}

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

@Override
public Long count(List<String> searchFields, String keywords,
         String where) {
  Query<?> q = ds().createQuery(clazz);
  if (keywords != null && !keywords.equals("")) {
    List<Criteria> cl = new ArrayList<Criteria>();
    String[] sa = keywords.split("[\\W]+");
    for (String f : fillSearchFieldsIfEmpty_(searchFields)) {
      for (String s : sa) {
        cl.add(q.criteria(f).containsIgnoreCase(keywords));
      }
    }
    q.or(cl.toArray(new Criteria[]{}));
  }
  processWhere(q, where);
  return q.countAll();
}

代码示例来源:origin: groupon/DotCi

private Query<DynamicBuild> filterBranch(final Query<DynamicBuild> query) {
  final String branch = getBranch();
  if ("All".equals(branch)) {
    return query;
  }
  if ("Mine".equals(branch)) {
    query.or(
      query.criteria("actions.causes.user").equal(Jenkins.getAuthentication().getName()),
      query.criteria("actions.causes.pusher").equal(Jenkins.getAuthentication().getName())
    );
    return query;
  }
  return getDynamicBuildRepository().filterExpression(branch, query);
}

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

@Override
public List<play.db.Model> fetch(int offset, int size, String orderBy,
                 String order, List<String> searchFields, String keywords,
                 String where) {
  if (orderBy == null)
    orderBy = keyName();
  if ("DESC".equalsIgnoreCase(order))
    orderBy = null == orderBy ? null : "-" + orderBy;
  Query<? extends Model> q = ds().createQuery(clazz).offset(offset)
      .limit(size);
  if (null != orderBy)
    q = q.order(orderBy);
  if (keywords != null && !keywords.equals("")) {
    List<Criteria> cl = new ArrayList<Criteria>();
    String[] sa = keywords.split("[\\W]+");
    for (String f : fillSearchFieldsIfEmpty_(searchFields)) {
      List<Criteria> cl0 = new ArrayList<Criteria>();
      for (String s : sa) {
        cl0.add(q.criteria(f).containsIgnoreCase(s));
      }
      cl.add(q.and(cl0.toArray(new Criteria[]{})));
    }
    q.or(cl.toArray(new Criteria[]{}));
  }
  processWhere(q, where);
  List<play.db.Model> l = new ArrayList<play.db.Model>();
  l.addAll(q.asList());
  return l;
}

代码示例来源:origin: groupon/DotCi

private Query<DynamicBuild> getDynamicBuildsForUser(final String user, final int numberOfBuilds) {
  final Query<DynamicBuild> query = getDatastore().createQuery(DynamicBuild.class)
    .limit(numberOfBuilds)
    .disableValidation()
    .order("-timestamp")
    .field("className").equal("com.groupon.jenkins.dynamic.build.DynamicBuild");
  query.or(
    query.criteria("actions.causes.user").equal(user),
    query.criteria("actions.causes.pusher").equal(user)
  );
  return query;
}

代码示例来源:origin: RentTheRunway/alchemy

query.criteria("name").containsIgnoreCase(filter.getFilter()),
  query.criteria("description").containsIgnoreCase(filter.getFilter())
);

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

private Query<RoleAssignment> withUserOrAnyUserAndTarget(Subject subject, Resource resource) {
  String userName = toUserName(subject);
  String projectId = toProjectId(resource);
  Query<RoleAssignment> query = datastore.createQuery(RoleAssignment.class)
                      .field(PROJECT_ID).equal(projectId);
  if (!subject.isGuest()) {
    query.or(
        query.criteria(USER_NAME).equal(userName),
        query.criteria(USER_NAME).equal(null)
    );
  }
  else {
    query.field(USER_NAME).equal(userName);
  }
  return query;
}

代码示例来源:origin: groupon/DotCi

public <T extends DbBackedBuild> Iterable<T> getCurrentUserBuilds(final DbBackedProject project, final int i, final Result result) {
  Query<DbBackedBuild> query = getQuery(project)
    .limit(i)
    .order("-number");
  query.or(
    query.criteria("actions.causes.user").equal(Jenkins.getAuthentication().getName()),
    query.criteria("actions.causes.pusher").equal(Jenkins.getAuthentication().getName())
  );
  if (result != null) {
    query = query.filter("result", result.toString());
  }
  final List<DbBackedBuild> builds = query.asList();
  for (final DbBackedBuild build : builds) {
    associateProject(project, build);
  }
  return (Iterable<T>) builds;
}

相关文章