Search in sources :

Example 1 with PersonForCollections

use of com.blazebit.persistence.view.testsuite.collections.entity.simple.PersonForCollections in project blaze-persistence by Blazebit.

the class ArrayFilteredCollectionsTest method setUpOnce.

@Override
public void setUpOnce() {
    cleanDatabase();
    transactional(new TxVoidWork() {

        @Override
        public void work(EntityManager em) {
            doc1 = new DocumentForCollections("doc1");
            doc2 = new DocumentForCollections("doc2");
            PersonForCollections o1 = new PersonForCollections("pers1");
            PersonForCollections o2 = new PersonForCollections("pers2");
            PersonForCollections o3 = new PersonForCollections("pers3");
            PersonForCollections o4 = new PersonForCollections("pers4");
            o1.setPartnerDocument(doc1);
            o2.setPartnerDocument(doc2);
            o3.setPartnerDocument(doc1);
            o4.setPartnerDocument(doc2);
            doc1.setOwner(o1);
            doc2.setOwner(o2);
            doc1.getContacts().put(1, o1);
            doc2.getContacts().put(1, o2);
            doc1.getContacts().put(2, o3);
            doc2.getContacts().put(2, o4);
            em.persist(o1);
            em.persist(o2);
            em.persist(o3);
            em.persist(o4);
            doc1.getPartners().add(o1);
            doc1.getPartners().add(o3);
            doc2.getPartners().add(o2);
            doc2.getPartners().add(o4);
            doc1.getPersonList().add(o1);
            doc1.getPersonList().add(o2);
            doc2.getPersonList().add(o3);
            doc2.getPersonList().add(o4);
            em.persist(doc1);
            em.persist(doc2);
        }
    });
}
Also used : EntityManager(javax.persistence.EntityManager) PersonForCollections(com.blazebit.persistence.view.testsuite.collections.entity.simple.PersonForCollections) TxVoidWork(com.blazebit.persistence.testsuite.tx.TxVoidWork) DocumentForCollections(com.blazebit.persistence.view.testsuite.collections.entity.simple.DocumentForCollections)

Example 2 with PersonForCollections

use of com.blazebit.persistence.view.testsuite.collections.entity.simple.PersonForCollections in project blaze-persistence by Blazebit.

the class ViewSetAsListTest method assertSubviewPersonCollectionEquals.

private void assertSubviewPersonCollectionEquals(Set<PersonForCollections> partnerPersons, List<? extends PersonForCollectionsView> persons) {
    assertEquals(partnerPersons.size(), persons.size());
    PersonForCollections[] sortedPersons = sortedByPersonName(partnerPersons);
    for (int i = 0; i < sortedPersons.length; i++) {
        PersonForCollections pers = sortedPersons[i];
        if (!pers.getName().equals(persons.get(i).getName())) {
            Assert.fail("Could not find a PersonForCollectionsView with the name: " + pers.getName());
        }
    }
}
Also used : PersonForCollections(com.blazebit.persistence.view.testsuite.collections.entity.simple.PersonForCollections)

Example 3 with PersonForCollections

use of com.blazebit.persistence.view.testsuite.collections.entity.simple.PersonForCollections in project blaze-persistence by Blazebit.

the class BasicCollectionsTest method setUpOnce.

@Override
public void setUpOnce() {
    cleanDatabase();
    transactional(new TxVoidWork() {

        @Override
        public void work(EntityManager em) {
            doc1 = new DocumentForCollections("doc1");
            doc2 = new DocumentForCollections("doc2");
            PersonForCollections o1 = new PersonForCollections("pers1");
            PersonForCollections o2 = new PersonForCollections("pers2");
            PersonForCollections o3 = new PersonForCollections("pers3");
            PersonForCollections o4 = new PersonForCollections("pers4");
            o1.setPartnerDocument(doc1);
            o2.setPartnerDocument(doc2);
            o3.setPartnerDocument(doc1);
            o4.setPartnerDocument(doc2);
            doc1.setOwner(o1);
            doc2.setOwner(o2);
            doc1.getContacts().put(1, o1);
            doc2.getContacts().put(1, o2);
            doc1.getContacts().put(2, o3);
            doc2.getContacts().put(2, o4);
            em.persist(o1);
            em.persist(o2);
            em.persist(o3);
            em.persist(o4);
            doc1.getPartners().add(o1);
            doc1.getPartners().add(o3);
            doc2.getPartners().add(o2);
            doc2.getPartners().add(o4);
            doc1.getPersonList().add(o1);
            doc1.getPersonList().add(o2);
            doc2.getPersonList().add(o3);
            doc2.getPersonList().add(o4);
            em.persist(doc1);
            em.persist(doc2);
        }
    });
}
Also used : EntityManager(javax.persistence.EntityManager) PersonForCollections(com.blazebit.persistence.view.testsuite.collections.entity.simple.PersonForCollections) TxVoidWork(com.blazebit.persistence.testsuite.tx.TxVoidWork) DocumentForCollections(com.blazebit.persistence.view.testsuite.collections.entity.simple.DocumentForCollections)

Example 4 with PersonForCollections

use of com.blazebit.persistence.view.testsuite.collections.entity.simple.PersonForCollections in project blaze-persistence by Blazebit.

the class MultisetFetchCollectionsBenchmarkTest method setUpOnce.

