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);
}
});
}
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);
}
});
}
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);
}
});
}
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);
}
});
}
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));
}
Aggregations