code: static <E extends Entity> String getSqlCount(
        EntityType entityType, Query<E> q, List<Object> parameters) {
      StringBuilder sqlBuilder = new StringBuilder("SELECT COUNT");
      String idAttribute = getColumnName(entityType.getIdAttribute());
  
      List<QueryRule> queryRules = q.getRules();
      if (queryRules == null || queryRules.isEmpty()) {
        sqlBuilder.append("(*) FROM ").append(getTableName(entityType));
      } else {
        boolean distinctSelectRequired = isDistinctSelectRequired(entityType, q);
        if (distinctSelectRequired) {
          // distinct count in case query contains one or more rules referring to MREF attributes.
          sqlBuilder.append("(DISTINCT this.").append(idAttribute).append(')');
        } else {
          sqlBuilder.append("(*)");
        }
  
        String from = getSqlFrom(entityType, q);
        String where = getSqlWhere(entityType, q, parameters, new AtomicInteger());
        sqlBuilder.append(from).append(" WHERE ").append(where);
      }
      return sqlBuilder.toString();
    }
docs: Produces SQL to count the number of entities that match the given query. Ignores query offset
  and pagesize.
  
  @param q query
  @param parameters prepared statement parameters
  @return SQL string