Search in sources :

Example 6 with BooleanBuilder

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

the class TransportistaServiceImpl method buscarTransportistas.

@Override
public List<Transportista> buscarTransportistas(BusquedaTransportistaCriteria criteria) {
    //Empresa
    if (criteria.getEmpresa() == null) {
        throw new EntityNotFoundException(ResourceBundle.getBundle("Mensajes").getString("mensaje_empresa_no_existente"));
    }
    QTransportista qtransportista = QTransportista.transportista;
    BooleanBuilder builder = new BooleanBuilder();
    builder.and(qtransportista.empresa.eq(criteria.getEmpresa()).and(qtransportista.eliminado.eq(false)));
    //Nombre
    if (criteria.isBuscarPorNombre() == true) {
        builder.and(this.buildPredicadoNombre(criteria.getNombre(), qtransportista));
    }
    //Localidad
    if (criteria.isBuscarPorLocalidad() == true) {
        builder.and(qtransportista.localidad.eq(criteria.getLocalidad()));
    }
    //Provincia
    if (criteria.isBuscarPorProvincia() == true) {
        builder.and(qtransportista.localidad.provincia.eq(criteria.getProvincia()));
    }
    //Pais
    if (criteria.isBuscarPorPais() == true) {
        builder.and(qtransportista.localidad.provincia.pais.eq(criteria.getPais()));
    }
    List<Transportista> list = new ArrayList<>();
    transportistaRepository.findAll(builder, new Sort(Sort.Direction.ASC, "nombre")).iterator().forEachRemaining(list::add);
    return list;
}
Also used : QTransportista(sic.modelo.QTransportista) Transportista(sic.modelo.Transportista) QTransportista(sic.modelo.QTransportista) BooleanBuilder(com.querydsl.core.BooleanBuilder) ArrayList(java.util.ArrayList) Sort(org.springframework.data.domain.Sort) EntityNotFoundException(javax.persistence.EntityNotFoundException)

Example 7 with BooleanBuilder

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

the class CajaServiceImpl method getCajasCriteria.

@Override
public List<Caja> getCajasCriteria(BusquedaCajaCriteria criteria) {
    //Empresa
    if (criteria.getEmpresa() == null) {
        throw new EntityNotFoundException(ResourceBundle.getBundle("Mensajes").getString("mensaje_empresa_no_existente"));
    }
    //Fecha
    if (criteria.isBuscaPorFecha() == true && (criteria.getFechaDesde() == null || criteria.getFechaHasta() == null)) {
        throw new BusinessServiceException(ResourceBundle.getBundle("Mensajes").getString("mensaje_caja_fechas_invalidas"));
    }
    if (criteria.isBuscaPorFecha() == true) {
        Calendar cal = new GregorianCalendar();
        cal.setTime(criteria.getFechaDesde());
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        criteria.setFechaDesde(cal.getTime());
        cal.setTime(criteria.getFechaHasta());
        cal.set(Calendar.HOUR_OF_DAY, 23);
        cal.set(Calendar.MINUTE, 59);
        cal.set(Calendar.SECOND, 59);
        criteria.setFechaHasta(cal.getTime());
    }
    if (criteria.getEmpresa() == null) {
        throw new EntityNotFoundException(ResourceBundle.getBundle("Mensajes").getString("mensaje_empresa_no_existente"));
    }
    QCaja qcaja = QCaja.caja;
    BooleanBuilder builder = new BooleanBuilder();
    builder.and(qcaja.empresa.eq(criteria.getEmpresa()).and(qcaja.eliminada.eq(false)));
    if (criteria.isBuscaPorUsuario() == true) {
        builder.and(qcaja.usuarioCierraCaja.eq(criteria.getUsuario()));
    }
    if (criteria.isBuscaPorFecha() == true) {
        FormatterFechaHora formateadorFecha = new FormatterFechaHora(FormatterFechaHora.FORMATO_FECHAHORA_INTERNACIONAL);
        DateExpression<Date> fDesde = Expressions.dateTemplate(Date.class, "convert({0}, datetime)", formateadorFecha.format(criteria.getFechaDesde()));
        DateExpression<Date> fHasta = Expressions.dateTemplate(Date.class, "convert({0}, datetime)", formateadorFecha.format(criteria.getFechaHasta()));
        builder.and(qcaja.fechaApertura.between(fDesde, fHasta));
    }
    List<Caja> cajas = new ArrayList<>();
    cajaRepository.findAll(builder, new Sort(Sort.Direction.DESC, "fechaApertura")).iterator().forEachRemaining(cajas::add);
    return cajas;
}
Also used : FormatterFechaHora(sic.util.FormatterFechaHora) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) ArrayList(java.util.ArrayList) Caja(sic.modelo.Caja) QCaja(sic.modelo.QCaja) EstadoCaja(sic.modelo.EstadoCaja) EntityNotFoundException(javax.persistence.EntityNotFoundException) Date(java.util.Date) LocalDate(java.time.LocalDate) BusinessServiceException(sic.service.BusinessServiceException) QCaja(sic.modelo.QCaja) BooleanBuilder(com.querydsl.core.BooleanBuilder) Sort(org.springframework.data.domain.Sort)

Example 8 with BooleanBuilder

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

the class PathBuilderTest method getByExample.

@SuppressWarnings("unchecked")
private <T> BooleanBuilder getByExample(T entity) {
    PathBuilder<T> entityPath = new PathBuilder<T>((Class<T>) entity.getClass(), "entity");
    BooleanBuilder conditions = new BooleanBuilder();
    Map<String, Object> beanMap = new BeanMap(entity);
    for (Map.Entry<String, Object> entry : beanMap.entrySet()) {
        if (!entry.getKey().equals("class")) {
            if (entry.getValue() != null) {
                conditions.and(entityPath.get(entry.getKey()).eq(entry.getValue()));
            }
        }
    }
    return conditions;
}
Also used : BeanMap(com.querydsl.core.util.BeanMap) BooleanBuilder(com.querydsl.core.BooleanBuilder) BeanMap(com.querydsl.core.util.BeanMap) Map(java.util.Map)

Example 9 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 10 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)

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