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