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);
}
}
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;
}
}
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);
}
}
}
}
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));
}
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));
}
Aggregations