MetadataNodeEntityAdapter extends IterableEntityAdapter<T> { long countGroupByQuery(final ODatabaseDocumentTx db, @Nullable final String whereClause, @Nullable final Map<String, Object> parameters, @Nullable final Iterable<Bucket> buckets, final String querySuffix) { checkNotNull(querySuffix); checkState(containsIgnoreCase(querySuffix, "group by")); String query = buildQuery(true, whereClause, buckets, querySuffix); if (isBlank(query)) { log.debug("Skipped counting {}s as query is empty, parameters: {}", getTypeName(), parameters); return 0; } query = "select count(*) from (" + buildQuery(true, whereClause, buckets, querySuffix) + ")"; log.debug("Counting {}s with grouped by query: {}, parameters: {}", getTypeName(), query, parameters); List<ODocument> results = db.command(new OCommandSQL(query)).execute(parameters); return results.get(0).field("count"); } MetadataNodeEntityAdapter(final String typeName, final BucketEntityAdapter bucketEntityAdapter);  static final String P_ATTRIBUTES; static final String P_BUCKET; static final String P_FORMAT; static final String P_NAME; }
@Test public void emptyBucketsCountGroupByQuery() throws Exception { buckets.clear(); try (ODatabaseDocumentTx db = database.getInstance().connect()) { assertThat(underTest.countGroupByQuery(db, null, null, buckets, "group by name"), is(0L)); } }