Search in sources :

Example 11 with PaginatedCriteriaBuilder

use of com.blazebit.persistence.PaginatedCriteriaBuilder in project blaze-persistence by Blazebit.

the class SubviewEntityViewSettingTest method testEntityViewSettingFilterSubview.

@Test
@Category({ NoEclipselink.class })
public // Eclipselink has a result set mapping bug in case of map keys
void testEntityViewSettingFilterSubview() {
    EntityViewManager evm = build(DocumentMasterView.class, SimpleDocumentView.class, PersonSubView.class, PersonSubViewFiltered.class);
    // Base setting
    EntityViewSetting<DocumentMasterView, PaginatedCriteriaBuilder<DocumentMasterView>> setting = EntityViewSetting.create(DocumentMasterView.class, 0, 1);
    // Query
    CriteriaBuilder<Document> cb = cbf.create(em, Document.class);
    setting.addAttributeFilter("owner.name", "OWNER");
    setting.addAttributeSorter("owner.name", Sorters.descending());
    setting.addAttributeSorter("id", Sorters.descending());
    setting.addOptionalParameter("contactPersonNumber", 1);
    PaginatedCriteriaBuilder<DocumentMasterView> paginatedCb = evm.applySetting(setting, cb);
    PagedList<DocumentMasterView> result = paginatedCb.getResultList();
    assertEquals(1, result.size());
    assertEquals(2, result.getTotalSize());
    assertEquals("HisTest", result.get(0).getName());
    assertEquals("DocumentOwnerSlave".toUpperCase(), result.get(0).getOwner().getName());
}
Also used : EntityViewManager(com.blazebit.persistence.view.EntityViewManager) DocumentMasterView(com.blazebit.persistence.view.testsuite.subview.model.DocumentMasterView) Document(com.blazebit.persistence.testsuite.entity.Document) PaginatedCriteriaBuilder(com.blazebit.persistence.PaginatedCriteriaBuilder) Category(org.junit.experimental.categories.Category) Test(org.junit.Test) AbstractEntityViewTest(com.blazebit.persistence.view.testsuite.AbstractEntityViewTest)

Example 12 with PaginatedCriteriaBuilder

use of com.blazebit.persistence.PaginatedCriteriaBuilder in project blaze-persistence by Blazebit.

the class MappingSubqueryTest method testSubqueryEntityViewSettings.

@Test
public void testSubqueryEntityViewSettings() {
    EntityViewManager evm = build(DocumentWithSubquery.class);
    CriteriaBuilder<Document> cb = cbf.create(em, Document.class).orderByDesc("id");
    EntityViewSetting<DocumentWithSubquery, PaginatedCriteriaBuilder<DocumentWithSubquery>> setting = EntityViewSetting.create(DocumentWithSubquery.class, 0, 1);
    setting.addOptionalParameter("optionalParameter", 1);
    setting.addAttributeFilter("contactCount", "0");
    PagedList<DocumentWithSubquery> list = evm.applySetting(setting, cb).getResultList();
    assertEquals(1, list.size());
    assertEquals(2, list.getTotalSize());
    assertEquals("doc2", list.get(0).getName());
    assertEquals(Long.valueOf(2), list.get(0).getContactCount());
}
Also used : EntityViewManager(com.blazebit.persistence.view.EntityViewManager) Document(com.blazebit.persistence.testsuite.entity.Document) DocumentWithSubquery(com.blazebit.persistence.view.testsuite.subquery.model.DocumentWithSubquery) PaginatedCriteriaBuilder(com.blazebit.persistence.PaginatedCriteriaBuilder) Test(org.junit.Test) AbstractEntityViewTest(com.blazebit.persistence.view.testsuite.AbstractEntityViewTest)

Example 13 with PaginatedCriteriaBuilder

use of com.blazebit.persistence.PaginatedCriteriaBuilder in project blaze-persistence by Blazebit.

the class EntityViewSettingTest method testEntityViewSettingWithEntityAttribute.

