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

  public  MetadataNodeEntityAdapter(final String typeName, final BucketEntityAdapter bucketEntityAdapter);

}