Search in sources :

Example 36 with BooleanBuilder

use of com.querydsl.core.BooleanBuilder in project querydsl by querydsl.

the class ForeignKey method on.

@SuppressWarnings("unchecked")
public Predicate on(RelationalPath<E> entity) {
    BooleanBuilder builder = new BooleanBuilder();
    for (int i = 0; i < localColumns.size(); i++) {
        Expression<Object> local = (Expression<Object>) localColumns.get(i);
        Expression<?> foreign = ExpressionUtils.path(local.getType(), entity, foreignColumns.get(i));
        builder.and(ExpressionUtils.eq(local, foreign));
    }
    return builder.getValue();
}
Also used : BooleanExpression(com.querydsl.core.types.dsl.BooleanExpression) BooleanBuilder(com.querydsl.core.BooleanBuilder)

Example 37 with BooleanBuilder

use of com.querydsl.core.BooleanBuilder in project querydsl by querydsl.

the class SQLSerializerTest method boolean_.

@Test
public void boolean_() {
    QSurvey s = new QSurvey("s");
    BooleanBuilder bb1 = new BooleanBuilder();
    bb1.and(s.name.eq(s.name));
    BooleanBuilder bb2 = new BooleanBuilder();
    bb2.or(s.name.eq(s.name));
    bb2.or(s.name.eq(s.name));
    String str = new SQLSerializer(Configuration.DEFAULT).handle(bb1.and(bb2)).toString();
    assertEquals("s.NAME = s.NAME and (s.NAME = s.NAME or s.NAME = s.NAME)", str);
}
Also used : BooleanBuilder(com.querydsl.core.BooleanBuilder) QSurvey(com.querydsl.sql.domain.QSurvey) Test(org.junit.Test)

Example 38 with BooleanBuilder

use of com.querydsl.core.BooleanBuilder in project querydsl by querydsl.

the class CustomFinder method findCustom.

@SuppressWarnings("unchecked")
public static <T> List<T> findCustom(EntityManager em, Class<T> entityClass, Map<String, ?> filters, String sort) {
    EntityPath<T> entityPath = new EntityPathBase<T>(entityClass, "entity");
    BooleanBuilder builder = new BooleanBuilder();
    for (Map.Entry<String, ?> entry : filters.entrySet()) {
        SimplePath<Object> property = Expressions.path((Class) entry.getValue().getClass(), entityPath, entry.getKey());
        builder.and(property.eq(entry.getValue()));
    }
    ComparablePath<?> sortProperty = Expressions.comparablePath(Comparable.class, entityPath, sort);
    return new JPAQuery<Void>(em).from(entityPath).where(builder.getValue()).orderBy(sortProperty.asc()).select(entityPath).fetch();
}
Also used : BooleanBuilder(com.querydsl.core.BooleanBuilder) EntityPathBase(com.querydsl.core.types.dsl.EntityPathBase) Map(java.util.Map)

Example 39 with BooleanBuilder

use of com.querydsl.core.BooleanBuilder in project querydsl by querydsl.

the class HibernateQueryTest method clone_.

@Test
public void clone_() {
    QCat cat = QCat.cat;
    BooleanBuilder emptyBooleanBuilder = new BooleanBuilder();
    HibernateQuery<?> hq = new HibernateQuery<Void>().from(cat).where(cat.name.isNull().and(emptyBooleanBuilder));
    HibernateQuery<?> hq2 = hq.clone();
    assertNotNull(hq2);
}
Also used : QCat(com.querydsl.jpa.domain.QCat) BooleanBuilder(com.querydsl.core.BooleanBuilder) HibernateQuery(com.querydsl.jpa.hibernate.HibernateQuery) Test(org.junit.Test)

Example 40 with BooleanBuilder

use of com.querydsl.core.BooleanBuilder in project querydsl by querydsl.

the class BooleanOperationsTest method booleanBuilder2.

@Test
public void booleanBuilder2() {
    BooleanBuilder bb1 = new BooleanBuilder();
    bb1.and(cat.eq(cat));
    BooleanBuilder bb2 = new BooleanBuilder();
    bb2.or(cat.eq(cat));
    bb2.or(cat.eq(cat));
    assertToString("cat = cat and (cat = cat or cat = cat)", bb1.and(bb2.getValue()));
}
Also used : BooleanBuilder(com.querydsl.core.BooleanBuilder) Test(org.junit.Test)

Aggregations

BooleanBuilder (com.querydsl.core.BooleanBuilder)41 Predicate (com.querydsl.core.types.Predicate)12 ArrayList (java.util.ArrayList)10 JPAQuery (com.querydsl.jpa.impl.JPAQuery)8 QJpaAlert (com.thinkbiganalytics.metadata.jpa.alerts.QJpaAlert)8 Sort (org.springframework.data.domain.Sort)8 List (java.util.List)7 QJpaOpsManagerFeed (com.thinkbiganalytics.metadata.jpa.feed.QJpaOpsManagerFeed)6 Map (java.util.Map)6 Pageable (org.springframework.data.domain.Pageable)6 Alert (com.thinkbiganalytics.alerts.api.Alert)5 Test (org.junit.Test)5 JpaAlert (com.thinkbiganalytics.metadata.jpa.alerts.JpaAlert)4 HashMap (java.util.HashMap)4 Collectors (java.util.stream.Collectors)4 EntityNotFoundException (javax.persistence.EntityNotFoundException)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 Service (org.springframework.stereotype.Service)4 Expression (com.querydsl.core.types.Expression)3 Projections (com.querydsl.core.types.Projections)3