use of com.blazebit.persistence.deltaspike.data.KeysetPageable in project blaze-persistence by Blazebit.
the class AbstractEntityViewAwareRepositoryHandler method findAll.
@Override
public Page<V> findAll(Specification<E> specification, Pageable pageable) {
CriteriaBuilder<E> cb;
if (specification == null) {
cb = createCriteriaBuilder();
} else {
BlazeCriteriaBuilder blazeCriteriaBuilder = BlazeCriteria.get(criteriaBuilderFactory());
BlazeCriteriaQuery<?> query = blazeCriteriaBuilder.createQuery(entityClass());
Root queryRoot = query.from(entityClass());
Predicate predicate = specification.toPredicate(queryRoot, query, blazeCriteriaBuilder);
if (predicate != null) {
if (query.getRestriction() == null) {
query.where(predicate);
} else {
query.where(query.getRestriction(), predicate);
}
}
cb = (CriteriaBuilder<E>) query.createCriteriaBuilder(entityManager());
}
String[] fetches = getFetches();
if (fetches.length != 0) {
cb.fetch(fetches);
}
boolean withCountQuery = true;
boolean withKeysetExtraction = false;
boolean withExtractAllKeysets = false;
TypedQuery<V> query;
if (viewClass() == null) {
PaginatedCriteriaBuilder<V> pcb;
if (pageable instanceof KeysetPageable) {
KeysetPageable keysetPageable = (KeysetPageable) pageable;
pcb = (PaginatedCriteriaBuilder<V>) cb.page(keysetPageable.getKeysetPage(), pageable.getOffset(), pageable.getPageSize());
withCountQuery = keysetPageable.isWithCountQuery();
withKeysetExtraction = true;
withExtractAllKeysets = keysetPageable.isWithExtractAllKeysets();
} else {
pcb = (PaginatedCriteriaBuilder<V>) cb.page(pageable.getOffset(), pageable.getPageSize());
}
QueryBuilderUtils.applySort(pageable.getSort(), pcb);
pcb.withCountQuery(withCountQuery);
pcb.withKeysetExtraction(withKeysetExtraction);
pcb.withExtractAllKeysets(withExtractAllKeysets);
query = pcb.getQuery();
} else {
EntityViewSetting<V, PaginatedCriteriaBuilder<V>> setting = EntityViewSetting.create(viewClass(), pageable.getOffset(), pageable.getPageSize());
if (pageable instanceof KeysetPageable) {
KeysetPageable keysetPageable = (KeysetPageable) pageable;
setting.withKeysetPage(keysetPageable.getKeysetPage());
withCountQuery = keysetPageable.isWithCountQuery();
withKeysetExtraction = true;
withExtractAllKeysets = keysetPageable.isWithExtractAllKeysets();
}
QueryBuilderUtils.applySort(pageable.getSort(), setting);
PaginatedCriteriaBuilder<V> pcb = applySetting(setting, cb);
pcb.withCountQuery(withCountQuery);
pcb.withKeysetExtraction(withKeysetExtraction);
pcb.withExtractAllKeysets(withExtractAllKeysets);
query = pcb.getQuery();
}
applyQueryHints(query, fetches.length == 0);
PagedList<V> resultList = (PagedList<V>) query.getResultList();
return new KeysetAwarePageImpl<>(resultList, pageable);
}
use of com.blazebit.persistence.deltaspike.data.KeysetPageable in project blaze-persistence by Blazebit.
the class FullEntityViewRepositoryTest method testFindByNameKeysetPaginated.
@Test
@Category(NoH2.class)
public void testFindByNameKeysetPaginated() {
// we do not test DeltaSpike's findAll(int, int) method here because its results are non-deterministic
Page<PersonView> actual = personViewRepository.findByNameLike("John %", new KeysetPageRequest(null, new PageRequest(0, 1, Sort.Direction.ASC, "id")));
assertTrue(actual instanceof KeysetAwarePage<?>);
assertEquals(1, actual.getNumberOfElements());
assertEquals("John Doe", actual.getContent().get(0).getName());
actual = personViewRepository.findByNameLike("John %", (KeysetPageable) actual.nextPageable());
assertEquals(1, actual.getNumberOfElements());
assertEquals("John Smith", actual.getContent().get(0).getName());
}
use of com.blazebit.persistence.deltaspike.data.KeysetPageable in project blaze-persistence by Blazebit.
the class FullEntityViewRepositoryTest method testFindByNameKeysetPaginatedEntity.
@Test
public void testFindByNameKeysetPaginatedEntity() {
// we do not test DeltaSpike's findAll(int, int) method here because its results are non-deterministic
Page<Person> actual = personRepository.findByNameLike("John %", new KeysetPageRequest(null, new PageRequest(0, 1, Sort.Direction.ASC, "id")));
assertTrue(actual instanceof KeysetAwarePage<?>);
assertEquals(1, actual.getNumberOfElements());
assertEquals("John Doe", actual.getContent().get(0).getName());
actual = personRepository.findByNameLike("John %", (KeysetPageable) actual.nextPageable());
assertEquals(1, actual.getNumberOfElements());
assertEquals("John Smith", actual.getContent().get(0).getName());
}
Aggregations