Search in sources :

Example 11 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)

Example 12 with BooleanBuilder

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

the class BooleanOperationsTest method booleanBuilder1.

@Test
public void booleanBuilder1() {
    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));
}
Also used : BooleanBuilder(com.querydsl.core.BooleanBuilder) Test(org.junit.Test)

Example 13 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 14 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 15 with BooleanBuilder

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

the class ProductoServiceImpl method buscarProductos.

@Override
public Page<Producto> buscarProductos(BusquedaProductoCriteria criteria) {
    //Empresa
    if (criteria.getEmpresa() == null) {
        throw new EntityNotFoundException(ResourceBundle.getBundle("Mensajes").getString("mensaje_empresa_no_existente"));
    }
    //Rubro
    if (criteria.isBuscarPorRubro() == true && criteria.getRubro() == null) {
        throw new BusinessServiceException(ResourceBundle.getBundle("Mensajes").getString("mensaje_producto_vacio_rubro"));
    }
    //Proveedor
    if (criteria.isBuscarPorProveedor() == true && criteria.getProveedor() == null) {
        throw new BusinessServiceException(ResourceBundle.getBundle("Mensajes").getString("mensaje_producto_vacio_proveedor"));
    }
    QProducto qproducto = QProducto.producto;
    BooleanBuilder builder = new BooleanBuilder();
    builder.and(qproducto.empresa.eq(criteria.getEmpresa()).and(qproducto.eliminado.eq(false)));
    if (criteria.isBuscarPorCodigo() == true && criteria.isBuscarPorDescripcion() == true) {
        builder.and(qproducto.codigo.containsIgnoreCase(criteria.getCodigo()).or(this.buildPredicadoDescripcion(criteria.getDescripcion(), qproducto)));
    } else {
        if (criteria.isBuscarPorCodigo() == true) {
            builder.and(qproducto.codigo.containsIgnoreCase(criteria.getCodigo()));
        }
        if (criteria.isBuscarPorDescripcion() == true) {
            builder.and(this.buildPredicadoDescripcion(criteria.getDescripcion(), qproducto));
        }
    }
    if (criteria.isBuscarPorRubro() == true) {
        builder.and(qproducto.rubro.eq(criteria.getRubro()));
    }
    if (criteria.isBuscarPorProveedor()) {
        builder.and(qproducto.proveedor.eq(criteria.getProveedor()));
    }
    if (criteria.isListarSoloFaltantes() == true) {
        builder.and(qproducto.cantidad.loe(qproducto.cantMinima)).and(qproducto.ilimitado.eq(false));
    }
    return productoRepository.findAll(builder, criteria.getPageable());
}
Also used : BusinessServiceException(sic.service.BusinessServiceException) BooleanBuilder(com.querydsl.core.BooleanBuilder) EntityNotFoundException(javax.persistence.EntityNotFoundException) QProducto(sic.modelo.QProducto)

Aggregations

BooleanBuilder (com.querydsl.core.BooleanBuilder)16 EntityNotFoundException (javax.persistence.EntityNotFoundException)6 ArrayList (java.util.ArrayList)5 Sort (org.springframework.data.domain.Sort)5 Test (org.junit.Test)4 BusinessServiceException (sic.service.BusinessServiceException)3 Calendar (java.util.Calendar)2 Date (java.util.Date)2 GregorianCalendar (java.util.GregorianCalendar)2 Map (java.util.Map)2 FormatterFechaHora (sic.util.FormatterFechaHora)2 BooleanExpression (com.querydsl.core.types.dsl.BooleanExpression)1 EntityPathBase (com.querydsl.core.types.dsl.EntityPathBase)1 BeanMap (com.querydsl.core.util.BeanMap)1 QCat (com.querydsl.jpa.domain.QCat)1 HibernateQuery (com.querydsl.jpa.hibernate.HibernateQuery)1 QSurvey (com.querydsl.sql.domain.QSurvey)1 LocalDate (java.time.LocalDate)1 Caja (sic.modelo.Caja)1 Cliente (sic.modelo.Cliente)1