Search in sources :

Example 1 with TxVoidWork

use of com.blazebit.persistence.testsuite.tx.TxVoidWork in project blaze-persistence by Blazebit.

the class AbstractClassViewTest 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.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(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 2 with TxVoidWork

use of com.blazebit.persistence.testsuite.tx.TxVoidWork in project blaze-persistence by Blazebit.

the class EmbeddableTestEntityViewTest method setUp.

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

        @Override
        public void work(EntityManager em) {
            IntIdEntity intIdEntity1 = new IntIdEntity("1");
            entity1 = new EmbeddableTestEntity2();
            entity1.setId(new EmbeddableTestEntityId2(intIdEntity1, "1"));
            entity1.getEmbeddableSet().add(new EmbeddableTestEntitySimpleEmbeddable2("1"));
            entity1.getEmbeddableMap().put("key1", new EmbeddableTestEntitySimpleEmbeddable2("1"));
            entity1.getEmbeddable().setName("1");
            entity1.getEmbeddable().setManyToOne(null);
            entity1.getEmbeddable().getElementCollection().put("1", intIdEntity1);
            IntIdEntity intIdEntity2 = new IntIdEntity("2");
            entity2 = new EmbeddableTestEntity2();
            entity2.setId(new EmbeddableTestEntityId2(intIdEntity2, "2"));
            entity2.getEmbeddableSet().add(new EmbeddableTestEntitySimpleEmbeddable2("2"));
            entity2.getEmbeddableMap().put("key2", new EmbeddableTestEntitySimpleEmbeddable2("2"));
            entity2.getEmbeddable().setName("2");
            entity2.getEmbeddable().setManyToOne(entity1);
            entity2.getEmbeddable().getElementCollection().put("2", intIdEntity2);
            em.persist(intIdEntity1);
            em.persist(intIdEntity2);
            em.persist(entity1);
            em.persist(entity2);
        }
    });
    entity1 = cbf.create(em, EmbeddableTestEntity2.class).fetch("id.intIdEntity", "embeddableSet", "embeddableMap", "embeddable.manyToOne", "embeddable.oneToMany", "embeddable.elementCollection").where("id").eq(entity1.getId()).getSingleResult();
    entity2 = cbf.create(em, EmbeddableTestEntity2.class).fetch("id.intIdEntity", "embeddableSet", "embeddableMap", "embeddable.manyToOne", "embeddable.oneToMany", "embeddable.elementCollection").where("id").eq(entity2.getId()).getSingleResult();
}
Also used : EmbeddableTestEntity2(com.blazebit.persistence.view.testsuite.entity.EmbeddableTestEntity2) EmbeddableTestEntitySimpleEmbeddable2(com.blazebit.persistence.view.testsuite.entity.EmbeddableTestEntitySimpleEmbeddable2) EntityManager(javax.persistence.EntityManager) IntIdEntity(com.blazebit.persistence.testsuite.entity.IntIdEntity) TxVoidWork(com.blazebit.persistence.testsuite.tx.TxVoidWork) EmbeddableTestEntityId2(com.blazebit.persistence.view.testsuite.entity.EmbeddableTestEntityId2) Before(org.junit.Before)

Example 3 with TxVoidWork

use of com.blazebit.persistence.testsuite.tx.TxVoidWork in project blaze-persistence by Blazebit.

the class EntityViewSettingTest method setUpOnce.

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

        @Override
        public void work(EntityManager em) {
            Document doc1 = new Document("MyTest");
            Document doc2 = new Document("YourTest");
            Document doc3 = new Document("NoContacts");
            Person o1 = new Person("pers1");
            Person o2 = new Person("pers2");
            Person o3 = new Person("pers3");
            Person o4 = new Person("pers4");
            Person o5 = new Person("pers5");
            Person o6 = new Person("pers6");
            o1.getLocalized().put(1, "localized1");
            o2.getLocalized().put(1, "localized2");
            o1.setPartnerDocument(doc1);
            o2.setPartnerDocument(doc2);
            doc1.setOwner(o1);
            doc2.setOwner(o2);
            doc3.setOwner(o2);
            doc1.getContacts().put(1, o1);
            doc2.getContacts().put(1, o2);
            doc3.getContacts().put(1, o3);
            doc1.getContacts().put(2, o4);
            doc2.getContacts().put(2, o5);
            doc3.getContacts().put(2, o6);
            doc1.getContacts2().put(2, o1);
            doc2.getContacts2().put(2, o2);
            doc3.getContacts2().put(2, o3);
            em.persist(o1);
            em.persist(o2);
            em.persist(o3);
            em.persist(o4);
            em.persist(o5);
            em.persist(o6);
            em.persist(doc1);
            em.persist(doc2);
            em.persist(doc3);
        }
    });
}
Also used : EntityManager(javax.persistence.EntityManager) TxVoidWork(com.blazebit.persistence.testsuite.tx.TxVoidWork) Document(com.blazebit.persistence.testsuite.entity.Document) FilteredDocument(com.blazebit.persistence.view.testsuite.basic.model.FilteredDocument) Person(com.blazebit.persistence.testsuite.entity.Person)

Example 4 with TxVoidWork

use of com.blazebit.persistence.testsuite.tx.TxVoidWork 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);
        }
    });
}
Also used : EntityManager(javax.persistence.EntityManager) PersonForCollections(com.blazebit.persistence.view.testsuite.collections.entity.simple.PersonForCollections) TxVoidWork(com.blazebit.persistence.testsuite.tx.TxVoidWork) DocumentForCollections(com.blazebit.persistence.view.testsuite.collections.entity.simple.DocumentForCollections)

Example 5 with TxVoidWork

use of com.blazebit.persistence.testsuite.tx.TxVoidWork 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)

Aggregations

TxVoidWork (com.blazebit.persistence.testsuite.tx.TxVoidWork)135 EntityManager (javax.persistence.EntityManager)131 Person (com.blazebit.persistence.testsuite.entity.Person)76 Document (com.blazebit.persistence.testsuite.entity.Document)69 Before (org.junit.Before)28 Test (org.junit.Test)15 Version (com.blazebit.persistence.testsuite.entity.Version)14 DocumentForCollections (com.blazebit.persistence.view.testsuite.collections.entity.simple.DocumentForCollections)11 PersonForCollections (com.blazebit.persistence.view.testsuite.collections.entity.simple.PersonForCollections)11 Category (org.junit.experimental.categories.Category)7 IntIdEntity (com.blazebit.persistence.testsuite.entity.IntIdEntity)5 SingleTableSub1 (com.blazebit.persistence.testsuite.treat.entity.SingleTableSub1)5 SingleTableSub2 (com.blazebit.persistence.testsuite.treat.entity.SingleTableSub2)5 PolymorphicSub1 (com.blazebit.persistence.testsuite.entity.PolymorphicSub1)4 PolymorphicSub2 (com.blazebit.persistence.testsuite.entity.PolymorphicSub2)4 TPCSub1 (com.blazebit.persistence.testsuite.entity.TPCSub1)4 TPCSub2 (com.blazebit.persistence.testsuite.entity.TPCSub2)4 CriteriaBuilder (com.blazebit.persistence.CriteriaBuilder)3 EmbeddableTestEntity (com.blazebit.persistence.testsuite.entity.EmbeddableTestEntity)3 EmbeddableTestEntityId (com.blazebit.persistence.testsuite.entity.EmbeddableTestEntityId)3