Search in sources :

Example 6 with Predicate

use of com.querydsl.core.types.Predicate in project querydsl by querydsl.

the class SerializationBase method any_serialized.

@Test
public void any_serialized() throws Exception {
    Predicate where = cat.kittens.any().name.eq("Ruth234");
    Predicate where2 = Serialization.serialize(where);
    assertEquals(0, query().from(cat).where(where).fetchCount());
    assertEquals(0, query().from(cat).where(where2).fetchCount());
}
Also used : Predicate(com.querydsl.core.types.Predicate) Test(org.junit.Test)

Example 7 with Predicate

use of com.querydsl.core.types.Predicate in project querydsl by querydsl.

the class JPACollectionAnyVisitorTest method simple_booleanOperation_elementCollection.

@Test
public void simple_booleanOperation_elementCollection() {
    QEmployee employee = QEmployee.employee;
    Predicate predicate = employee.jobFunctions.any().stringValue().eq("CODER");
    assertEquals("exists (select 1\n" + "from Employee employee_1463394548\n" + "  inner join employee_1463394548.jobFunctions as employee_jobFunctions_0\n" + "where employee_1463394548 = employee and str(employee_jobFunctions_0) = ?1)", serialize(predicate));
}
Also used : QEmployee(com.querydsl.jpa.domain.QEmployee) Predicate(com.querydsl.core.types.Predicate) Test(org.junit.Test)

Example 8 with Predicate

use of com.querydsl.core.types.Predicate in project querydsl by querydsl.

the class JPACollectionAnyVisitorTest method simple_stringOperation.

@Test
public void simple_stringOperation() {
    Predicate predicate = cat.kittens.any().name.substring(1).eq("uth123");
    assertEquals("exists (select 1\n" + "from cat.kittens as cat_kittens_0\n" + "where substring(cat_kittens_0.name,2) = ?1)", serialize(predicate));
}
Also used : Predicate(com.querydsl.core.types.Predicate) Test(org.junit.Test)

Example 9 with Predicate

use of com.querydsl.core.types.Predicate in project querydsl by querydsl.

the class JPACollectionAnyVisitorTest method and_operation.

@Test
public void and_operation() {
    Predicate predicate = cat.kittens.any().name.eq("Ruth123").and(cat.kittens.any().bodyWeight.gt(10.0));
    assertEquals("exists (select 1\n" + "from cat.kittens as cat_kittens_0\n" + "where cat_kittens_0.name = ?1) and exists (select 1\n" + "from cat.kittens as cat_kittens_1\n" + "where cat_kittens_1.bodyWeight > ?2)", serialize(predicate));
}
Also used : Predicate(com.querydsl.core.types.Predicate) Test(org.junit.Test)

Example 10 with Predicate

use of com.querydsl.core.types.Predicate 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)

Aggregations

Predicate (com.querydsl.core.types.Predicate)22 Test (org.junit.Test)20 QCat (com.querydsl.core.domain.QCat)1 Context (com.querydsl.core.support.Context)1 StringPath (com.querydsl.core.types.dsl.StringPath)1 QCompany (com.querydsl.jpa.domain.QCompany)1 QDomesticCat (com.querydsl.jpa.domain.QDomesticCat)1 QEmployee (com.querydsl.jpa.domain.QEmployee)1