use of com.blazebit.persistence.testsuite.entity.QDocument in project blaze-persistence by Blazebit.
the class BasicQueryTest method testNestedSubQuery.
// NOTE: No advanced sql support for Datanucleus, Eclipselink and OpenJPA yet
@Test
@Category({ NoDatanucleus.class, NoEclipselink.class, NoOpenJPA.class })
public void testNestedSubQuery() {
doInJPA(entityManager -> {
QDocument sub = new QDocument("sub");
QDocument sub2 = new QDocument("sub2");
BlazeJPAQuery<Tuple> query = new BlazeJPAQuery<Document>(entityManager, cbf).from(document).select(document.name.as("documentName"), document.name.substring(0, 2)).where(document.id.in(select(sub.id).from(sub).where(sub.id.in(select(sub2.id).from(sub2).where(sub2.id.eq(sub.id)))).orderBy(sub.id.asc()).limit(5)));
List<Tuple> fetch = query.fetch();
assertFalse(fetch.isEmpty());
});
}
use of com.blazebit.persistence.testsuite.entity.QDocument in project blaze-persistence by Blazebit.
the class BasicQueryTest method testEntityJoin.
// NOTE: Entity joins are only supported on Hibernate 5.1+
@Test
@Category({ NoDatanucleus.class, NoEclipselink.class, NoOpenJPA.class, NoHibernate42.class, NoHibernate43.class, NoHibernate50.class })
public void testEntityJoin() {
Assume.assumeTrue(jpaProvider.supportsEntityJoin());
doInJPA(entityManager -> {
QPerson otherAuthor = new QPerson("otherAuthor");
QDocument otherBook = new QDocument("otherBook");
Map<Person, List<Document>> booksByAuthor = new BlazeJPAQuery<Document>(entityManager, cbf).from(otherAuthor).innerJoin(otherBook).on(otherBook.owner.eq(otherAuthor)).transform(GroupBy.groupBy(otherAuthor).as(GroupBy.list(otherBook)));
assertNotNull(booksByAuthor);
});
}
use of com.blazebit.persistence.testsuite.entity.QDocument in project blaze-persistence by Blazebit.
the class BasicQueryTest method testComplexSubqueryUnion.
// NOTE: No advanced sql support for Datanucleus, Eclipselink and OpenJPA yet
// NOTE: MySQL only supports the UNION set operation
@Test
@Category({ NoMySQL.class, NoFirebird.class, NoDatanucleus.class, NoEclipselink.class, NoOpenJPA.class })
public void testComplexSubqueryUnion() {
doInJPA(entityManager -> {
Person person = new Person();
person.setName("Person");
entityManager.persist(person);
Document theBook = new Document();
theBook.setId(1337L);
theBook.setName("test");
theBook.setOwner(person);
entityManager.merge(theBook);
Document theSequel = new Document();
theSequel.setId(42L);
theSequel.setName("test2");
theSequel.setOwner(person);
entityManager.merge(theSequel);
});
doInJPA(entityManager -> {
SetExpression<Long> union = new BlazeJPAQuery<Long>(entityManager, cbf).union(select(document.id).from(document).where(document.id.eq(1337L)), new BlazeJPAQuery<Long>().intersect(select(document.id).from(document).where(document.id.eq(41L)), new BlazeJPAQuery<Long>().except(select(document.id).from(document).where(document.id.eq(42L)), select(document.id).from(document).where(document.id.eq(43L)))), select(document.id).from(document).where(document.id.eq(46L)));
QDocument book2 = new QDocument("secondBook");
List<Document> fetch = new BlazeJPAQuery<Document>(entityManager, cbf).select(book2).from(book2).where(book2.id.in(union)).fetch();
assertNotNull(fetch);
});
}
use of com.blazebit.persistence.testsuite.entity.QDocument in project blaze-persistence by Blazebit.
the class BasicQueryTest method testWindowFunction.
// NOTE: Window functions were only introduced in MySQL8
@Test
@Category({ NoMySQLOld.class })
public void testWindowFunction() {
Assume.assumeTrue(dbmsDialect.supportsWindowFunctions());
doInJPA(entityManager -> {
QDocument sub = new QDocument("sub");
BlazeJPAQuery<Tuple> query = new BlazeJPAQuery<Document>(entityManager, cbf).from(document).select(document.name.as("documentName"), rowNumber().over().orderBy(document.id), lastValue(document.name).over().partitionBy(document.id).orderBy(document.id)).where(document.id.in(select(sub.id).from(sub)));
List<Tuple> fetch = query.fetch();
assertFalse(fetch.isEmpty());
});
}
use of com.blazebit.persistence.testsuite.entity.QDocument in project blaze-persistence by Blazebit.
the class BasicQueryTest method testSubQuery.
@Test
public void testSubQuery() {
doInJPA(entityManager -> {
QDocument sub = new QDocument("sub");
BlazeJPAQuery<Tuple> query = new BlazeJPAQuery<Document>(entityManager, cbf).from(document).select(document.name.as("blep"), document.name.substring(0, 2)).where(document.id.in(select(sub.id).from(sub)));
List<Tuple> fetch = query.fetch();
assertFalse(fetch.isEmpty());
});
}
Aggregations