Exemplo n.º 1
0
 @Override
 public Iterator<Item> iterator() {
   PathQuery pq = new PathQuery(services.getModel());
   pq.addViews(PQUtil.getStar(services.getModel(), getType()));
   pq.addConstraint(Constraints.in(type, name));
   Iterator<Map<String, Object>> it = services.getQueryService().getRowMapIterator(pq);
   return new ItemIterator(it);
 }
Exemplo n.º 2
0
 /**
  * Convenience method for finding members of a collection matching certain properties.
  *
  * <p>This search is implemented with a query that performs case-insensitive matching on values.
  * Null constraints will be honoured, but other lookups will be converted to strings. Wild-cards
  * are permitted wherever they are permitted in path-queries. <br>
  * Using a query to back the search means that finding matching members is efficient even over
  * large lists - you will not need to pull in and iterate over thousands of rows of data to find
  * items if you have specific conditions. <br>
  * These conditions must all match for the result to be included. For more specific and flexible
  * searching strategies, please see the {@link PathQuery} API.
  *
  * @param conditions The properties these elements should have.
  * @return A list of matching items.
  */
 public List<Item> find(Map<String, Object> conditions) {
   List<Item> ret = new ArrayList<Item>();
   PathQuery q = new PathQuery(services.getModel());
   q.addViews(PQUtil.getStar(services.getModel(), type));
   q.addConstraint(Constraints.in(type, name));
   for (Entry<String, Object> condition : conditions.entrySet()) {
     String path = type + "." + condition.getKey();
     if (condition.getValue() == null) {
       q.addConstraint(Constraints.isNull(path));
     } else {
       q.addConstraint(Constraints.eq(path, condition.getValue().toString()));
     }
   }
   List<Map<String, Object>> results = services.getQueryService().getRowsAsMaps(q);
   for (Map<String, Object> result : results) {
     ret.add(new Item(services, type, result));
   }
   return ret;
 }