@Override
    public long countTicketsFor(final Service service) {
        return transactionTemplate.execute(status -> {
            val factory = getJpaTicketEntityFactory();
            val sql = String.format("SELECT COUNT(t.id) FROM %s t WHERE t.service = :service", factory.getEntityName());
            val query = entityManager.createQuery(sql).setParameter("service", service.getId());
            return countToLong(query.getSingleResult());
        });
    }
This method purposefully doesn't lock any rows, because the stream traversing can take an indeterminate
amount of time, and logging in to an application with an existing TGT will update the TGT row in the database.

@return streamable results
support/cas-server-support-jpa-ticket-registry/src/main/java/org/apereo/cas/ticket/registry/JpaTicketRegistry.java