Search in sources :

Example 6 with BooleanExpression

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);
}
Also used : BooleanExpression(com.querydsl.core.types.dsl.BooleanExpression) Test(org.junit.Test)

Example 7 with BooleanExpression

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());
}
Also used : BooleanExpression(com.querydsl.core.types.dsl.BooleanExpression) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 8 with BooleanExpression

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);
}
Also used : BooleanExpression(com.querydsl.core.types.dsl.BooleanExpression) Query(org.apache.lucene.search.Query) Test(org.junit.Test)

Example 9 with BooleanExpression

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;
}
Also used : BooleanExpression(com.querydsl.core.types.dsl.BooleanExpression)

Example 10 with BooleanExpression

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);
}
Also used : BooleanExpression(com.querydsl.core.types.dsl.BooleanExpression) StringPath(com.querydsl.core.types.dsl.StringPath) Test(org.junit.Test)

Aggregations

BooleanExpression (com.querydsl.core.types.dsl.BooleanExpression)16 Test (org.junit.Test)13 Field (java.lang.reflect.Field)2 LinkedList (java.util.LinkedList)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Tuple (com.querydsl.core.Tuple)1 Expression (com.querydsl.core.types.Expression)1 OrderSpecifier (com.querydsl.core.types.OrderSpecifier)1 ComparableExpressionBase (com.querydsl.core.types.dsl.ComparableExpressionBase)1 EntityPathBase (com.querydsl.core.types.dsl.EntityPathBase)1 StringExpression (com.querydsl.core.types.dsl.StringExpression)1 StringPath (com.querydsl.core.types.dsl.StringPath)1 IOException (java.io.IOException)1 Serializable (java.io.Serializable)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1 Function (java.util.function.Function)1