Search in sources :

Example 16 with QueryMetadata

use of com.querydsl.core.QueryMetadata in project querydsl by querydsl.

the class SQLListenersTest method notifyQuery.

@Test
public void notifyQuery() {
    SQLListener listener = createMock(SQLListener.class);
    SQLListeners listeners = new SQLListeners();
    listeners.add(listener);
    QueryMetadata md = new DefaultQueryMetadata();
    listener.notifyQuery(md);
    replay(listener);
    listeners.notifyQuery(md);
    verify(listener);
}
Also used : DefaultQueryMetadata(com.querydsl.core.DefaultQueryMetadata) QueryMetadata(com.querydsl.core.QueryMetadata) DefaultQueryMetadata(com.querydsl.core.DefaultQueryMetadata) Test(org.junit.Test)

Example 17 with QueryMetadata

use of com.querydsl.core.QueryMetadata in project querydsl by querydsl.

the class SQLSerializerTest method withRecursive.

@SuppressWarnings("unchecked")
@Test
public void withRecursive() {
    /*with sub (id, firstname, superior_id) as (
            select id, firstname, superior_id from employee where firstname like 'Mike'
            union all
            select employee.id, employee.firstname, employee.superior_id from sub, employee
            where employee.superior_id = sub.id)
        select * from sub;*/
    QEmployee e = QEmployee.employee;
    PathBuilder<Tuple> sub = new PathBuilder<Tuple>(Tuple.class, "sub");
    SQLQuery<?> query = new SQLQuery<Void>(SQLTemplates.DEFAULT);
    query.withRecursive(sub, unionAll(select(e.id, e.firstname, e.superiorId).from(e).where(e.firstname.eq("Mike")), select(e.id, e.firstname, e.superiorId).from(e, sub).where(e.superiorId.eq(sub.get(e.id))))).from(sub);
    QueryMetadata md = query.getMetadata();
    md.setProjection(Wildcard.all);
    SQLSerializer serializer = new SQLSerializer(Configuration.DEFAULT);
    serializer.serialize(md, false);
    assertEquals("with recursive sub as ((select EMPLOYEE.ID, EMPLOYEE.FIRSTNAME, EMPLOYEE.SUPERIOR_ID\n" + "from EMPLOYEE EMPLOYEE\n" + "where EMPLOYEE.FIRSTNAME = ?)\n" + "union all\n" + "(select EMPLOYEE.ID, EMPLOYEE.FIRSTNAME, EMPLOYEE.SUPERIOR_ID\n" + "from EMPLOYEE EMPLOYEE, sub\n" + "where EMPLOYEE.SUPERIOR_ID = sub.ID))\n" + "select *\n" + "from sub", serializer.toString());
}
Also used : QueryMetadata(com.querydsl.core.QueryMetadata) QEmployee(com.querydsl.sql.domain.QEmployee) Tuple(com.querydsl.core.Tuple) Test(org.junit.Test)

Example 18 with QueryMetadata

use of com.querydsl.core.QueryMetadata in project querydsl by querydsl.

the class QueryMetadataTest method reusage.

@Test
public void reusage() {
    QueryMetadata metadata = new DefaultQueryMetadata();
    metadata.addJoin(JoinType.DEFAULT, cat);
    metadata.addWhere(cat.name.startsWith("A"));
    CollQuery<?> query = new CollQuery<Void>(metadata);
    query.bind(cat, cats);
    assertEquals(Arrays.asList(c3), query.select(cat).fetch());
}
Also used : QueryMetadata(com.querydsl.core.QueryMetadata) DefaultQueryMetadata(com.querydsl.core.DefaultQueryMetadata) DefaultQueryMetadata(com.querydsl.core.DefaultQueryMetadata) Test(org.junit.Test)

Example 19 with QueryMetadata

use of com.querydsl.core.QueryMetadata in project querydsl by querydsl.

the class JPQLSerializerTest method openJPA_variables.

@Test
public void openJPA_variables() {
    QCat cat = QCat.cat;
    JPQLSerializer serializer = new JPQLSerializer(OpenJPATemplates.DEFAULT);
    QueryMetadata md = new DefaultQueryMetadata();
    md.addJoin(JoinType.DEFAULT, cat);
    md.addJoin(JoinType.INNERJOIN, cat.mate);
    md.addJoinCondition(cat.mate.alive);
    serializer.serialize(md, false, null);
    assertEquals("select cat_\nfrom Cat cat_\n  inner join cat_.mate on cat_.mate.alive", 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 20 with QueryMetadata

use of com.querydsl.core.QueryMetadata in project querydsl by querydsl.

the class JPQLSerializerTest method treat.

@SuppressWarnings("unchecked")
@Test
public void treat() {
    QCat cat = QCat.cat;
    JPQLSerializer serializer = new JPQLSerializer(HQLTemplates.DEFAULT);
    QueryMetadata md = new DefaultQueryMetadata();
    md.addJoin(JoinType.DEFAULT, cat);
    md.addJoin(JoinType.JOIN, cat.mate.as((Path) QDomesticCat.domesticCat));
    md.setProjection(QDomesticCat.domesticCat);
    serializer.serialize(md, false, null);
    assertEquals("select domesticCat\n" + "from Cat cat\n" + "  inner join treat(cat.mate as DomesticCat) as domesticCat", serializer.toString());
}
Also used : QCat(com.querydsl.core.domain.QCat) Path(com.querydsl.core.types.Path) NumberPath(com.querydsl.core.types.dsl.NumberPath) EntityPath(com.querydsl.core.types.EntityPath) DefaultQueryMetadata(com.querydsl.core.DefaultQueryMetadata) QueryMetadata(com.querydsl.core.QueryMetadata) DefaultQueryMetadata(com.querydsl.core.DefaultQueryMetadata) 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