use of com.querydsl.core.types.dsl.BooleanExpression in project querydsl by querydsl.
the class SearchQueryTest method paging.
@Test
public void paging() {
BooleanExpression filter = user.middleName.eq("X");
OrderSpecifier<?> order = user.firstName.asc();
// limit
List<String> limit = getFirstNames(query().where(filter).orderBy(order).limit(2).fetch());
assertEquals(Arrays.asList("Anton", "Barbara"), limit);
// offset
List<String> offset = getFirstNames(query().where(filter).orderBy(order).offset(1).fetch());
assertEquals(Arrays.asList("Barbara", "John", "Robert"), offset);
// limit + offset
List<String> limitAndOffset = getFirstNames(query().where(filter).orderBy(order).limit(2).offset(1).fetch());
assertEquals(Arrays.asList("Barbara", "John"), limitAndOffset);
}
use of com.querydsl.core.types.dsl.BooleanExpression in project querydsl by querydsl.
the class JPABase method subquery_uniqueResult.
@Test
// isn't a valid JPQL query
@Ignore
public void subquery_uniqueResult() {
QCat cat2 = new QCat("cat2");
BooleanExpression exists = selectOne().from(cat2).where(cat2.eyecolor.isNotNull()).exists();
assertNotNull(query().from(cat).where(cat.breed.eq(0).not()).select(new QCatSummary(cat.breed.count(), exists)).fetchOne());
}
use of com.querydsl.core.types.dsl.BooleanExpression in project querydsl by querydsl.
the class LuceneSerializerTest method queryElement.
@Test
public void queryElement() throws Exception {
Query query1 = serializer.toQuery(author.like("Michael"), metadata);
Query query2 = serializer.toQuery(text.like("Text"), metadata);
BooleanExpression query = Expressions.anyOf(new QueryElement(query1), new QueryElement(query2));
testQuery(query, "author:michael text:text", 1);
}
use of com.querydsl.core.types.dsl.BooleanExpression in project querydsl by querydsl.
the class RelationalPathBase method primaryKeyOperation.
private BooleanExpression primaryKeyOperation(Operator op, PrimaryKey<?> pk1, PrimaryKey<?> pk2) {
if (pk1 == null || pk2 == null) {
throw new UnsupportedOperationException("No primary keys available");
}
if (pk1.getLocalColumns().size() != pk2.getLocalColumns().size()) {
throw new UnsupportedOperationException("Size mismatch for primary key columns");
}
BooleanExpression rv = null;
for (int i = 0; i < pk1.getLocalColumns().size(); i++) {
BooleanExpression pred = Expressions.booleanOperation(op, pk1.getLocalColumns().get(i), pk2.getLocalColumns().get(i));
rv = rv != null ? rv.and(pred) : pred;
}
return rv;
}
use of com.querydsl.core.types.dsl.BooleanExpression in project querydsl by querydsl.
the class PrecedenceTest method test.
@Test
public void test() {
StringPath str1 = Expressions.stringPath("str1");
StringPath str2 = Expressions.stringPath("str2");
BooleanExpression pending = str1.eq("3").and(str2.eq("1"));
BooleanExpression notNew = str1.ne("1").and(str2.in("2", "3"));
BooleanExpression whereClause = str1.eq("a").and(pending.or(notNew));
String str = new SQLSerializer(Configuration.DEFAULT).handle(whereClause).toString();
assertEquals("str1 = ? and (str1 = ? and str2 = ? or str1 != ? and str2 in (?, ?))", str);
}
Aggregations