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