Search in sources :

Example 11 with Predicate

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

the class MongodbQueryTest method various.

@Test
public void various() {
    ListPath<Address, QAddress> list = user.addresses;
    StringPath str = user.lastName;
    List<Predicate> predicates = new ArrayList<Predicate>();
    predicates.add(str.between("a", "b"));
    predicates.add(str.contains("a"));
    predicates.add(str.containsIgnoreCase("a"));
    predicates.add(str.endsWith("a"));
    predicates.add(str.endsWithIgnoreCase("a"));
    predicates.add(str.eq("a"));
    predicates.add(str.equalsIgnoreCase("a"));
    predicates.add(str.goe("a"));
    predicates.add(str.gt("a"));
    predicates.add(str.in("a", "b", "c"));
    predicates.add(str.isEmpty());
    predicates.add(str.isNotNull());
    predicates.add(str.isNull());
    predicates.add(str.like("a"));
    predicates.add(str.loe("a"));
    predicates.add(str.lt("a"));
    predicates.add(str.matches("a"));
    predicates.add(str.ne("a"));
    predicates.add(str.notBetween("a", "b"));
    predicates.add(str.notIn("a", "b", "c"));
    predicates.add(str.startsWith("a"));
    predicates.add(str.startsWithIgnoreCase("a"));
    predicates.add(list.isEmpty());
    predicates.add(list.isNotEmpty());
    for (Predicate predicate : predicates) {
        long count1 = where(predicate).fetchCount();
        long count2 = where(predicate.not()).fetchCount();
        assertEquals(predicate.toString(), 4, count1 + count2);
    }
}
Also used : StringPath(com.querydsl.core.types.dsl.StringPath) Predicate(com.querydsl.core.types.Predicate) Test(org.junit.Test)

Example 12 with Predicate

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

the class CollQueryMixin method convert.

@Override
protected Predicate convert(Predicate predicate, Role role) {
    predicate = (Predicate) ExpressionUtils.extract(predicate);
    if (predicate != null) {
        Context context = new Context();
        Predicate transformed = (Predicate) predicate.accept(collectionAnyVisitor, context);
        for (int i = 0; i < context.paths.size(); i++) {
            leftJoin((Path) context.paths.get(i).getMetadata().getParent(), (Path) context.replacements.get(i));
            on(ANY);
        }
        return transformed;
    } else {
        return predicate;
    }
}
Also used : Context(com.querydsl.core.support.Context) Predicate(com.querydsl.core.types.Predicate)

Example 13 with Predicate

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

the class QueryExecution method runFilterQueries.

private void runFilterQueries(Collection<Predicate> filters, boolean matching) {
    if (this.runFilters) {
        for (Predicate f : filters) {
            total++;
            try {
                // filter
                int results = runFilter(f);
                // filter distinct
                runFilterDistinct(f);
                if (counts) {
                    // count
                    runCount(f);
                    // count distinct
                    runCountDistinct(f);
                }
                if (matching && results == 0) {
                    failures.add(f + " failed");
                }
            } catch (Throwable t) {
                t.printStackTrace();
                t = addError(f, t);
            }
        }
    }
}
Also used : Predicate(com.querydsl.core.types.Predicate)

Example 14 with Predicate

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

the class CollectionAnyVisitorTest method simple_stringOperation.

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

Example 15 with Predicate

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

the class CollectionAnyVisitorTest 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("cat_kittens_0.name = Ruth123 && cat_kittens_1.bodyWeight > 10.0", serialize(predicate));
}
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