Search in sources :

Example 6 with Version

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

the class SizeTransformationTest method testSizeToCountTransformationMultiLevel.

@Test
public void testSizeToCountTransformationMultiLevel() {
    final Holder holder = new Holder();
    cleanDatabase();
    transactional(new TxVoidWork() {

        @Override
        public void work(EntityManager em) {
            Document doc1;
            Document doc2;
            Person o1;
            Person o2;
            doc1 = new Document("doc1");
            doc2 = new Document("doc2");
            o1 = new Person("Karl1");
            o2 = new Person("Karl2");
            o1.getLocalized().put(1, "abra kadabra");
            o2.getLocalized().put(1, "ass");
            Version v1 = new Version();
            v1.setDocument(doc1);
            Version v2 = new Version();
            v2.setDocument(doc2);
            Version v3 = new Version();
            v3.setDocument(doc2);
            doc1.setOwner(o1);
            doc2.setOwner(o1);
            doc1.getContacts().put(1, o1);
            doc1.getContacts().put(2, o2);
            em.persist(o1);
            em.persist(o2);
            em.persist(doc1);
            em.persist(doc2);
            em.persist(v1);
            em.persist(v2);
            em.persist(v3);
            holder.doc1 = doc1;
            holder.doc2 = doc2;
            holder.o1 = o1;
            holder.o2 = o2;
        }
    });
    Document doc1 = holder.doc1;
    Document doc2 = holder.doc2;
    Person o1 = holder.o1;
    Person o2 = holder.o2;
    CriteriaBuilder<Tuple> cb = cbf.create(this.em, Tuple.class).from(Person.class, "p").leftJoin("p.ownedDocuments", "ownedDocument").select("p.id").select("ownedDocument.id").select("SIZE(ownedDocument.versions)").select("SIZE(p.ownedDocuments)").orderByAsc("p.id").orderByAsc("ownedDocument.id");
    String expectedQuery = "SELECT p.id, ownedDocument.id, " + function("COUNT_TUPLE", "'DISTINCT'", "versions_1.id") + ", (SELECT " + countStar() + " FROM " + correlationPath("p.ownedDocuments", Document.class, "ownedDocuments", "owner.id = p.id") + ") FROM Person p LEFT JOIN p.ownedDocuments ownedDocument LEFT JOIN ownedDocument.versions versions_1" + " GROUP BY " + groupBy("ownedDocument.id", "p.id", renderNullPrecedenceGroupBy("ownedDocument.id", "ASC", "LAST")) + " ORDER BY p.id ASC, " + renderNullPrecedence("ownedDocument.id", "ASC", "LAST");
    Assert.assertEquals(expectedQuery, cb.getQueryString());
    List<Tuple> result = cb.getResultList();
    Assert.assertEquals(3, result.size());
    Assert.assertArrayEquals(new Object[] { o1.getId(), doc1.getId(), 1l, 2l }, result.get(0).toArray());
    Assert.assertArrayEquals(new Object[] { o1.getId(), doc2.getId(), 2l, 2l }, result.get(1).toArray());
    Assert.assertArrayEquals(new Object[] { o2.getId(), null, 0l, 0l }, result.get(2).toArray());
}
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)

Example 7 with Version

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

the class SelectNewObjectBuilderTest method setUpOnce.

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

        @Override
        public void work(EntityManager em) {
            Person p = new Person("Karl");
            em.persist(p);
            Version v1 = new Version();
            Version v2 = new Version();
            Version v3 = new Version();
            em.persist(v1);
            em.persist(v2);
            em.persist(v3);
            em.persist(new Document("Doc1", p, v1, v3));
            em.persist(new Document("Doc2", p, v2));
        }
    });
}
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 8 with Version

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

the class SelectNewTest method setUpOnce.

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

        @Override
        public void work(EntityManager em) {
            Person p = new Person("Karl");
            p.setAge(20L);
            p.getLocalized().put(1, "msg1");
            p.getLocalized().put(2, "msg2");
            em.persist(p);
            Version v1 = new Version();
            Version v2 = new Version();
            Version v3 = new Version();
            em.persist(v1);
            em.persist(v2);
            em.persist(v3);
            Document doc1 = new Document("Doc1", p, v1, v3);
            doc1.getPartners().add(p);
            em.persist(doc1);
            p.setPartnerDocument(doc1);
            em.persist(new Document("Doc2", p, v2));
        }
    });
}
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 9 with Version

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

the class ListaggTest 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();
            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("a");
            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 10 with Version

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

the class DateExtractTest method setUpOnce.

@Override
protected // Doing this for every timezone
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.setLastModified(c2.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)

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