@Test
public void testEntityViewSettingWithEntityAttribute() {
    EntityViewManager evm = build(DocumentWithEntityView.class, PersonView.class);
    // Base setting
    EntityViewSetting<DocumentWithEntityView, PaginatedCriteriaBuilder<DocumentWithEntityView>> setting = EntityViewSetting.create(DocumentWithEntityView.class, 0, 1);
    // Query
    CriteriaBuilder<Document> cb = cbf.create(em, Document.class);
    setting.addAttributeFilter("owner.name", "pers2");
    // Currently we have no way to express what filter should be used when using entity attributes
    try {
        evm.applySetting(setting, cb);
        Assert.fail("Expected IllegalArgumentException");
    } catch (IllegalArgumentException ex) {
    // Ok
    }
}
Also used : DocumentWithEntityView(com.blazebit.persistence.view.testsuite.basic.model.DocumentWithEntityView) EntityViewManager(com.blazebit.persistence.view.EntityViewManager) Document(com.blazebit.persistence.testsuite.entity.Document) FilteredDocument(com.blazebit.persistence.view.testsuite.basic.model.FilteredDocument) PaginatedCriteriaBuilder(com.blazebit.persistence.PaginatedCriteriaBuilder) Test(org.junit.Test) AbstractEntityViewTest(com.blazebit.persistence.view.testsuite.AbstractEntityViewTest)

Example 14 with PaginatedCriteriaBuilder

use of com.blazebit.persistence.PaginatedCriteriaBuilder in project blaze-persistence by Blazebit.

the class EntityViewSettingTest method testEntityViewSettingNotExistingFilterAttribute.

@Test
public void testEntityViewSettingNotExistingFilterAttribute() {
    EntityViewManager evm = build(DocumentWithEntityView.class, PersonView.class);
    // Base setting
    EntityViewSetting<DocumentWithEntityView, PaginatedCriteriaBuilder<DocumentWithEntityView>> setting = EntityViewSetting.create(DocumentWithEntityView.class, 0, 1);
    // Query
    CriteriaBuilder<Document> cb = cbf.create(em, Document.class);
    setting.addAttributeFilter("asd", "test");
    // Currently we have no way to express what filter should be used when using entity attributes
    try {
        evm.applySetting(setting, cb);
        Assert.fail("Expected IllegalArgumentException");
    } catch (IllegalArgumentException ex) {
    // Ok
    }
}
Also used : DocumentWithEntityView(com.blazebit.persistence.view.testsuite.basic.model.DocumentWithEntityView) EntityViewManager(com.blazebit.persistence.view.EntityViewManager) Document(com.blazebit.persistence.testsuite.entity.Document) FilteredDocument(com.blazebit.persistence.view.testsuite.basic.model.FilteredDocument) PaginatedCriteriaBuilder(com.blazebit.persistence.PaginatedCriteriaBuilder) Test(org.junit.Test) AbstractEntityViewTest(com.blazebit.persistence.view.testsuite.AbstractEntityViewTest)

Example 15 with PaginatedCriteriaBuilder

use of com.blazebit.persistence.PaginatedCriteriaBuilder in project blaze-persistence by Blazebit.

the class EntityViewSettingTest method testEntityViewSetting.

@Test
public void testEntityViewSetting() {
    EntityViewManager evm = build(FilteredDocument.class);
    // Base setting
    EntityViewSetting<FilteredDocument, PaginatedCriteriaBuilder<FilteredDocument>> setting = EntityViewSetting.create(FilteredDocument.class, 0, 1);
    // Query
    CriteriaBuilder<Document> cb = cbf.create(em, Document.class);
    setting.addAttributeFilter("name", "Test");
    setting.addAttributeFilter("contactCount", "1");
    setting.addAttributeSorter("name", Sorters.descending());
    setting.addAttributeSorter("id", Sorters.descending());
    setting.addOptionalParameter("index", 1);
    PaginatedCriteriaBuilder<FilteredDocument> paginatedCb = evm.applySetting(setting, cb);
    PagedList<FilteredDocument> result = paginatedCb.getResultList();
    assertEquals(1, result.size());
    assertEquals(2, result.getTotalSize());
    assertEquals("YourTest", result.get(0).getName());
    assertEquals("pers2", result.get(0).getContactName());
}
Also used : EntityViewManager(com.blazebit.persistence.view.EntityViewManager) FilteredDocument(com.blazebit.persistence.view.testsuite.basic.model.FilteredDocument) Document(com.blazebit.persistence.testsuite.entity.Document) FilteredDocument(com.blazebit.persistence.view.testsuite.basic.model.FilteredDocument) PaginatedCriteriaBuilder(com.blazebit.persistence.PaginatedCriteriaBuilder) Test(org.junit.Test) AbstractEntityViewTest(com.blazebit.persistence.view.testsuite.AbstractEntityViewTest)

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