Search in sources :

Example 96 with TxVoidWork

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

the class TablePerClassTest method setUpOnce.

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

        @Override
        public void work(EntityManager em) {
            TPCSub1 entity1 = new TPCSub1(1L, "test1");
            TPCSub2 entity2 = new TPCSub2(2L, "test2");
            em.persist(entity1);
            em.persist(entity2);
        }
    });
}
Also used : EntityManager(javax.persistence.EntityManager) TxVoidWork(com.blazebit.persistence.testsuite.tx.TxVoidWork) TPCSub1(com.blazebit.persistence.testsuite.entity.TPCSub1) TPCSub2(com.blazebit.persistence.testsuite.entity.TPCSub2)

Example 97 with TxVoidWork

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

the class TupleTest method testGetTupleElementAlias.

// from issue #490
@Test
public void testGetTupleElementAlias() {
    cleanDatabase();
    transactional(new TxVoidWork() {

        @Override
        public void work(EntityManager em) {
            Document d = new Document("D1");
            Person p1 = new Person("Joe");
            Person p2 = new Person("Fred");
            d.setOwner(p1);
            d.getPartners().add(p1);
            d.getPartners().add(p2);
            em.persist(p1);
            em.persist(p2);
            em.persist(d);
        }
    });
    CriteriaBuilder<Tuple> criteria = cbf.create(em, Tuple.class).from(Document.class, "d").select("d.id", "theId");
    Tuple result = criteria.getResultList().get(0);
    String alias = result.getElements().get(0).getAlias();
    assertEquals("theId", alias);
    assertEquals(result.get(0), result.get("theId"));
}
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) Tuple(javax.persistence.Tuple) Test(org.junit.Test)

Example 98 with TxVoidWork

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

the class UpdateEmbeddableComplexTest method testUpdateWithReturningEmbeddable.

@Test
// TODO: report that datanucleus doesn't support element collection in an embeddable
@Category({ NoH2.class, NoOracle.class, NoSQLite.class, NoFirebird.class, NoMySQL.class, NoDatanucleus.class, NoEclipselink.class, NoOpenJPA.class })
public void testUpdateWithReturningEmbeddable() {
    final String newEmbeddableTestEntityIdKey = "newKey";
    cleanDatabase();
    transactional(new TxVoidWork() {

        @Override
        public void work(EntityManager em) {
            EmbeddableTestEntityId embeddable1Id = new EmbeddableTestEntityId("1", "oldKey");
            EmbeddableTestEntity embeddable1 = new EmbeddableTestEntity();
            embeddable1.setId(embeddable1Id);
            em.persist(embeddable1);
            em.flush();
            String key = cbf.update(em, EmbeddableTestEntity.class, "e").set("id.key", newEmbeddableTestEntityIdKey).executeWithReturning("id.key", String.class).getLastResult();
            assertEquals(newEmbeddableTestEntityIdKey, key);
        }
    });
}
Also used : EmbeddableTestEntity(com.blazebit.persistence.testsuite.entity.EmbeddableTestEntity) EntityManager(javax.persistence.EntityManager) TxVoidWork(com.blazebit.persistence.testsuite.tx.TxVoidWork) EmbeddableTestEntityId(com.blazebit.persistence.testsuite.entity.EmbeddableTestEntityId) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 99 with TxVoidWork

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

the class OptimizedKeysetPaginationTest method setUpOnce.

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

        @Override
        public void work(EntityManager em) {
            DocumentWithNullableName doc1 = new DocumentWithNullableName("doc1");
            DocumentWithNullableName doc2 = new DocumentWithNullableName("doc2");
            DocumentWithNullableName doc3 = new DocumentWithNullableName("doc3");
            DocumentWithNullableName doc4 = new DocumentWithNullableName("doc4");
            DocumentWithNullableName doc5 = new DocumentWithNullableName("doc5");
            DocumentWithNullableName doc6 = new DocumentWithNullableName("doc6");
            Person o1 = new Person("Karl1");
            Person o2 = new Person("Karl2");
            Person o3 = new Person("Karl3");
            o4 = new Person("Karl4");
            doc1.setOwner(o1);
            doc2.setOwner(o2);
            doc3.setOwner(o3);
            doc4.setOwner(o4);
            doc5.setOwner(o4);
            doc6.setOwner(o4);
            doc1.setFriend(o1);
            doc2.setFriend(o2);
            doc3.setFriend(o3);
            doc4.setFriend(o4);
            doc5.setFriend(o4);
            doc6.setFriend(o4);
            em.persist(o1);
            em.persist(o2);
            em.persist(o3);
            em.persist(o4);
            em.persist(doc1);
            em.persist(doc2);
            em.persist(doc3);
            em.persist(doc4);
            em.persist(doc5);
            em.persist(doc6);
        }
    });
}
Also used : EntityManager(javax.persistence.EntityManager) TxVoidWork(com.blazebit.persistence.testsuite.tx.TxVoidWork) Person(com.blazebit.persistence.testsuite.entity.Person) DocumentWithNullableName(com.blazebit.persistence.testsuite.entity.DocumentWithNullableName)

Example 100 with TxVoidWork

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

the class PaginationOneToOneTest method setUpOnce.

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

        @Override
        public void work(EntityManager em) {
            DocumentForOneToOne doc1 = new DocumentForOneToOne("doc1");
            DocumentForOneToOne doc2 = new DocumentForOneToOne("doc2");
            Person p1 = new Person("owner");
            doc1.setOwner(p1);
            doc2.setOwner(p1);
            DocumentInfo o1 = new DocumentInfo(1L, doc2, "Karl1");
            DocumentInfo o2 = new DocumentInfo(2L, doc1, "Karl2");
            em.persist(p1);
            em.persist(doc1);
            em.persist(doc2);
            em.persist(o1);
            em.persist(o2);
        }
    });
}
Also used : EntityManager(javax.persistence.EntityManager) TxVoidWork(com.blazebit.persistence.testsuite.tx.TxVoidWork) DocumentForOneToOne(com.blazebit.persistence.testsuite.entity.DocumentForOneToOne) Person(com.blazebit.persistence.testsuite.entity.Person) DocumentInfo(com.blazebit.persistence.testsuite.entity.DocumentInfo)

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