Search in sources :

Example 66 with EntityViewManager

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());
}
Also used : EntityViewManager(com.blazebit.persistence.view.EntityViewManager) DocumentForCollections(com.blazebit.persistence.view.testsuite.collections.entity.simple.DocumentForCollections) SubviewClassDocumentForCollectionsView(com.blazebit.persistence.view.testsuite.collections.subview.model.SubviewClassDocumentForCollectionsView) Test(org.junit.Test) AbstractEntityViewTest(com.blazebit.persistence.view.testsuite.AbstractEntityViewTest)

Example 67 with EntityViewManager

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();
}
Also used : CriteriaBuilder(com.blazebit.persistence.CriteriaBuilder) PersonSubselectView(com.blazebit.persistence.view.testsuite.correlation.subselectsubset.model.PersonSubselectView) EntityViewManager(com.blazebit.persistence.view.EntityViewManager) Person(com.blazebit.persistence.testsuite.entity.Person) Test(org.junit.Test) AbstractCorrelationTest(com.blazebit.persistence.view.testsuite.correlation.AbstractCorrelationTest)

Example 68 with EntityViewManager

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());
}
Also used : EntityViewConfiguration(com.blazebit.persistence.view.spi.EntityViewConfiguration) EntityViewManager(com.blazebit.persistence.view.EntityViewManager) DocumentForCollections(com.blazebit.persistence.view.testsuite.collections.entity.simple.DocumentForCollections) SubviewDocumentCollectionsView(com.blazebit.persistence.view.testsuite.array.model.SubviewDocumentCollectionsView) Category(org.junit.experimental.categories.Category) Test(org.junit.Test) AbstractEntityViewTest(com.blazebit.persistence.view.testsuite.AbstractEntityViewTest)

Example 69 with EntityViewManager

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());
}
Also used : Jsonb(javax.json.bind.Jsonb) EntityViewManager(com.blazebit.persistence.view.EntityViewManager) Test(org.junit.Test)

Example 70 with EntityViewManager

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());
}
Also used : Jsonb(javax.json.bind.Jsonb) EntityViewManager(com.blazebit.persistence.view.EntityViewManager) Test(org.junit.Test)

Aggregations

EntityViewManager (com.blazebit.persistence.view.EntityViewManager)70 Test (org.junit.Test)61 AbstractEntityViewTest (com.blazebit.persistence.view.testsuite.AbstractEntityViewTest)51 Document (com.blazebit.persistence.testsuite.entity.Document)31 CriteriaBuilder (com.blazebit.persistence.CriteriaBuilder)25 Category (org.junit.experimental.categories.Category)25 PaginatedCriteriaBuilder (com.blazebit.persistence.PaginatedCriteriaBuilder)19 AbstractCorrelationTest (com.blazebit.persistence.view.testsuite.correlation.AbstractCorrelationTest)7 DocumentForCollections (com.blazebit.persistence.view.testsuite.collections.entity.simple.DocumentForCollections)6 FilteredDocument (com.blazebit.persistence.view.testsuite.basic.model.FilteredDocument)5 Person (com.blazebit.persistence.testsuite.entity.Person)4 DocumentWithEntityView (com.blazebit.persistence.view.testsuite.basic.model.DocumentWithEntityView)4 PersonForCollections (com.blazebit.persistence.view.testsuite.collections.entity.simple.PersonForCollections)4 DocumentSimpleCorrelationViewJoinId (com.blazebit.persistence.view.testsuite.correlation.expression.model.DocumentSimpleCorrelationViewJoinId)4 DocumentMasterView (com.blazebit.persistence.view.testsuite.subview.model.DocumentMasterView)4 EntityViewConfiguration (com.blazebit.persistence.view.spi.EntityViewConfiguration)3 PrimitiveDocument (com.blazebit.persistence.testsuite.entity.PrimitiveDocument)2 PersonWithPartnerDocument (com.blazebit.persistence.view.testsuite.cte.model.PersonWithPartnerDocument)2 HashSet (java.util.HashSet)2 Jsonb (javax.json.bind.Jsonb)2