Search in sources :

Example 6 with Document

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());
}
Also used : CriteriaBuilder(com.blazebit.persistence.CriteriaBuilder) EntityViewManager(com.blazebit.persistence.view.EntityViewManager) DocumentWithCTE(com.blazebit.persistence.view.testsuite.cte.model.DocumentWithCTE) Document(com.blazebit.persistence.testsuite.entity.Document) PersonWithPartnerDocument(com.blazebit.persistence.view.testsuite.cte.model.PersonWithPartnerDocument) Test(org.junit.Test) AbstractEntityViewTest(com.blazebit.persistence.view.testsuite.AbstractEntityViewTest)

Example 7 with Document

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);
        }
    });
}
Also used : EntityManager(javax.persistence.EntityManager) TxVoidWork(com.blazebit.persistence.testsuite.tx.TxVoidWork) Document(com.blazebit.persistence.testsuite.entity.Document) PersonWithPartnerDocument(com.blazebit.persistence.view.testsuite.cte.model.PersonWithPartnerDocument) Person(com.blazebit.persistence.testsuite.entity.Person)

Example 8 with Document

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());
}
Also used : EntityManager(javax.persistence.EntityManager) TxVoidWork(com.blazebit.persistence.testsuite.tx.TxVoidWork) Document(com.blazebit.persistence.testsuite.entity.Document) Person(com.blazebit.persistence.testsuite.entity.Person) Before(org.junit.Before)

Example 9 with Document

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());
}
Also used : UnusedOldDocumentView(com.blazebit.persistence.view.testsuite.inheritance.basic.model.UnusedOldDocumentView) OldDocumentView(com.blazebit.persistence.view.testsuite.inheritance.basic.model.OldDocumentView) UsedOldDocumentView(com.blazebit.persistence.view.testsuite.inheritance.basic.model.UsedOldDocumentView) DocumentBaseView(com.blazebit.persistence.view.testsuite.inheritance.basic.model.DocumentBaseView) UsedOldDocumentView(com.blazebit.persistence.view.testsuite.inheritance.basic.model.UsedOldDocumentView) NewSub1DocumentView(com.blazebit.persistence.view.testsuite.inheritance.basic.model.NewSub1DocumentView) NewSub2DocumentView(com.blazebit.persistence.view.testsuite.inheritance.basic.model.NewSub2DocumentView) Document(com.blazebit.persistence.testsuite.entity.Document) Category(org.junit.experimental.categories.Category) Test(org.junit.Test) AbstractEntityViewTest(com.blazebit.persistence.view.testsuite.AbstractEntityViewTest)

Example 10 with Document

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();
}
Also used : EntityManager(javax.persistence.EntityManager) TxVoidWork(com.blazebit.persistence.testsuite.tx.TxVoidWork) Document(com.blazebit.persistence.testsuite.entity.Document) Person(com.blazebit.persistence.testsuite.entity.Person) Before(org.junit.Before)

Aggregations

Document (com.blazebit.persistence.testsuite.entity.Document)283 Test (org.junit.Test)206 AssertStatementBuilder (com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder)114 Person (com.blazebit.persistence.testsuite.entity.Person)99 EntityManager (javax.persistence.EntityManager)70 TxVoidWork (com.blazebit.persistence.testsuite.tx.TxVoidWork)69 AbstractEntityViewUpdateDocumentTest (com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateDocumentTest)54 Category (org.junit.experimental.categories.Category)44 AbstractEntityViewTest (com.blazebit.persistence.view.testsuite.AbstractEntityViewTest)43 EntityViewManager (com.blazebit.persistence.view.EntityViewManager)31 AbstractEntityViewUpdateEntityCollectionsTest (com.blazebit.persistence.view.testsuite.update.entity.AbstractEntityViewUpdateEntityCollectionsTest)24 CriteriaBuilder (com.blazebit.persistence.CriteriaBuilder)21 AbstractEntityViewUpdateEntityMapsTest (com.blazebit.persistence.view.testsuite.update.entity.AbstractEntityViewUpdateEntityMapsTest)21 Version (com.blazebit.persistence.testsuite.entity.Version)20 PaginatedCriteriaBuilder (com.blazebit.persistence.PaginatedCriteriaBuilder)16 AbstractCoreTest (com.blazebit.persistence.testsuite.AbstractCoreTest)16 Before (org.junit.Before)16 Tuple (javax.persistence.Tuple)14 QDocument (com.blazebit.persistence.testsuite.entity.QDocument)11 UpdatableDocumentEntityWithCollectionsView (com.blazebit.persistence.view.testsuite.update.entity.mutable.model.UpdatableDocumentEntityWithCollectionsView)9