Search in sources :

Example 1 with Predicate

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

the class QueryByExampleTest method name_not_set.

@Test
public void name_not_set() {
    ExampleEntity entity = new ExampleEntity();
    Predicate qbe = QExampleEntity.exampleEntity.like(entity);
    assertNull(qbe);
}
Also used : Predicate(com.querydsl.core.types.Predicate) Test(org.junit.Test)

Example 2 with Predicate

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

the class QueryByExampleTest method name_set.

@Test
public void name_set() {
    ExampleEntity entity = new ExampleEntity();
    entity.name = "XXX";
    Predicate qbe = QExampleEntity.exampleEntity.like(entity);
    assertEquals("exampleEntity.name = XXX", qbe.toString());
}
Also used : Predicate(com.querydsl.core.types.Predicate) Test(org.junit.Test)

Example 3 with Predicate

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

the class DocumentTest method test4.

@Test
public void test4() {
    Predicate crit = qDoc.id.eq(3L).or(qDoc.meshThesaurusTerms.any().eq("x"));
    List<Document> expResult = CollQueryFactory.from(qDoc, doc1, doc2, doc3).where(crit).fetch();
    assertTrue(expResult.contains(doc1));
    //fails, expResult contains only doc1, but should contain doc1 and doc3!
    assertTrue(expResult.contains(doc3));
}
Also used : Predicate(com.querydsl.core.types.Predicate) Test(org.junit.Test)

Example 4 with Predicate

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

the class CollectionAnyVisitorTest method simple_booleanOperation.

@Test
public void simple_booleanOperation() {
    Predicate predicate = cat.kittens.any().name.eq("Ruth123");
    assertEquals("cat_kittens_0.name = Ruth123", serialize(predicate));
}
Also used : Predicate(com.querydsl.core.types.Predicate) Test(org.junit.Test)

Example 5 with Predicate

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

the class SerializationBase method any_serialized2.

@Test
public void any_serialized2() throws Exception {
    Predicate where = cat.kittens.any().name.eq("Ruth234");
    File file = new File("target", "predicate.ser");
    if (!file.exists()) {
        // serialize predicate on first run
        FileOutputStream fileOutputStream = new FileOutputStream(file);
        ObjectOutputStream out = new ObjectOutputStream(fileOutputStream);
        out.writeObject(where);
        out.close();
        assertEquals(0, query().from(cat).where(where).fetchCount());
    } else {
        // deserialize predicate on second run
        FileInputStream fileInputStream = new FileInputStream(file);
        ObjectInputStream in = new ObjectInputStream(fileInputStream);
        Predicate where2 = (Predicate) in.readObject();
        in.close();
        assertEquals(0, query().from(cat).where(where2).fetchCount());
    }
}
Also used : 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