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