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());
}
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());
}
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
}
}
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
}
}
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());
}
Aggregations