Ejemplo n.º 1
0
    @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>();
        for (String f : fillSearchFieldsIfEmpty_(searchFields)) {
          cl.add(q.criteria(f).containsIgnoreCase(keywords));
        }
        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;
    }
Ejemplo n.º 2
0
    @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>();
        for (String f : fillSearchFieldsIfEmpty_(searchFields)) {
          cl.add(q.criteria(f).contains(keywords));
        }
        q.or(cl.toArray(new Criteria[] {}));
      }

      processWhere(q, where);
      return q.countAll();
    }