Search in sources :

Example 11 with Document

use of com.blazebit.persistence.testsuite.entity.Document in project blaze-persistence by Blazebit.

the class UpdatableFlatViewTest method setUp.

@Before
public void setUp() {
    cleanDatabase();
    transactional(new TxVoidWork() {

        @Override
        public void work(EntityManager em) {
            doc1 = new Document("doc1");
            Person o1 = new Person("pers1");
            doc1.setOwner(o1);
            doc1.getNameMap().put("doc1", new NameObject("doc1", "doc1"));
            doc1.getNameMap().put("doc2", new NameObject("doc1", "doc1"));
            em.persist(o1);
            em.persist(doc1);
        }
    });
    doc1 = cbf.create(em, Document.class).where("id").eq(doc1.getId()).fetch("owner").getSingleResult();
}
Also used : EntityManager(javax.persistence.EntityManager) NameObject(com.blazebit.persistence.testsuite.entity.NameObject) 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 12 with Document

use of com.blazebit.persistence.testsuite.entity.Document in project blaze-persistence by Blazebit.

the class ConstructorOnlyFlatViewTest method setUp.

@Before
public void setUp() {
    cleanDatabase();
    transactional(new TxVoidWork() {

        @Override
        public void work(EntityManager em) {
            Document doc1 = new Document("doc1");
            Document doc2 = new Document("doc2");
            Person o1 = new Person("pers1");
            doc1.setOwner(o1);
            doc2.setOwner(o1);
            em.persist(o1);
            em.persist(doc1);
            em.persist(doc2);
        }
    });
}
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 13 with Document

use of com.blazebit.persistence.testsuite.entity.Document in project blaze-persistence by Blazebit.

the class AbstractFetchTest method testCorrelation.

protected <T extends DocumentFetchView> void testCorrelation(Class<T> entityView, Integer batchSize) {
    EntityViewManager evm = build(entityView, SimpleDocumentFetchView.class, SimplePersonFetchSubView.class);
    CriteriaBuilder<Document> criteria = cbf.create(em, Document.class, "d").orderByAsc("id");
    EntityViewSetting<T, CriteriaBuilder<T>> setting = EntityViewSetting.create(entityView);
    if (batchSize != null) {
        setting.setProperty(ConfigurationProperties.DEFAULT_BATCH_SIZE + ".correlatedOwnerId", batchSize);
    }
    CriteriaBuilder<T> cb = evm.applySetting(setting, criteria);
    List<T> results = cb.getResultList();
    assertEquals(4, results.size());
    // Doc1
    assertEquals(doc1.getName(), results.get(0).getName());
    assertThisAndOwnerMappings(doc1, results.get(0));
    // Doc2
    assertEquals(doc2.getName(), results.get(1).getName());
    assertThisAndOwnerMappings(doc2, results.get(1));
    // Doc3
    assertEquals(doc3.getName(), results.get(2).getName());
    assertThisAndOwnerMappings(doc3, results.get(2));
    // Doc4
    assertEquals(doc4.getName(), results.get(3).getName());
    assertThisAndOwnerMappings(doc4, results.get(3));
}
Also used : CriteriaBuilder(com.blazebit.persistence.CriteriaBuilder) EntityViewManager(com.blazebit.persistence.view.EntityViewManager) Document(com.blazebit.persistence.testsuite.entity.Document)

Example 14 with Document

use of com.blazebit.persistence.testsuite.entity.Document in project blaze-persistence by Blazebit.

the class AbstractFetchTest method setUpOnce.

@Override
public void setUpOnce() {
    cleanDatabase();
    transactional(new TxVoidWork() {

        @Override
        public void work(EntityManager em) {
            doc1 = new Document("doc1");
            doc2 = new Document("doc2");
            doc3 = new Document("doc3");
            doc4 = new Document("doc4");
            Person o1 = new Person("pers1");
            Person o2 = new Person("pers2");
            Person o3 = new Person("pers3");
            doc1.setOwner(o1);
            doc2.setOwner(o2);
            doc3.setOwner(o2);
            doc4.setOwner(o2);
            doc1.getStrings().add("s1");
            doc1.getStrings().add("s2");
            doc2.getStrings().add("s1");
            doc2.getStrings().add("s2");
            doc3.getStrings().add("s1");
            doc3.getStrings().add("s2");
            doc4.getStrings().add("s1");
            doc4.getStrings().add("s2");
            em.persist(o1);
            em.persist(o2);
            em.persist(o3);
            em.persist(doc1);
            em.persist(doc2);
            em.persist(doc3);
            em.persist(doc4);
            o1.setPartnerDocument(doc1);
            o2.setPartnerDocument(doc2);
            o3.setPartnerDocument(doc3);
        }
    });
}
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)

Example 15 with Document

use of com.blazebit.persistence.testsuite.entity.Document in project blaze-persistence by Blazebit.

the class ConstructorInheritanceTest method inheritanceQuery.

@Test
public void inheritanceQuery() {
    doc1 = cbf.create(em, Document.class).where("name").eq("doc1").getSingleResult();
    doc2 = cbf.create(em, Document.class).where("name").eq("doc2").getSingleResult();
    doc3 = cbf.create(em, Document.class).where("name").eq("doc3").getSingleResult();
    this.evm = build(SimplePersonSubView.class, DocumentBaseView.class, NewDocumentView.class, OldDocumentView.class);
    CriteriaBuilder<Document> criteria = cbf.create(em, Document.class, "d").orderByAsc("name");
    CriteriaBuilder<DocumentBaseView> cb = evm.applySetting(EntityViewSetting.create(DocumentBaseView.class), criteria);
    List<DocumentBaseView> results = cb.getResultList();
    assertEquals(3, results.size());
    NewDocumentView docView1 = (NewDocumentView) results.get(0);
    DocumentBaseView docView2 = (DocumentBaseView) results.get(1);
    OldDocumentView docView3 = (OldDocumentView) results.get(2);
    assertDocumentEquals(doc1, docView1);
    assertDocumentEquals(doc2, docView2);
    assertDocumentEquals(doc3, docView3);
    assertSubviewEquals(doc1.getContacts().values(), docView1.getPeople());
    assertSubviewEquals(Collections.singleton(doc2.getOwner()), docView2.getPeople());
    assertSubviewEquals(doc3.getPartners(), docView3.getPeople());
}
Also used : SimplePersonSubView(com.blazebit.persistence.view.testsuite.inheritance.constructor.model.SimplePersonSubView) ParameterOldDocumentView(com.blazebit.persistence.view.testsuite.inheritance.constructor.model.ParameterOldDocumentView) OldDocumentView(com.blazebit.persistence.view.testsuite.inheritance.constructor.model.OldDocumentView) DocumentBaseView(com.blazebit.persistence.view.testsuite.inheritance.constructor.model.DocumentBaseView) SuperTypeParameterDocumentBaseView(com.blazebit.persistence.view.testsuite.inheritance.constructor.model.SuperTypeParameterDocumentBaseView) Document(com.blazebit.persistence.testsuite.entity.Document) NewDocumentView(com.blazebit.persistence.view.testsuite.inheritance.constructor.model.NewDocumentView) ParameterNewDocumentView(com.blazebit.persistence.view.testsuite.inheritance.constructor.model.ParameterNewDocumentView) Test(org.junit.Test) AbstractEntityViewTest(com.blazebit.persistence.view.testsuite.AbstractEntityViewTest)

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