Search in sources :

Example 6 with PaginatedCriteriaBuilder

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());
}
Also used : EntityViewManager(com.blazebit.persistence.view.EntityViewManager) DocumentSimpleCorrelationViewJoinId(com.blazebit.persistence.view.testsuite.correlation.expression.model.DocumentSimpleCorrelationViewJoinId) Document(com.blazebit.persistence.testsuite.entity.Document) PaginatedCriteriaBuilder(com.blazebit.persistence.PaginatedCriteriaBuilder) Category(org.junit.experimental.categories.Category) Test(org.junit.Test) AbstractCorrelationTest(com.blazebit.persistence.view.testsuite.correlation.AbstractCorrelationTest)

Example 7 with PaginatedCriteriaBuilder

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());
}
Also used : EntityViewManager(com.blazebit.persistence.view.EntityViewManager) DocumentSimpleCorrelationViewSubselectId(com.blazebit.persistence.view.testsuite.correlation.expression.model.DocumentSimpleCorrelationViewSubselectId) Document(com.blazebit.persistence.testsuite.entity.Document) PaginatedCriteriaBuilder(com.blazebit.persistence.PaginatedCriteriaBuilder) Category(org.junit.experimental.categories.Category) Test(org.junit.Test) AbstractCorrelationTest(com.blazebit.persistence.view.testsuite.correlation.AbstractCorrelationTest)

Example 8 with PaginatedCriteriaBuilder

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());
}
Also used : EntityViewManager(com.blazebit.persistence.view.EntityViewManager) DocumentSimpleCorrelationViewJoinId(com.blazebit.persistence.view.testsuite.correlation.expression.model.DocumentSimpleCorrelationViewJoinId) Document(com.blazebit.persistence.testsuite.entity.Document) PaginatedCriteriaBuilder(com.blazebit.persistence.PaginatedCriteriaBuilder) Category(org.junit.experimental.categories.Category) Test(org.junit.Test) AbstractCorrelationTest(com.blazebit.persistence.view.testsuite.correlation.AbstractCorrelationTest)

Example 9 with PaginatedCriteriaBuilder

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());
}
Also used : EntityViewManager(com.blazebit.persistence.view.EntityViewManager) DocumentSimpleCorrelationViewJoinId(com.blazebit.persistence.view.testsuite.correlation.expression.model.DocumentSimpleCorrelationViewJoinId) Document(com.blazebit.persistence.testsuite.entity.Document) PaginatedCriteriaBuilder(com.blazebit.persistence.PaginatedCriteriaBuilder) Category(org.junit.experimental.categories.Category) Test(org.junit.Test) AbstractCorrelationTest(com.blazebit.persistence.view.testsuite.correlation.AbstractCorrelationTest)

Example 10 with PaginatedCriteriaBuilder

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);
}
Also used : Root(javax.persistence.criteria.Root) PagedList(com.blazebit.persistence.PagedList) BlazeCriteriaBuilder(com.blazebit.persistence.criteria.BlazeCriteriaBuilder) PaginatedCriteriaBuilder(com.blazebit.persistence.PaginatedCriteriaBuilder) Predicate(javax.persistence.criteria.Predicate) KeysetPageable(com.blazebit.persistence.deltaspike.data.KeysetPageable)

Aggregations

PaginatedCriteriaBuilder (com.blazebit.persistence.PaginatedCriteriaBuilder)16 Document (com.blazebit.persistence.testsuite.entity.Document)12 EntityViewManager (com.blazebit.persistence.view.EntityViewManager)12 Test (org.junit.Test)12 Category (org.junit.experimental.categories.Category)8 AbstractEntityViewTest (com.blazebit.persistence.view.testsuite.AbstractEntityViewTest)7 AbstractCorrelationTest (com.blazebit.persistence.view.testsuite.correlation.AbstractCorrelationTest)5 DocumentSimpleCorrelationViewJoinId (com.blazebit.persistence.view.testsuite.correlation.expression.model.DocumentSimpleCorrelationViewJoinId)4 FilteredDocument (com.blazebit.persistence.view.testsuite.basic.model.FilteredDocument)3 CriteriaBuilder (com.blazebit.persistence.CriteriaBuilder)2 BlazeCriteriaBuilder (com.blazebit.persistence.criteria.BlazeCriteriaBuilder)2 DocumentWithEntityView (com.blazebit.persistence.view.testsuite.basic.model.DocumentWithEntityView)2 DocumentMasterView (com.blazebit.persistence.view.testsuite.subview.model.DocumentMasterView)2 LimitBuilder (com.blazebit.persistence.LimitBuilder)1 ObjectBuilder (com.blazebit.persistence.ObjectBuilder)1 PagedList (com.blazebit.persistence.PagedList)1 KeysetPageable (com.blazebit.persistence.deltaspike.data.KeysetPageable)1 BasicCatView (com.blazebit.persistence.examples.showcase.fragments.cte.view.BasicCatView)1 ExpressionFactory (com.blazebit.persistence.parser.expression.ExpressionFactory)1 JpaProvider (com.blazebit.persistence.spi.JpaProvider)1