use of com.blazebit.persistence.testsuite.entity.Document in project blaze-persistence by Blazebit.
the class WithCTEMappingTest method testCteBinding.
@Test
public void testCteBinding() {
EntityViewManager evm = build(DocumentWithCTE.class);
CriteriaBuilder<Document> cb = cbf.create(em, Document.class).orderByAsc("id");
EntityViewSetting<DocumentWithCTE, CriteriaBuilder<DocumentWithCTE>> setting;
setting = EntityViewSetting.create(DocumentWithCTE.class);
setting.addOptionalParameter("ownerMaxAge", 63L);
List<DocumentWithCTE> list = evm.applySetting(setting, cb).getResultList();
assertEquals(2, list.size());
assertEquals("doc1", list.get(0).getName());
assertEquals("doc2", list.get(1).getName());
assertNull(list.get(0).getOwnedDocumentCount());
assertEquals(Long.valueOf(1), list.get(1).getOwnedDocumentCount());
}
use of com.blazebit.persistence.testsuite.entity.Document in project blaze-persistence by Blazebit.
the class WithCTEMappingTest method setUpOnce.
@Override
public void setUpOnce() {
cleanDatabase();
transactional(new TxVoidWork() {
@Override
public void work(EntityManager em) {
doc1 = new Document("doc1");
doc2 = new Document("doc2");
Person o1 = new Person("pers1", 64);
Person o2 = new Person("pers2", 32);
Person o3 = new Person("pers3", 16);
o1.getLocalized().put(1, "localized1");
o2.getLocalized().put(1, "localized2");
o3.getLocalized().put(1, "localized3");
doc1.setAge(10);
doc1.setOwner(o1);
doc2.setAge(20);
doc2.setOwner(o2);
doc1.getContacts().put(1, o1);
doc2.getContacts().put(1, o2);
doc1.getContacts2().put(2, o1);
doc2.getContacts2().put(2, o2);
em.persist(o1);
em.persist(o2);
em.persist(o3);
// Flush doc1 before so we get the ids we would expect
em.persist(doc1);
em.flush();
em.persist(doc2);
em.flush();
o1.setPartnerDocument(doc1);
o2.setPartnerDocument(doc2);
o3.setPartnerDocument(doc2);
}
});
}
use of com.blazebit.persistence.testsuite.entity.Document in project blaze-persistence by Blazebit.
the class CustomClassViewTest method setUp.
@Before
public void setUp() {
cleanDatabase();
transactional(new TxVoidWork() {
@Override
public void work(EntityManager em) {
doc1 = new Document("doc1", 5L);
doc2 = new Document("doc2", 10L);
Person o1 = new Person("pers1");
Person o2 = new Person("pers2");
o1.getLocalized().put(1, "localized1");
o2.getLocalized().put(1, "localized2");
o1.setPartnerDocument(doc1);
o2.setPartnerDocument(doc2);
doc1.setOwner(o1);
doc2.setOwner(o2);
doc1.getContacts().put(1, o1);
doc2.getContacts().put(1, o2);
doc1.getContacts2().put(2, o1);
doc2.getContacts2().put(2, o2);
em.persist(o1);
em.persist(o2);
em.persist(doc1);
em.persist(doc2);
}
});
doc1 = em.find(Document.class, doc1.getId());
doc2 = em.find(Document.class, doc2.getId());
}
use of com.blazebit.persistence.testsuite.entity.Document in project blaze-persistence by Blazebit.
the class InheritanceTest method inheritanceQuery.
@Test
// TODO: report that datanucleus thinks a NULL literal is of type Integer and normal integral literals are of type Long
@Category({ NoDatanucleus.class })
public void inheritanceQuery() {
CriteriaBuilder<Document> criteria = cbf.create(em, Document.class, "d").orderByAsc("id");
CriteriaBuilder<DocumentBaseView> cb = evm.applySetting(EntityViewSetting.create(DocumentBaseView.class), criteria);
List<DocumentBaseView> results = cb.getResultList();
assertEquals(6, results.size());
assertTypeMatches(results.get(0), evm, DocumentBaseView.class, NewSub1DocumentView.class);
assertTypeMatches(results.get(1), evm, DocumentBaseView.class, NewSub1DocumentView.class);
assertTypeMatches(results.get(2), evm, DocumentBaseView.class, NewSub2DocumentView.class);
assertTypeMatches(results.get(3), evm, DocumentBaseView.class, DocumentBaseView.class);
assertTypeMatches(results.get(4), evm, DocumentBaseView.class, UsedOldDocumentView.class);
assertTypeMatches(results.get(5), evm, DocumentBaseView.class, OldDocumentView.class);
NewSub1DocumentView docView1 = (NewSub1DocumentView) results.get(0);
NewSub1DocumentView docView2 = (NewSub1DocumentView) results.get(1);
NewSub2DocumentView docView3 = (NewSub2DocumentView) results.get(2);
DocumentBaseView docView4 = results.get(3);
UsedOldDocumentView docView5 = (UsedOldDocumentView) results.get(4);
OldDocumentView docView6 = (OldDocumentView) results.get(5);
assertDocumentEquals(doc1, docView1);
assertDocumentEquals(doc2, docView2);
assertDocumentEquals(doc3, docView3);
assertDocumentEquals(doc4, docView4);
assertDocumentEquals(doc5, docView5);
assertDocumentEquals(doc6, docView6);
assertSubviewEquals(doc1.getContacts().values(), docView1.getContacts());
assertVersionsEquals(doc1.getVersions(), docView1.getVersionIds());
assertSubviewEquals(doc2.getContacts().values(), docView2.getContacts());
assertVersionsEquals(doc2.getVersions(), docView2.getVersionIds());
assertEquals(doc3.getDefaultContact(), docView3.getDefaultContact());
assertSubviewEquals(doc5.getContacts().values(), docView5.getContacts());
assertSubviewEquals(doc5.getPartners(), docView5.getPartners());
assertSubviewEquals(doc6.getPartners(), docView6.getPartners());
}
use of com.blazebit.persistence.testsuite.entity.Document in project blaze-persistence by Blazebit.
the class FlatViewTest method setUp.
@Before
public void setUp() {
cleanDatabase();
transactional(new TxVoidWork() {
@Override
public void work(EntityManager em) {
doc1 = new Document("doc1");
doc2 = new Document("doc2");
Person o1 = new Person("pers1");
Person o2 = new Person("pers2");
o1.getLocalized().put(1, "localized1");
o2.getLocalized().put(1, "localized2");
o1.setPartnerDocument(doc1);
o2.setPartnerDocument(doc2);
doc1.setOwner(o1);
doc2.setOwner(o2);
doc1.getContacts().put(1, o1);
doc2.getContacts().put(1, o2);
doc1.getContacts2().put(2, o1);
doc2.getContacts2().put(2, o2);
em.persist(o1);
em.persist(o2);
em.persist(doc1);
em.persist(doc2);
}
});
doc1 = cbf.create(em, Document.class).where("id").eq(doc1.getId()).fetch("owner").getSingleResult();
doc2 = cbf.create(em, Document.class).where("id").eq(doc2.getId()).fetch("owner").getSingleResult();
}
Aggregations