Search in sources :

Example 1 with DocumentForCollections

use of com.blazebit.persistence.view.testsuite.collections.entity.simple.DocumentForCollections 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 DocumentForCollections

use of com.blazebit.persistence.view.testsuite.collections.entity.simple.DocumentForCollections 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 3 with DocumentForCollections

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

the class BasicPredicatedTest method multipleBasicPredicatedCollectionsAreFetchedCorrectly.

@Test
// Apparently EclipseLink just ignores any ON conditions when having join tables...
@Category({ NoEclipselink.class, NoDatanucleus.class })
public void multipleBasicPredicatedCollectionsAreFetchedCorrectly() {
    EntityViewManager evm = build(BasicPredicatedDocumentCollectionsView.class);
    CriteriaBuilder<DocumentForCollections> criteria = cbf.create(em, DocumentForCollections.class, "d").orderByAsc("id");
    CriteriaBuilder<BasicPredicatedDocumentCollectionsView> cb = evm.applySetting(EntityViewSetting.create(BasicPredicatedDocumentCollectionsView.class), criteria);
    List<BasicPredicatedDocumentCollectionsView> results = cb.getResultList();
    assertEquals(2, results.size());
    // Doc1
    assertEquals(doc1.getName(), results.get(0).getName());
    assertEquals(doc1.getContacts().get(0).getName(), results.get(0).getDefaultContactName());
    assertEquals(doc1.getContacts().get(1).getName(), results.get(0).getSecondContactName());
    assertEquals(doc1.getPersonList().get(0).getName(), results.get(0).getDefaultPersonName());
    assertEquals(doc1.getPersonList().get(1).getName(), results.get(0).getSecondPersonName());
    // Doc2
    assertEquals(doc2.getName(), results.get(1).getName());
    assertEquals(doc2.getContacts().get(0).getName(), results.get(1).getDefaultContactName());
    assertEquals(doc2.getContacts().get(1).getName(), results.get(1).getSecondContactName());
    assertEquals(doc2.getPersonList().get(0).getName(), results.get(1).getDefaultPersonName());
    assertEquals(doc2.getPersonList().get(1).getName(), results.get(1).getSecondPersonName());
}
Also used : EntityViewManager(com.blazebit.persistence.view.EntityViewManager) DocumentForCollections(com.blazebit.persistence.view.testsuite.collections.entity.simple.DocumentForCollections) BasicPredicatedDocumentCollectionsView(com.blazebit.persistence.view.testsuite.predicated.basic.model.BasicPredicatedDocumentCollectionsView) Category(org.junit.experimental.categories.Category) Test(org.junit.Test) AbstractEntityViewTest(com.blazebit.persistence.view.testsuite.AbstractEntityViewTest)

Example 4 with DocumentForCollections

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

the class MultisetFetchCollectionsBenchmarkTest method assertSubviewCollectionEquals.

private void assertSubviewCollectionEquals(Set<DocumentForCollections> ownedDocuments, Set<? extends SubviewDocumentMultisetFetchView> ownedSubviewDocuments) {
    assertEquals(ownedDocuments.size(), ownedSubviewDocuments.size());
    for (DocumentForCollections doc : ownedDocuments) {
        boolean found = false;
        for (SubviewDocumentMultisetFetchView docSub : ownedSubviewDocuments) {
            if (doc.getName().equals(docSub.getName())) {
                found = true;
                assertCollectionEquals(doc.getPartners(), docSub.getPartners());
                assertListEquals(doc.getPersonList(), docSub.getPersonList());
                assertMapEquals(doc.getContacts(), docSub.getContacts());
                assertEquals(Locale.ENGLISH, docSub.getTest());
                break;
            }
        }
        if (!found) {
            Assert.fail("Could not find a SubviewDocumentCollectionsView with the name: " + doc.getName());
        }
    }
}
Also used : DocumentForCollections(com.blazebit.persistence.view.testsuite.collections.entity.simple.DocumentForCollections) SubviewDocumentMultisetFetchView(com.blazebit.persistence.view.testsuite.multiset.model.SubviewDocumentMultisetFetchView)

Example 5 with DocumentForCollections

use of com.blazebit.persistence.view.testsuite.collections.entity.simple.DocumentForCollections 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)

Aggregations

DocumentForCollections (com.blazebit.persistence.view.testsuite.collections.entity.simple.DocumentForCollections)23 TxVoidWork (com.blazebit.persistence.testsuite.tx.TxVoidWork)11 PersonForCollections (com.blazebit.persistence.view.testsuite.collections.entity.simple.PersonForCollections)11 EntityManager (javax.persistence.EntityManager)11 EntityViewManager (com.blazebit.persistence.view.EntityViewManager)6 AbstractEntityViewTest (com.blazebit.persistence.view.testsuite.AbstractEntityViewTest)6 Test (org.junit.Test)6 Category (org.junit.experimental.categories.Category)3 SubviewDocumentCollectionsView (com.blazebit.persistence.view.testsuite.collections.subview.model.SubviewDocumentCollectionsView)2 EntityViewConfiguration (com.blazebit.persistence.view.spi.EntityViewConfiguration)1 SubviewDocumentCollectionsView (com.blazebit.persistence.view.testsuite.array.model.SubviewDocumentCollectionsView)1 BaseDocumentView (com.blazebit.persistence.view.testsuite.collections.ordered.model.BaseDocumentView)1 SubviewClassDocumentForCollectionsView (com.blazebit.persistence.view.testsuite.collections.subview.model.SubviewClassDocumentForCollectionsView)1 SubviewDocumentMultisetFetchView (com.blazebit.persistence.view.testsuite.collections.subview.model.SubviewDocumentMultisetFetchView)1 SubviewDocumentSelectFetchView (com.blazebit.persistence.view.testsuite.collections.subview.model.SubviewDocumentSelectFetchView)1 SubviewDocumentMultisetFetchView (com.blazebit.persistence.view.testsuite.multiset.model.SubviewDocumentMultisetFetchView)1 BasicPredicatedDocumentCollectionsView (com.blazebit.persistence.view.testsuite.predicated.basic.model.BasicPredicatedDocumentCollectionsView)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Before (org.junit.Before)1