Search in sources :

Example 16 with Version

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

the class DateTruncTest method setUpOnce.

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

        @Override
        public void work(EntityManager em) {
            Person p = new Person("Pers1");
            p.setAge(20L);
            em.persist(p);
            Version v1 = new Version();
            em.persist(v1);
            Document doc1 = new Document("Doc1", p, v1);
            doc1.setCreationDate(c1);
            doc1.setCreationDate2(c1);
            doc1.setLastModified(c1.getTime());
            doc1.setLastModified2(c1.getTime());
            em.persist(doc1);
        }
    });
}
Also used : EntityManager(javax.persistence.EntityManager) TxVoidWork(com.blazebit.persistence.testsuite.tx.TxVoidWork) Version(com.blazebit.persistence.testsuite.entity.Version) Document(com.blazebit.persistence.testsuite.entity.Document) Person(com.blazebit.persistence.testsuite.entity.Person)

Example 17 with Version

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

the class DateAddTest method setUpOnce.

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

        @Override
        public void work(EntityManager em) {
            Person p = new Person("Pers1");
            p.setAge(20L);
            em.persist(p);
            Version v1 = new Version();
            em.persist(v1);
            Document doc1 = new Document("Doc1", p, v1);
            doc1.setCreationDate(c1);
            doc1.setCreationDate2(c1);
            doc1.setLastModified(c1.getTime());
            doc1.setLastModified2(c1.getTime());
            em.persist(doc1);
        }
    });
}
Also used : EntityManager(javax.persistence.EntityManager) TxVoidWork(com.blazebit.persistence.testsuite.tx.TxVoidWork) Version(com.blazebit.persistence.testsuite.entity.Version) Document(com.blazebit.persistence.testsuite.entity.Document) Person(com.blazebit.persistence.testsuite.entity.Person)

Example 18 with Version

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

the class DateDiffTest method setUpOnce.

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

        @Override
        public void work(EntityManager em) {
            Person p = new Person("Pers1");
            p.setAge(20L);
            em.persist(p);
            Version v1 = new Version();
            em.persist(v1);
            Document doc1 = new Document("Doc1", p, v1);
            doc1.setCreationDate(c1);
            doc1.setCreationDate2(c2);
            doc1.setLastModified(l1.getTime());
            doc1.setLastModified2(l2.getTime());
            em.persist(doc1);
        }
    });
}
Also used : EntityManager(javax.persistence.EntityManager) TxVoidWork(com.blazebit.persistence.testsuite.tx.TxVoidWork) Version(com.blazebit.persistence.testsuite.entity.Version) Document(com.blazebit.persistence.testsuite.entity.Document) Person(com.blazebit.persistence.testsuite.entity.Person)

Example 19 with Version

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

the class JsonAndXmlTest method setUpOnce.

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

        @Override
        public void work(EntityManager em) {
            Person p = new Person("Pers1");
            p.setAge(20L);
            em.persist(p);
            Version v1 = new Version();
            v1.setUrl("a");
            Document doc1 = new Document("Doc1", p, v1);
            em.persist(doc1);
            em.persist(v1);
            Version v2 = new Version();
            v2.setUrl("b");
            Document doc2 = new Document("Doc1", p, v2);
            em.persist(doc2);
            em.persist(v2);
            Version v3 = new Version();
            v3.setUrl("c");
            Document doc3 = new Document("Doc2", p, v3);
            em.persist(doc3);
            em.persist(v3);
        }
    });
}
Also used : EntityManager(javax.persistence.EntityManager) TxVoidWork(com.blazebit.persistence.testsuite.tx.TxVoidWork) Version(com.blazebit.persistence.testsuite.entity.Version) Document(com.blazebit.persistence.testsuite.entity.Document) Person(com.blazebit.persistence.testsuite.entity.Person)

Example 20 with Version

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

the class SelectTest method testSelectSizeAsDistinctCount2.

@Test
public void testSelectSizeAsDistinctCount2() {
    // Given
    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);
            Version v1 = new Version();
            v1.setDate(Calendar.getInstance());
            v1.setDocument(d);
            Version v2 = new Version();
            v2.setDate(Calendar.getInstance());
            v2.setDocument(d);
            Version v3 = new Version();
            v3.setDate(Calendar.getInstance());
            v3.setDocument(d);
            em.persist(v1);
            em.persist(v2);
            em.persist(v3);
        }
    });
    // When
    CriteriaBuilder<Tuple> cb = cbf.create(em, Tuple.class).from(Document.class, "d").select("CASE WHEN SIZE(d.contacts) > 2 THEN SIZE(d.partners) ELSE SIZE(d.versions) END");
    // Then
    String expected = "SELECT CASE WHEN " + function("COUNT_TUPLE", "'DISTINCT'", "KEY(contacts_1)") + " > 2 THEN " + function("COUNT_TUPLE", "'DISTINCT'", "partners_1.id") + " ELSE " + function("COUNT_TUPLE", "'DISTINCT'", "versions_1.id") + " END FROM Document d LEFT JOIN d.contacts contacts_1 LEFT JOIN d.partners partners_1 LEFT JOIN d.versions versions_1 GROUP BY d.id";
    assertEquals(expected, cb.getQueryString());
    List<Tuple> result = cb.getResultList();
    assertEquals(3L, result.get(0).get(0));
}
Also used : EntityManager(javax.persistence.EntityManager) TxVoidWork(com.blazebit.persistence.testsuite.tx.TxVoidWork) Version(com.blazebit.persistence.testsuite.entity.Version) Document(com.blazebit.persistence.testsuite.entity.Document) Person(com.blazebit.persistence.testsuite.entity.Person) Tuple(javax.persistence.Tuple) Test(org.junit.Test)

Aggregations

Version (com.blazebit.persistence.testsuite.entity.Version)25 Document (com.blazebit.persistence.testsuite.entity.Document)24 Person (com.blazebit.persistence.testsuite.entity.Person)22 TxVoidWork (com.blazebit.persistence.testsuite.tx.TxVoidWork)14 EntityManager (javax.persistence.EntityManager)14 Test (org.junit.Test)9 AssertStatementBuilder (com.blazebit.persistence.testsuite.base.jpa.assertion.AssertStatementBuilder)6 AbstractEntityViewRemoveDocumentTest (com.blazebit.persistence.view.testsuite.update.remove.cascade.AbstractEntityViewRemoveDocumentTest)6 Tuple (javax.persistence.Tuple)3 NameObject (com.blazebit.persistence.testsuite.entity.NameObject)2 NameObjectContainer (com.blazebit.persistence.testsuite.entity.NameObjectContainer)2 Date (java.util.Date)2 CriteriaBuilder (com.blazebit.persistence.CriteriaBuilder)1 AbstractCoreTest (com.blazebit.persistence.testsuite.AbstractCoreTest)1 EntityViewConfiguration (com.blazebit.persistence.view.spi.EntityViewConfiguration)1 UpdatableDocumentView (com.blazebit.persistence.view.testsuite.update.remove.cascade.nested.model.UpdatableDocumentView)1 UpdatableDocumentWithCollectionsView (com.blazebit.persistence.view.testsuite.update.remove.cascade.nested.model.UpdatableDocumentWithCollectionsView)1 UpdatableDocumentWithMapsView (com.blazebit.persistence.view.testsuite.update.remove.cascade.nested.model.UpdatableDocumentWithMapsView)1 ArrayList (java.util.ArrayList)1 Category (org.junit.experimental.categories.Category)1