Search in sources :

Example 11 with QueryMetadata

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

the class JPAQueryMixinTest method orderBy_groupBy.

@Test
public void orderBy_groupBy() {
    QCat cat = QCat.cat;
    mixin.from(cat);
    mixin.groupBy(cat.mate.name);
    mixin.orderBy(cat.mate.name.asc());
    QueryMetadata md = mixin.getMetadata();
    assertEquals(Arrays.asList(new JoinExpression(JoinType.DEFAULT, cat)), md.getJoins());
    assertEquals(Arrays.asList(cat.mate.name.asc()), md.getOrderBy());
}
Also used : QCat(com.querydsl.jpa.domain.QCat) QueryMetadata(com.querydsl.core.QueryMetadata) JoinExpression(com.querydsl.core.JoinExpression) Test(org.junit.Test)

Example 12 with QueryMetadata

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

the class JPQLSerializerTest method fromWithCustomEntityName.

@Test
public void fromWithCustomEntityName() {
    JPQLSerializer serializer = new JPQLSerializer(HQLTemplates.DEFAULT);
    EntityPath<Location> entityPath = new EntityPathBase<Location>(Location.class, "entity");
    QueryMetadata md = new DefaultQueryMetadata();
    md.addJoin(JoinType.DEFAULT, entityPath);
    serializer.serialize(md, false, null);
    assertEquals("select entity\nfrom Location2 entity", serializer.toString());
}
Also used : DefaultQueryMetadata(com.querydsl.core.DefaultQueryMetadata) QueryMetadata(com.querydsl.core.QueryMetadata) DefaultQueryMetadata(com.querydsl.core.DefaultQueryMetadata) EntityPathBase(com.querydsl.core.types.dsl.EntityPathBase) Location(com.querydsl.jpa.domain.Location) Test(org.junit.Test)

Example 13 with QueryMetadata

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

the class JPQLSerializerTest method delete_clause_uses_dELETE_fROM.

@Test
public void delete_clause_uses_dELETE_fROM() {
    QEmployee employee = QEmployee.employee;
    JPQLSerializer serializer = new JPQLSerializer(HQLTemplates.DEFAULT);
    QueryMetadata md = new DefaultQueryMetadata();
    md.addJoin(JoinType.DEFAULT, employee);
    md.addWhere(employee.lastName.isNull());
    serializer.serializeForDelete(md);
    assertEquals("delete from Employee employee\nwhere employee.lastName is null", serializer.toString());
}
Also used : DefaultQueryMetadata(com.querydsl.core.DefaultQueryMetadata) QueryMetadata(com.querydsl.core.QueryMetadata) DefaultQueryMetadata(com.querydsl.core.DefaultQueryMetadata) QEmployee(com.querydsl.jpa.domain.QEmployee) Test(org.junit.Test)

Example 14 with QueryMetadata

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

the class JPQLSerializerTest method join_with.

@Test
public void join_with() {
    QCat cat = QCat.cat;
    JPQLSerializer serializer = new JPQLSerializer(HQLTemplates.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 with 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 15 with QueryMetadata

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

the class RelationalPathExtractor method visit.

@Override
public Set<RelationalPath<?>> visit(SubQueryExpression<?> expr, Set<RelationalPath<?>> known) {
    Set<RelationalPath<?>> old = known;
    final QueryMetadata md = expr.getMetadata();
    known = visitJoins(md.getJoins(), known);
    if (md.getProjection() != null) {
        known = md.getProjection().accept(this, known);
    }
    for (OrderSpecifier<?> o : md.getOrderBy()) {
        known = o.getTarget().accept(this, known);
    }
    for (Expression<?> g : md.getGroupBy()) {
        known = g.accept(this, known);
    }
    if (md.getHaving() != null) {
        known = md.getHaving().accept(this, known);
    }
    if (md.getWhere() != null) {
        md.getWhere().accept(this, known);
    }
    return old;
}
Also used : QueryMetadata(com.querydsl.core.QueryMetadata)

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