class 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);
        }
    }

}