Search in sources :

Example 1 with DocumentWithEntityView

use of com.blazebit.persistence.view.testsuite.basic.model.DocumentWithEntityView 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 2 with DocumentWithEntityView

use of com.blazebit.persistence.view.testsuite.basic.model.DocumentWithEntityView in project blaze-persistence by Blazebit.

the class EntityViewSettingTest method testEntityViewFetches.

@Test
public void testEntityViewFetches() {
    EntityViewManager evm = build(DocumentWithEntityView.class, PersonView.class);
    EntityViewSetting<DocumentWithEntityView, CriteriaBuilder<DocumentWithEntityView>> setting = EntityViewSetting.create(DocumentWithEntityView.class);
    setting.fetch("id");
    setting.fetch("name");
    DocumentWithEntityView view = evm.applySetting(setting, cbf.create(em, Document.class).where("name").eq("MyTest")).getSingleResult();
    assertEquals("MyTest", view.getName());
    assertNotNull(view.getId());
    assertNull(view.getOwner());
}
Also used : CriteriaBuilder(com.blazebit.persistence.CriteriaBuilder) PaginatedCriteriaBuilder(com.blazebit.persistence.PaginatedCriteriaBuilder) DocumentWithEntityView(com.blazebit.persistence.view.testsuite.basic.model.DocumentWithEntityView) EntityViewManager(com.blazebit.persistence.view.EntityViewManager) Test(org.junit.Test) AbstractEntityViewTest(com.blazebit.persistence.view.testsuite.AbstractEntityViewTest)

Example 3 with DocumentWithEntityView

use of com.blazebit.persistence.view.testsuite.basic.model.DocumentWithEntityView 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 4 with DocumentWithEntityView

use of com.blazebit.persistence.view.testsuite.basic.model.DocumentWithEntityView in project blaze-persistence by Blazebit.

the class EntityViewSettingTest method testEntityViewFetchesWithFilterAndSorter.

@Test
@Category({ NoMySQLOld.class, NoHibernate42.class, NoHibernate43.class, NoHibernate50.class, NoHibernate51.class, NoEclipselink.class, NoDatanucleus.class, NoOpenJPA.class })
public // OpenJPA has no function support
void testEntityViewFetchesWithFilterAndSorter() {
    EntityViewManager evm = build(DocumentWithEntityView.class, PersonView.class);
    EntityViewSetting<DocumentWithEntityView, CriteriaBuilder<DocumentWithEntityView>> setting = EntityViewSetting.create(DocumentWithEntityView.class);
    setting.fetch("id");
    setting.addAttributeSorter("name", Sorters.ascending());
    setting.addAttributeFilter("owner", false);
    setting.addAttributeSorter("firstContact.name", Sorters.ascending());
    setting.addAttributeSorter("contactCount", Sorters.ascending());
    List<DocumentWithEntityView> list = evm.applySetting(setting, cbf.create(em, Document.class)).getResultList();
    assertEquals(3, list.size());
    DocumentWithEntityView view = list.get(0);
    assertNotNull(view.getId());
    assertNull(view.getName());
    assertNull(view.getOwner());
    // We need to fetch it to provide sorting
    assertNotNull(view.getFirstContact());
    Document document = cbf.create(em, Document.class).where("name").eq("MyTest").getSingleResult();
    assertEquals(document.getId(), view.getId());
}
Also used : CriteriaBuilder(com.blazebit.persistence.CriteriaBuilder) PaginatedCriteriaBuilder(com.blazebit.persistence.PaginatedCriteriaBuilder) 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) Category(org.junit.experimental.categories.Category) Test(org.junit.Test) AbstractEntityViewTest(com.blazebit.persistence.view.testsuite.AbstractEntityViewTest)

Aggregations

PaginatedCriteriaBuilder (com.blazebit.persistence.PaginatedCriteriaBuilder)4 EntityViewManager (com.blazebit.persistence.view.EntityViewManager)4 AbstractEntityViewTest (com.blazebit.persistence.view.testsuite.AbstractEntityViewTest)4 DocumentWithEntityView (com.blazebit.persistence.view.testsuite.basic.model.DocumentWithEntityView)4 Test (org.junit.Test)4 Document (com.blazebit.persistence.testsuite.entity.Document)3 FilteredDocument (com.blazebit.persistence.view.testsuite.basic.model.FilteredDocument)3 CriteriaBuilder (com.blazebit.persistence.CriteriaBuilder)2 Category (org.junit.experimental.categories.Category)1