use of com.querydsl.core.QueryMetadata in project querydsl by querydsl.
the class JPQLSerializerTest method nullsLast.
@Test
public void nullsLast() {
QCat cat = QCat.cat;
JPQLSerializer serializer = new JPQLSerializer(HQLTemplates.DEFAULT);
QueryMetadata md = new DefaultQueryMetadata();
md.addJoin(JoinType.DEFAULT, cat);
md.addOrderBy(cat.name.asc().nullsLast());
serializer.serialize(md, false, null);
assertEquals("select cat\n" + "from Cat cat\n" + "order by cat.name asc nulls last", serializer.toString());
}
use of com.querydsl.core.QueryMetadata in project querydsl by querydsl.
the class JPQLSerializerTest method count.
@Test
public void count() {
QCat cat = QCat.cat;
QueryMetadata md = new DefaultQueryMetadata();
md.addJoin(JoinType.DEFAULT, cat);
md.setProjection(cat.mate.countDistinct());
JPQLSerializer serializer1 = new JPQLSerializer(HQLTemplates.DEFAULT);
serializer1.serialize(md, true, null);
assertEquals("select count(count(distinct cat.mate))\n" + "from Cat cat", serializer1.toString());
JPQLSerializer serializer2 = new JPQLSerializer(HQLTemplates.DEFAULT);
serializer2.serialize(md, false, null);
assertEquals("select count(distinct cat.mate)\n" + "from Cat cat", serializer2.toString());
}
use of com.querydsl.core.QueryMetadata in project querydsl by querydsl.
the class JPQLSerializerTest method delete_with_subQuery.
@Test
public void delete_with_subQuery() {
QCat parent = QCat.cat;
QCat child = new QCat("kitten");
JPQLSerializer serializer = new JPQLSerializer(HQLTemplates.DEFAULT);
QueryMetadata md = new DefaultQueryMetadata();
md.addJoin(JoinType.DEFAULT, child);
md.addWhere(child.id.eq(1).and(selectOne().from(parent).where(parent.id.eq(2), child.in(parent.kittens)).exists()));
serializer.serializeForDelete(md);
assertEquals("delete from Cat kitten\n" + "where kitten.id = ?1 and exists (select 1\n" + "from Cat cat\nwhere cat.id = ?2 and kitten member of cat.kittens)", serializer.toString());
}
use of com.querydsl.core.QueryMetadata in project querydsl by querydsl.
the class JPQLSerializerTest method nullsFirst.
@Test
public void nullsFirst() {
QCat cat = QCat.cat;
JPQLSerializer serializer = new JPQLSerializer(HQLTemplates.DEFAULT);
QueryMetadata md = new DefaultQueryMetadata();
md.addJoin(JoinType.DEFAULT, cat);
md.addOrderBy(cat.name.asc().nullsFirst());
serializer.serialize(md, false, null);
assertEquals("select cat\n" + "from Cat cat\n" + "order by cat.name asc nulls first", serializer.toString());
}
use of com.querydsl.core.QueryMetadata in project querydsl by querydsl.
the class JPAQueryMixinTest method orderBy_nonRoot_twice.
@Test
public void orderBy_nonRoot_twice() {
QDepartment department = QDepartment.department;
QCompany departmentCompany = new QCompany("department_company");
QEmployee departmentCompanyCeo = new QEmployee("department_company_ceo");
mixin.from(department);
mixin.orderBy(department.company.ceo.firstName.asc(), department.company.ceo.lastName.asc());
QueryMetadata md = mixin.getMetadata();
assertEquals(Arrays.asList(new JoinExpression(JoinType.DEFAULT, department), new JoinExpression(JoinType.LEFTJOIN, department.company.as(departmentCompany)), new JoinExpression(JoinType.LEFTJOIN, departmentCompany.ceo.as(departmentCompanyCeo))), md.getJoins());
assertEquals(Arrays.asList(departmentCompanyCeo.firstName.asc(), departmentCompanyCeo.lastName.asc()), md.getOrderBy());
}
Aggregations