Search in sources :

Example 1 with QCat

use of com.querydsl.core.domain.QCat in project querydsl by querydsl.

the class JPQLSerializerTest method and_or.

@Test
public void and_or() {
    //A.a.id.eq(theId).and(B.b.on.eq(false).or(B.b.id.eq(otherId)));
    QCat cat = QCat.cat;
    Predicate pred = cat.id.eq(1).and(cat.name.eq("Kitty").or(cat.name.eq("Boris")));
    JPQLSerializer serializer = new JPQLSerializer(HQLTemplates.DEFAULT);
    serializer.handle(pred);
    assertEquals("cat.id = ?1 and (cat.name = ?2 or cat.name = ?3)", serializer.toString());
    assertEquals("cat.id = 1 && (cat.name = Kitty || cat.name = Boris)", pred.toString());
}
Also used : QCat(com.querydsl.core.domain.QCat) Predicate(com.querydsl.core.types.Predicate) Test(org.junit.Test)

Example 2 with QCat

use of com.querydsl.core.domain.QCat in project querydsl by querydsl.

the class JPQLSerializerTest method case1_hibernate.

@Test
public void case1_hibernate() {
    QCat cat = QCat.cat;
    JPQLSerializer serializer = new JPQLSerializer(HQLTemplates.DEFAULT);
    Expression<?> expr = Expressions.cases().when(cat.toes.eq(2)).then(2).when(cat.toes.eq(3)).then(3).otherwise(4);
    serializer.handle(expr);
    assertEquals("case when (cat.toes = ?1) then ?1 when (cat.toes = ?2) then ?2 else 4 end", serializer.toString());
}
Also used : QCat(com.querydsl.core.domain.QCat) Test(org.junit.Test)

Example 3 with QCat

use of com.querydsl.core.domain.QCat 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 4 with QCat

use of com.querydsl.core.domain.QCat in project querydsl by querydsl.

the class JPQLSerializerTest method case1.

@Test
public void case1() {
    QCat cat = QCat.cat;
    JPQLSerializer serializer = new JPQLSerializer(JPQLTemplates.DEFAULT);
    Expression<?> expr = Expressions.cases().when(cat.toes.eq(2)).then(2).when(cat.toes.eq(3)).then(3).otherwise(4);
    serializer.handle(expr);
    assertEquals("case when (cat.toes = ?1) then ?1 when (cat.toes = ?2) then ?2 else ?3 end", serializer.toString());
}
Also used : QCat(com.querydsl.core.domain.QCat) Test(org.junit.Test)

Example 5 with QCat

use of com.querydsl.core.domain.QCat 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)

Aggregations

QCat (com.querydsl.core.domain.QCat)16 Test (org.junit.Test)16 DefaultQueryMetadata (com.querydsl.core.DefaultQueryMetadata)7 QueryMetadata (com.querydsl.core.QueryMetadata)7 EntityPath (com.querydsl.core.types.EntityPath)1 Path (com.querydsl.core.types.Path)1 Predicate (com.querydsl.core.types.Predicate)1 NumberPath (com.querydsl.core.types.dsl.NumberPath)1