code: public <T> long getCount(final Class<T> cls) {
          final Query query = pm.newQuery(cls);
          //query.addExtension("datanucleus.query.resultSizeMethod", "count");
          query.setResult("count(id)");
          return (Long) query.execute();
      }
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 cls the persistence-capable class to query
  @return the number of items
  @param <T> candidate type for the query
  @since 1.0.0