info.unterrainer.commons.httpserver.daos.AsyncListQueryBuilder Maven / Gradle / Ivy
package info.unterrainer.commons.httpserver.daos;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.TypedQuery;
import info.unterrainer.commons.rdbutils.entities.BasicAsyncJpa;
import info.unterrainer.commons.rdbutils.enums.AsyncState;
public class AsyncListQueryBuilder
extends BasicListQueryBuilder
> implements QueryInterface
{
private Set asyncStates = new HashSet<>();
AsyncListQueryBuilder(final EntityManagerFactory emf, final AsyncJpqlDao dao, final Class resultType) {
super(emf, dao, resultType);
}
@Override
public TypedQuery getTypedQuery(final EntityManager em) {
return dao.coreDao.getQuery(em, selectClause, joinClause, whereClause, parameters, resultType, orderByClause,
lockPessimistic, asyncStates, readTenantIds);
}
@Override
public jakarta.persistence.Query getCountQuery(final EntityManager em) {
return dao.coreDao.getCountQuery(em, selectClause, joinClause, whereClause, parameters, asyncStates,
readTenantIds);
}
public ListQuery build() {
return new ListQuery<>(emf, this);
}
/**
* Adds a single or multiple OR-clauses containing the specified
* {@link AsyncState}s.
*
* For example calling
* {@code .whereStateOf(AsyncState.NEW, AsyncState.PROCESSING)} will result in
* the where-clause
* {@code (..rest of where clause..) AND (state = 'NEW' OR state = 'PROCESSING').}
*
* Repetitive calling of this method just adds all the AsyncState values
* (doesn't clear the collection).
*
* @param asyncStates a single or number of AsyncState values
* @return an instance of this builder to provide a fluent interface
*/
public AsyncListQueryBuilder
asyncStateOf(final AsyncState... asyncStates) {
this.asyncStates.addAll(Arrays.asList(asyncStates));
return this;
}
}