code: public long getCount(final Query query) {
          //query.addExtension("datanucleus.query.resultSizeMethod", "count");
          final String ordering = ((JDOQuery) query).getInternalQuery().getOrdering();
          query.setResult("count(id)");
          query.setOrdering(null);
          final long count = (Long) query.execute();
          query.setOrdering(ordering);
          return count;
      }
docs: Returns the number of items that would have resulted from returning all object.
  This method is performant in that the objects are not actually retrieved, only
  the count.
  @param query the query to return a count from
  @return the number of items
  @since 1.0.0