info.unterrainer.commons.httpserver.daos.CountQueryBuilder Maven / Gradle / Ivy
package info.unterrainer.commons.httpserver.daos;
import jakarta.persistence.EntityManagerFactory;
import info.unterrainer.commons.rdbutils.Transactions;
import info.unterrainer.commons.rdbutils.entities.BasicJpa;
public class CountQueryBuilder extends BasicListQueryBuilder
> {
CountQueryBuilder(final EntityManagerFactory emf, final JpqlDao
dao) {
super(emf, dao, Long.class);
}
public Long build() {
if (entityManager != null)
return (Long) dao.coreDao
.getCountQuery(entityManager, selectClause, joinClause, whereClause, parameters, null,
readTenantIds)
.getSingleResult();
return (Long) Transactions.withNewTransactionReturning(emf,
em -> dao.coreDao
.getCountQuery(em, selectClause, joinClause, whereClause, parameters, null, readTenantIds)
.getSingleResult());
}
}