DatastoreHelper { public void preFilterGaeKinds(Query query) throws IllegalArgumentException { if (!canPreFilterGaeKinds(query)) { throw new IllegalArgumentException("Cannot pre-filter kinds. Query already contains an inequality filter"); } FilterPredicate filter; if (Entities.KIND_METADATA_KIND.equals(query.getKind())) { filter = new FilterPredicate(Entity.KEY_RESERVED_PROPERTY, LESS_THAN, Entities.createKindKey(ENTITY_PREFIX)); } else { filter = new FilterPredicate(Entity.KEY_RESERVED_PROPERTY, LESS_THAN, KeyFactory.createKey(ENTITY_PREFIX, 1L)); } List<Query.Filter> filters = Lists.<Query.Filter>newArrayList(filter); if (query.getFilter() != null) { filters.add(query.getFilter()); query.setFilter(Query.CompositeFilterOperator.and(filters)); } else { query.setFilter(filter); } }  Entity get(KeyDto keyDto); Entity get(Key key); void delete(Key key, String namespace); void deleteOnAllNamespaces(Query query); Iterable<Entity> queryOnAllNamespaces(Query query); Collection<Entity> queryOnAllNamespaces(
            Query query,
            FetchOptions options); Entity querySingleEntity(String namespace, Query query); Iterable<Entity> queryOnNamespace(String namespace, Query query); Iterable<Entity> queryOnNamespace(String namespace, Query query, FetchOptions fetchOptions); void preFilterGaeKinds(Query query); Iterable<Entity> getAllNamespaces(); boolean canPreFilterGaeKinds(Query query);  }
@Test public void preFilterGaeKinds_validQuery_addsFilter() throws Exception { Query query = new Query(A_KIND); datastoreHelper.preFilterGaeKinds(query); then(query.getFilter()).isInstanceOf(Query.FilterPredicate.class); then(query.getFilter()).isNotNull(); }
@Test public void preFilterGaeKinds_withFilter_addsFilter(@All(NOT_INEQUALITY) FilterOperation operation) { Query query = new Query(A_KIND); query.setFilter(new Query.FilterPredicate(A_PROPERTY, operation.operator, operation.value)); datastoreHelper.preFilterGaeKinds(query); then(query.getFilter()).isInstanceOf(Query.CompositeFilter.class); }
@Test(expected = IllegalArgumentException.class) public void preFilterGaeKinds_withInequalityFilter_throwsIllegalArgumentException( @All(INEQUALITY) FilterOperation operation) throws Exception { Query query = new Query(A_KIND); query.setFilter(new Query.FilterPredicate(A_PROPERTY, operation.operator, operation.value)); datastoreHelper.preFilterGaeKinds(query); }