@Override
public void setUpOnce() {
    cleanDatabase();
    transactional(new TxVoidWork() {

        @Override
        public void work(EntityManager em) {
            List<DocumentForCollections> docs = new ArrayList<>();
            for (int i = 1; i <= 20; i++) {
                docs.add(new DocumentForCollections("doc" + i));
            }
            DocumentForCollections doc1 = docs.get(0);
            pers1 = new PersonForCollections("pers1");
            for (DocumentForCollections doc : docs) {
                doc.setOwner(pers1);
            }
            doc1.getPersonList().add(pers1);
            for (int i = 2; i <= 20; i++) {
                doc1.getPersonList().add(new PersonForCollections("listPers" + i));
            }
            doc1.getContacts().put(1, pers1);
            for (int i = 2; i <= 20; i++) {
                doc1.getContacts().put(i, new PersonForCollections("contactsPers" + i));
            }
            em.persist(pers1);
            for (PersonForCollections personForCollections : doc1.getPersonList()) {
                em.persist(personForCollections);
            }
            for (PersonForCollections personForCollections : doc1.getContacts().values()) {
                em.persist(personForCollections);
            }
            for (DocumentForCollections doc : docs) {
                em.persist(doc);
            }
            pers1.setPartnerDocument(doc1);
            for (int i = 2; i <= 20; i++) {
                PersonForCollections partner = new PersonForCollections("partnerPers" + i);
                partner.setPartnerDocument(doc1);
                em.persist(partner);
            }
        }
    });
}
Also used : EntityManager(javax.persistence.EntityManager) PersonForCollections(com.blazebit.persistence.view.testsuite.collections.entity.simple.PersonForCollections) TxVoidWork(com.blazebit.persistence.testsuite.tx.TxVoidWork) DocumentForCollections(com.blazebit.persistence.view.testsuite.collections.entity.simple.DocumentForCollections) ArrayList(java.util.ArrayList) List(java.util.List)

Example 5 with PersonForCollections

use of com.blazebit.persistence.view.testsuite.collections.entity.simple.PersonForCollections in project blaze-persistence by Blazebit.

the class MultisetFetchCollectionsTest method testCollections.

// 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
@Test
@Category({ NoDB2.class, NoDatanucleus.class, NoEclipselink.class })
public void testCollections() {
    EntityViewManager evm = build(PersonForCollectionsMultisetFetchNestedView.class, SubviewSimpleDocumentMultisetFetchView.class, SubviewDocumentMultisetFetchView.class, SubviewPersonForCollectionsMultisetFetchView.class, SubviewPersonForCollectionsView.class);
    CriteriaBuilder<PersonForCollections> criteria = cbf.create(em, PersonForCollections.class, "p").where("id").in(pers1.getId(), pers2.getId()).orderByAsc("id");
    CriteriaBuilder<PersonForCollectionsMultisetFetchNestedView> cb = evm.applySetting(EntityViewSetting.create(PersonForCollectionsMultisetFetchNestedView.class), criteria);
    List<PersonForCollectionsMultisetFetchNestedView> results = cb.getResultList();
    assertEquals(2, results.size());
    // Pers1
    assertEquals(pers1.getName(), results.get(0).getName());
    assertSubviewEquals(pers1.getPartnerDocument(), results.get(0).getPartnerDocument());
    assertSubviewCollectionEquals(pers1.getOwnedDocuments(), results.get(0).getOwnedDocuments());
    assertSubviewEquals(pers1.getPartnerDocument(), results.get(0).getCorrelatedPartnerDocument());
    assertSimpleSubviewCollectionEquals(pers1.getOwnedDocuments(), results.get(0).getCorrelatedOwnedDocuments());
    // Pers2
    assertEquals(pers2.getName(), results.get(1).getName());
    assertSubviewEquals(pers2.getPartnerDocument(), results.get(1).getPartnerDocument());
    assertSubviewCollectionEquals(pers2.getOwnedDocuments(), results.get(1).getOwnedDocuments());
    assertSubviewEquals(pers2.getPartnerDocument(), results.get(1).getCorrelatedPartnerDocument());
    assertSimpleSubviewCollectionEquals(pers2.getOwnedDocuments(), results.get(1).getCorrelatedOwnedDocuments());
}
Also used : PersonForCollections(com.blazebit.persistence.view.testsuite.collections.entity.simple.PersonForCollections) PersonForCollectionsMultisetFetchNestedView(com.blazebit.persistence.view.testsuite.collections.subview.model.PersonForCollectionsMultisetFetchNestedView) EntityViewManager(com.blazebit.persistence.view.EntityViewManager) Category(org.junit.experimental.categories.Category) Test(org.junit.Test) AbstractEntityViewTest(com.blazebit.persistence.view.testsuite.AbstractEntityViewTest)

Aggregations

PersonForCollections (com.blazebit.persistence.view.testsuite.collections.entity.simple.PersonForCollections)19 TxVoidWork (com.blazebit.persistence.testsuite.tx.TxVoidWork)11 DocumentForCollections (com.blazebit.persistence.view.testsuite.collections.entity.simple.DocumentForCollections)11 EntityManager (javax.persistence.EntityManager)11 EntityViewManager (com.blazebit.persistence.view.EntityViewManager)4 AbstractEntityViewTest (com.blazebit.persistence.view.testsuite.AbstractEntityViewTest)4 Test (org.junit.Test)4 SubviewPersonForCollectionsView (com.blazebit.persistence.view.testsuite.collections.subview.model.SubviewPersonForCollectionsView)3 Category (org.junit.experimental.categories.Category)2 PersonForCollectionsMultisetFetchNestedView (com.blazebit.persistence.view.testsuite.collections.subview.model.PersonForCollectionsMultisetFetchNestedView)1 PersonForCollectionsSelectFetchNestedView (com.blazebit.persistence.view.testsuite.collections.subview.model.PersonForCollectionsSelectFetchNestedView)1 SubviewPersonForCollectionsSelectFetchView (com.blazebit.persistence.view.testsuite.collections.subview.model.SubviewPersonForCollectionsSelectFetchView)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 Before (org.junit.Before)1