use of com.blazebit.persistence.PaginatedCriteriaBuilder in project blaze-persistence by Blazebit.
the class ExpressionCorrelationTest method testFilterSortJoinCorrelatedSingularBasicPaginated.
@Test
// @Category({ NoHibernate42.class, NoHibernate43.class, NoHibernate50.class, NoDatanucleus4.class, NoOpenJPA.class, NoEclipselink.class })
@Category({ NoHibernate42.class, NoHibernate43.class, NoHibernate50.class, NoDatanucleus.class, NoOpenJPA.class, NoEclipselink.class })
public void testFilterSortJoinCorrelatedSingularBasicPaginated() {
EntityViewManager evm = buildEntityViewManagerForFilter();
CriteriaBuilder<Document> criteria = cbf.create(em, Document.class, "d");
EntityViewSetting<DocumentSimpleCorrelationViewJoinId, PaginatedCriteriaBuilder<DocumentSimpleCorrelationViewJoinId>> setting;
setting = EntityViewSetting.create(DocumentSimpleCorrelationViewJoinId.class, 0, 1);
setting.addAttributeFilter("correlatedOwnerId", doc2.getOwner().getId());
setting.addAttributeSorter("correlatedOwnerId", Sorters.ascending());
setting.addAttributeSorter("id", Sorters.ascending());
PaginatedCriteriaBuilder<DocumentSimpleCorrelationViewJoinId> cb = evm.applySetting(setting, criteria);
PagedList<DocumentSimpleCorrelationViewJoinId> results = cb.getResultList();
assertEquals(1, results.size());
assertEquals(3, results.getTotalSize());
}
use of com.blazebit.persistence.PaginatedCriteriaBuilder in project blaze-persistence by Blazebit.
the class ExpressionCorrelationTest method testSubselectCorrelationIdPaginated.
@Test
// @Category({ NoHibernate42.class, NoHibernate43.class, NoHibernate50.class, NoDatanucleus4.class, NoOpenJPA.class, NoEclipselink.class })
@Category({ NoHibernate42.class, NoHibernate43.class, NoHibernate50.class, NoDatanucleus.class, NoOpenJPA.class, NoEclipselink.class })
public void testSubselectCorrelationIdPaginated() {
EntityViewManager evm = build(DocumentSimpleCorrelationViewSubselectId.class, SimpleDocumentCorrelatedView.class, SimplePersonCorrelatedSubView.class, SimpleVersionCorrelatedView.class);
CriteriaBuilder<Document> criteria = cbf.create(em, Document.class, "d");
EntityViewSetting<DocumentSimpleCorrelationViewSubselectId, PaginatedCriteriaBuilder<DocumentSimpleCorrelationViewSubselectId>> setting;
setting = EntityViewSetting.create(DocumentSimpleCorrelationViewSubselectId.class, 0, 1);
setting.addAttributeSorter("id", Sorters.ascending());
PaginatedCriteriaBuilder<DocumentSimpleCorrelationViewSubselectId> cb = evm.applySetting(setting, criteria);
PagedList<DocumentSimpleCorrelationViewSubselectId> results = cb.getResultList();
assertEquals(1, results.size());
assertEquals(4, results.getTotalSize());
}
use of com.blazebit.persistence.PaginatedCriteriaBuilder in project blaze-persistence by Blazebit.
the class ExpressionCorrelationTest method testFilterSortJoinCorrelatedPluralBasicPaginated.
@Test
// @Category({ NoHibernate42.class, NoHibernate43.class, NoHibernate50.class, NoDatanucleus4.class, NoOpenJPA.class, NoEclipselink.class })
@Category({ NoHibernate42.class, NoHibernate43.class, NoHibernate50.class, NoDatanucleus.class, NoOpenJPA.class, NoEclipselink.class })
public void testFilterSortJoinCorrelatedPluralBasicPaginated() {
EntityViewManager evm = buildEntityViewManagerForFilter();
CriteriaBuilder<Document> criteria = cbf.create(em, Document.class, "d");
EntityViewSetting<DocumentSimpleCorrelationViewJoinId, PaginatedCriteriaBuilder<DocumentSimpleCorrelationViewJoinId>> setting;
setting = EntityViewSetting.create(DocumentSimpleCorrelationViewJoinId.class, 0, 1);
setting.addAttributeFilter("correlatedOwnerIdList", doc2.getOwner().getId());
setting.addAttributeSorter("correlatedOwnerIdList", Sorters.ascending());
setting.addAttributeSorter("id", Sorters.ascending());
PaginatedCriteriaBuilder<DocumentSimpleCorrelationViewJoinId> cb = evm.applySetting(setting, criteria);
PagedList<DocumentSimpleCorrelationViewJoinId> results = cb.getResultList();
assertEquals(1, results.size());
assertEquals(3, results.getTotalSize());
}
use of com.blazebit.persistence.PaginatedCriteriaBuilder in project blaze-persistence by Blazebit.
the class ExpressionCorrelationTest method testFilterSortJoinCorrelatedPluralViewPaginated.
@Test
// @Category({ NoHibernate42.class, NoHibernate43.class, NoHibernate50.class, NoDatanucleus4.class, NoOpenJPA.class, NoEclipselink.class })
@Category({ NoHibernate42.class, NoHibernate43.class, NoHibernate50.class, NoDatanucleus.class, NoOpenJPA.class, NoEclipselink.class })
public void testFilterSortJoinCorrelatedPluralViewPaginated() {
EntityViewManager evm = buildEntityViewManagerForFilter();
CriteriaBuilder<Document> criteria = cbf.create(em, Document.class, "d");
EntityViewSetting<DocumentSimpleCorrelationViewJoinId, PaginatedCriteriaBuilder<DocumentSimpleCorrelationViewJoinId>> setting;
setting = EntityViewSetting.create(DocumentSimpleCorrelationViewJoinId.class, 0, 1);
setting.addAttributeFilter("correlatedOwnerViewList.name", "PERS2");
setting.addAttributeSorter("correlatedOwnerViewList.name", Sorters.ascending());
setting.addAttributeSorter("id", Sorters.ascending());
PaginatedCriteriaBuilder<DocumentSimpleCorrelationViewJoinId> cb = evm.applySetting(setting, criteria);
PagedList<DocumentSimpleCorrelationViewJoinId> results = cb.getResultList();
assertEquals(1, results.size());
assertEquals(3, results.getTotalSize());
}
use of com.blazebit.persistence.PaginatedCriteriaBuilder 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);
}
Aggregations