use of com.blazebit.persistence.view.EntityViewManager in project blaze-persistence by Blazebit.
the class SubviewClassCollectionsTest method testCollections.
@Test
public void testCollections() {
EntityViewManager evm = build(SubviewClassDocumentForCollectionsView.class, SubviewPersonForCollectionsView.class);
CriteriaBuilder<DocumentForCollections> criteria = cbf.create(em, DocumentForCollections.class, "d").orderByAsc("id");
CriteriaBuilder<SubviewClassDocumentForCollectionsView> cb = evm.applySetting(EntityViewSetting.create(SubviewClassDocumentForCollectionsView.class, viewConstructorName), criteria);
List<SubviewClassDocumentForCollectionsView> results = cb.getResultList();
assertEquals(2, results.size());
// Doc1
assertEquals(doc1.getName(), results.get(0).getName());
assertSubviewEquals(doc1.getContacts(), results.get(0).getContacts());
assertSubviewEquals(doc1.getPartners(), results.get(0).getPartners());
assertSubviewEquals(doc1.getPersonList(), results.get(0).getPersonList());
// Doc2
assertEquals(doc2.getName(), results.get(1).getName());
assertSubviewEquals(doc2.getContacts(), results.get(1).getContacts());
assertSubviewEquals(doc2.getPartners(), results.get(1).getPartners());
assertSubviewEquals(doc2.getPersonList(), results.get(1).getPersonList());
}
use of com.blazebit.persistence.view.EntityViewManager in project blaze-persistence by Blazebit.
the class SubselectSubsetCorrelationTest method testSubselectSubsetCorrelation.
@Test
public void testSubselectSubsetCorrelation() {
EntityViewManager evm = build(PersonSubselectView.class, SimplePersonSubView.class);
CriteriaBuilder<Person> criteria = cbf.create(em, Person.class, "p").orderByDesc("name").orderByDesc("id").setMaxResults(2);
EntityViewSetting<PersonSubselectView, CriteriaBuilder<PersonSubselectView>> setting = EntityViewSetting.create(PersonSubselectView.class);
CriteriaBuilder<PersonSubselectView> cb = evm.applySetting(setting, criteria);
cb.getResultList();
}
use of com.blazebit.persistence.view.EntityViewManager in project blaze-persistence by Blazebit.
the class ArrayFilteredCollectionsTest method testArrayExpression.
// NOTE: DB2 crashes when executing this test with the GROUP_CONCAT based implementation
// NOTE: EclipseLink cant' handle multiple subquery select items... Only one expression can be declared in a SELECT clause of a subquery
// NOTE: DataNucleus cant' handle multiple subquery select items... Number of result expressions in subquery should be 1
// NOTE: Entity joins are only supported on Hibernate 5.1+
@Test
@Category({ NoDB2.class, NoDatanucleus.class, NoEclipselink.class, NoHibernate42.class, NoHibernate43.class, NoHibernate50.class })
public void testArrayExpression() {
EntityViewConfiguration cfg = EntityViews.createDefaultConfiguration();
cfg.setProperty(ConfigurationProperties.PROXY_EAGER_LOADING, "true");
cfg.setProperty(ConfigurationProperties.UPDATER_EAGER_LOADING, "true");
EntityViewManager evm = build(cfg, SubviewDocumentCollectionsView.class, SubviewPersonForCollectionsView.class);
CriteriaBuilder<DocumentForCollections> criteria = cbf.create(em, DocumentForCollections.class, "d").orderByAsc("id");
CriteriaBuilder<SubviewDocumentCollectionsView> cb = evm.applySetting(EntityViewSetting.create(SubviewDocumentCollectionsView.class), criteria);
List<SubviewDocumentCollectionsView> results = cb.getResultList();
assertEquals(2, results.size());
// Doc1
assertEquals(doc1.getName(), results.get(0).getName());
assertSubviewEquals(doc1.getContacts(), results.get(0).getContacts());
assertSubviewEquals(doc1.getPartners(), results.get(0).getPartners());
assertSubviewEquals(doc1.getPersonList(), results.get(0).getPersonList());
// Doc2
assertEquals(doc2.getName(), results.get(1).getName());
assertSubviewEquals(doc2.getContacts(), results.get(1).getContacts());
assertSubviewEquals(doc2.getPartners(), results.get(1).getPartners());
assertSubviewEquals(doc2.getPersonList(), results.get(1).getPersonList());
}
use of com.blazebit.persistence.view.EntityViewManager in project blaze-persistence by Blazebit.
the class EntityViewJsonbDeserializerTest method testCreatableWithCollection.
@Test
public void testCreatableWithCollection() throws Exception {
EntityViewManager evm = evm(CreatableWithCollection.class, CreatableAndUpdatableViewWithSetters.class, NameView.class);
Jsonb mapper = mapper(evm);
CreatableWithCollection view = mapper.fromJson("{\"name\": \"test\", \"children\": [{\"name\": \"parent\"}]}", CreatableWithCollection.class);
Assert.assertTrue(((EntityViewProxy) view).$$_isNew());
assertEquals("test", view.getName());
assertEquals(evm.getChangeModel(view).get("children").getInitialState(), view.getChildren());
assertEquals(1, view.getChildren().size());
}
use of com.blazebit.persistence.view.EntityViewManager in project blaze-persistence by Blazebit.
the class EntityViewJsonbDeserializerTest method testCreatableWithCollectionWithSetter.
@Test
public void testCreatableWithCollectionWithSetter() throws Exception {
EntityViewManager evm = evm(CreatableWithCollectionWithSetter.class, CreatableAndUpdatableViewWithSetters.class, NameView.class);
Jsonb mapper = mapper(evm);
CreatableWithCollectionWithSetter view = mapper.fromJson("{\"name\": \"test\", \"children\": [{\"name\": \"parent\"}]}", CreatableWithCollectionWithSetter.class);
Assert.assertTrue(((EntityViewProxy) view).$$_isNew());
assertEquals("test", view.getName());
assertEquals(evm.getChangeModel(view).get("children").getInitialState(), view.getChildren());
assertEquals(1, view.getChildren().size());
}
Aggregations