Search in sources :

Example 21 with QueryMetadata

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());
}
Also used : QCat(com.querydsl.core.domain.QCat) DefaultQueryMetadata(com.querydsl.core.DefaultQueryMetadata) QueryMetadata(com.querydsl.core.QueryMetadata) DefaultQueryMetadata(com.querydsl.core.DefaultQueryMetadata) Test(org.junit.Test)

Example 22 with QueryMetadata

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());
}
Also used : QCat(com.querydsl.core.domain.QCat) DefaultQueryMetadata(com.querydsl.core.DefaultQueryMetadata) QueryMetadata(com.querydsl.core.QueryMetadata) DefaultQueryMetadata(com.querydsl.core.DefaultQueryMetadata) Test(org.junit.Test)

Example 23 with QueryMetadata

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());
}
Also used : QCat(com.querydsl.core.domain.QCat) DefaultQueryMetadata(com.querydsl.core.DefaultQueryMetadata) QueryMetadata(com.querydsl.core.QueryMetadata) DefaultQueryMetadata(com.querydsl.core.DefaultQueryMetadata) Test(org.junit.Test)

Example 24 with QueryMetadata

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());
}
Also used : QCat(com.querydsl.core.domain.QCat) DefaultQueryMetadata(com.querydsl.core.DefaultQueryMetadata) QueryMetadata(com.querydsl.core.QueryMetadata) DefaultQueryMetadata(com.querydsl.core.DefaultQueryMetadata) Test(org.junit.Test)

Example 25 with QueryMetadata

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());
}
Also used : QCompany(com.querydsl.jpa.domain.QCompany) QueryMetadata(com.querydsl.core.QueryMetadata) JoinExpression(com.querydsl.core.JoinExpression) QEmployee(com.querydsl.jpa.domain.QEmployee) QDepartment(com.querydsl.jpa.domain.QDepartment) Test(org.junit.Test)

Aggregations

QueryMetadata (com.querydsl.core.QueryMetadata)39 Test (org.junit.Test)35 DefaultQueryMetadata (com.querydsl.core.DefaultQueryMetadata)20 JoinExpression (com.querydsl.core.JoinExpression)15 QCat (com.querydsl.jpa.domain.QCat)8 QCat (com.querydsl.core.domain.QCat)7 StringPath (com.querydsl.core.types.dsl.StringPath)6 Tuple (com.querydsl.core.Tuple)2 QEmployee (com.querydsl.jpa.domain.QEmployee)2 QBookVersion (com.querydsl.jpa.domain4.QBookVersion)2 LuceneSerializer (com.querydsl.lucene5.LuceneSerializer)2 QEmployee (com.querydsl.sql.domain.QEmployee)2 Benchmark (com.querydsl.core.testutil.Benchmark)1 EntityPath (com.querydsl.core.types.EntityPath)1 Path (com.querydsl.core.types.Path)1 EntityPathBase (com.querydsl.core.types.dsl.EntityPathBase)1 NumberPath (com.querydsl.core.types.dsl.NumberPath)1 Location (com.querydsl.jpa.domain.Location)1 QCompany (com.querydsl.jpa.domain.QCompany)1 QDepartment (com.querydsl.jpa.domain.QDepartment)1