Example usage for org.hibernate.criterion Restrictions ge

List of usage examples for org.hibernate.criterion Restrictions ge

Introduction

In this page you can find the example usage for org.hibernate.criterion Restrictions ge.

Prototype

public static SimpleExpression ge(String propertyName, Object value) 

Source Link

Document

Apply a "greater than or equal" constraint to the named property

Usage

From source file:co.com.codesoftware.logic.ProductoLogic.java

/**
 * Funcion con la cual busco el//  ww  w  . ja  v a 2s .  c  om
 *
 * @param idDska
 * @param idSede
 * @param fechaIni
 * @param fechaFin
 * @return
 */
public List<KardexProductoEntity> buscaKardexProducto(Integer idDska, Integer idSede, Date fechaIni,
        Date fechaFin) {
    List<KardexProductoEntity> rta = null;
    try {
        initOperation();
        Criteria crit = sesion.createCriteria(KardexProductoEntity.class).createAlias("producto", "prod");
        crit.add(Restrictions.eq("prod.id", idDska)).setFetchMode("sede", FetchMode.JOIN)
                .setFetchMode("producto", FetchMode.JOIN).setFetchMode("usuario", FetchMode.JOIN)
                .setFetchMode("usuario.persona", FetchMode.JOIN).setFetchMode("usuario.sede", FetchMode.JOIN)
                .setFetchMode("usuario.idPerfil", FetchMode.JOIN).setFetchMode("movInv", FetchMode.JOIN);
        crit.addOrder(Order.desc("id"));
        if (fechaIni != null && fechaFin == null) {
            crit.add(Restrictions.ge("fecha", fechaIni));
        } else if (fechaIni == null && fechaFin != null) {
            crit.add(Restrictions.lt("fecha", fechaFin));
        } else if (fechaIni != null && fechaFin != null) {
            crit.add(Restrictions.between("fecha", fechaIni, fechaFin));
        }
        if (idSede != -1) {
            crit.createAlias("sede", "sed").add(Restrictions.eq("sed.id", idSede));
        }
        rta = crit.list();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return rta;
}

From source file:co.com.codesoftware.logic.productos.PedidosLogic.java

/**
 * Consulta de pedidos por los filtros de fecha, usuario y estado
 *
 * @param estado//from  w w w.j  a va2s. co  m
 * @param idUsuario
 * @param fInicial
 * @param fFinal
 * @return
 */
public List<PedidoEntity> consultaPedidoXFiltros(String estado, long idUsuario, Date fInicial, Date fFinal) {
    List<PedidoEntity> respuesta = null;
    try {
        initOperation();
        Criteria crit = sesion.createCriteria(PedidoEntity.class).createAlias("usuario", "us")
                .add(Restrictions.ge("fecha", fInicial)).add(Restrictions.lt("fecha", fFinal))
                //.add(Restrictions.between("fecha", fInicial, fFinal))
                .add(Restrictions.eq("us.id", idUsuario));
        if (!"".equalsIgnoreCase(estado)) {
            crit.add(Restrictions.eq("estado", estado));
        }
        respuesta = crit.list();

    } catch (Exception e) {
        e.printStackTrace();
    }
    return respuesta;
}

From source file:co.com.codesoftware.logica.importacion.ImportacionLogica.java

/**
 * metodo que consulta las importaciones en un rango de fechas
 *
 * @param fechaInicial//from   w  w  w. ja  v  a2s  .  co  m
 * @param fechaFinal
 * @return
 */
public List<ImportacionEntity> consultaImportaciones(Date fechaInicial, Date fechaFinal) {
    List<ImportacionEntity> rta = null;
    try {
        this.initOperation();

        Criteria crit = sesion.createCriteria(ImportacionEntity.class);
        if (fechaInicial != null && fechaFinal != null) {
            fechaFinal.setHours(23);
            fechaFinal.setMinutes(59);
            fechaFinal.setSeconds(59);
            crit.add(Restrictions.ge("fechaCrea", fechaInicial)).add(Restrictions.lt("fechaCrea", fechaFinal));
        }
        crit.addOrder(Order.asc("estado"));
        crit.addOrder(Order.desc("id"));
        rta = crit.list();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return rta;
}

From source file:co.com.codesoftware.logica.inventario.PedidoLogica.java

/**
* Consulta de pedidos por los filtros de fecha, usuario y estado
*
* @param estado/*from ww  w  .ja v  a 2  s .c o m*/
* @param idUsuario
* @param fInicial
* @param fFinal
* @return
*/
public List<PedidoEntity> consultaPedidoXFiltros(String estado, Integer idUsuario, Date fInicial, Date fFinal) {
    List<PedidoEntity> respuesta = null;
    try {
        initOperation();
        Criteria crit = sesion.createCriteria(PedidoEntity.class).createAlias("usuario", "us")
                .add(Restrictions.ge("fecha", fInicial)).add(Restrictions.lt("fecha", fFinal))
                .setFetchMode("sede", FetchMode.JOIN).setFetchMode("usuario", FetchMode.JOIN)
                .setFetchMode("cliente", FetchMode.JOIN).setFetchMode("usuario.persona", FetchMode.JOIN)
                .setFetchMode("usuario.perfil", FetchMode.JOIN)
                //.add(Restrictions.between("fecha", fInicial, fFinal))
                .add(Restrictions.eq("us.id", idUsuario));
        if (!"".equalsIgnoreCase(estado)) {
            crit.add(Restrictions.eq("estado", estado));
        }
        respuesta = crit.list();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return respuesta;
}

From source file:co.com.codesoftware.logica.inventario.SolicitudLogica.java

/**
 * metodo que consulta las solicitudes por los filtros seleccionados
 *
 * @param fechaInicial//w w w.  ja v  a 2  s  .  c  o m
 * @param fechaFinal
 * @param estado
 * @param usuario
 * @param sede
 * @return
 */
public List<SolicitudEntity> consultaSolicitudesXFiltro(Date fechaInicial, Date fechaFinal, String estado,
        Integer usuario, Integer sede) {
    System.out.println(fechaInicial);
    System.out.println(fechaFinal);
    System.out.println(estado);
    System.out.println(sede);
    System.out.println(usuario);
    List<SolicitudEntity> respuesta = null;
    try {
        initOperation();
        Criteria crit = sesion.createCriteria(SolicitudEntity.class);
        if (fechaInicial != null && fechaFinal != null) {
            crit.add(Restrictions.ge("fecha", fechaInicial));
            fechaFinal.setHours(23);
            fechaFinal.setMinutes(59);
            fechaFinal.setSeconds(59);
            crit.add(Restrictions.lt("fecha", fechaFinal));
        }
        if (estado != null && !"".equalsIgnoreCase(estado)) {
            crit.add(Restrictions.eq("estado", estado));
        }
        if (usuario != null && usuario != 0) {
            crit.createAlias("usuario", "usu").add(Restrictions.eq("usu.id", usuario));
        }
        if (sede != null && sede != 0) {
            crit.createAlias("sede", "sede").add(Restrictions.eq("sede.id", sede));
        }
        crit.addOrder(Order.desc("id"));
        respuesta = crit.setFetchMode("sede", FetchMode.JOIN).setFetchMode("usuario", FetchMode.JOIN).list();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return respuesta;
}

From source file:com.abssh.util.GenericDao.java

License:Apache License

/**
 * ??Criterion,.//  ww w.  j  av  a  2 s  .  c  om
 */
protected Criterion buildPropertyFilterCriterion(final String propertyName, final Object[] propertyValue,
        final MatchType matchType) {
    Assert.hasText(propertyName, "propertyName should not be null!");
    Criterion criterion = null;
    try {
        // ?MatchTypecriterion
        if (MatchType.EQ.equals(matchType)) {
            criterion = Restrictions.eq(propertyName, propertyValue[0]);
        } else if (MatchType.LIKE.equals(matchType)) {
            criterion = Restrictions.like(propertyName, (String) propertyValue[0], MatchMode.ANYWHERE);
        } else if (MatchType.ELIKE.equals(matchType)) {
            criterion = Restrictions.like(propertyName, (String) propertyValue[0], MatchMode.END);
        } else if (MatchType.SLIKE.equals(matchType)) {
            criterion = Restrictions.like(propertyName, (String) propertyValue[0], MatchMode.START);
        } else if (MatchType.LE.equals(matchType)) {
            criterion = Restrictions.le(propertyName, propertyValue[0]);
        } else if (MatchType.LT.equals(matchType)) {
            criterion = Restrictions.lt(propertyName, propertyValue[0]);
        } else if (MatchType.GE.equals(matchType)) {
            criterion = Restrictions.ge(propertyName, propertyValue[0]);
        } else if (MatchType.GT.equals(matchType)) {
            criterion = Restrictions.gt(propertyName, propertyValue[0]);
        } else if (MatchType.NE.equals(matchType)) {
            criterion = Restrictions.ne(propertyName, propertyValue[0]);
        } else if (MatchType.ISNULL.equals(matchType)) {
            criterion = Restrictions.isNull(propertyName);
        } else if (MatchType.ISNOTNULL.equals(matchType)) {
            criterion = Restrictions.isNotNull(propertyName);
        } else if (MatchType.ISEMPTY.equals(matchType)) {
            criterion = Restrictions.isEmpty(propertyName);
        } else if (MatchType.ISNOTEMPTY.equals(matchType)) {
            criterion = Restrictions.isNotEmpty(propertyName);
        } else if (MatchType.IN.equals(matchType)) {
            criterion = Restrictions.in(propertyName, propertyValue);
        }
    } catch (Exception e) {
        throw ReflectionUtils.convertReflectionExceptionToUnchecked(e);
    }
    return criterion;
}

From source file:com.abssh.util.GenericDao.java

License:Apache License

/**
 * ??//w  w  w .ja  v a2 s .  co  m
 */
private Criterion getCriterion(String propertyName, Object[] propertyValue, MatchType matchType) {
    Criterion criterion = null;
    try {
        // ?MatchTypecriterion
        if (MatchType.EQ.equals(matchType)) {
            criterion = Restrictions.eq(propertyName, propertyValue[0]);
        } else if (MatchType.LIKE.equals(matchType)) {
            criterion = RestrictionsUtils.ilike(propertyName, String.valueOf(propertyValue[0]),
                    MatchMode.ANYWHERE);
        } else if (MatchType.ELIKE.equals(matchType)) {
            criterion = RestrictionsUtils.ilike(propertyName, (String) propertyValue[0], MatchMode.END);
        } else if (MatchType.SLIKE.equals(matchType)) {
            criterion = RestrictionsUtils.ilike(propertyName, (String) propertyValue[0], MatchMode.START);
        } else if (MatchType.LE.equals(matchType)) {
            criterion = Restrictions.le(propertyName, propertyValue[0]);
        } else if (MatchType.LT.equals(matchType)) {
            criterion = Restrictions.lt(propertyName, propertyValue[0]);
        } else if (MatchType.GE.equals(matchType)) {
            criterion = Restrictions.ge(propertyName, propertyValue[0]);
        } else if (MatchType.GT.equals(matchType)) {
            criterion = Restrictions.gt(propertyName, propertyValue[0]);
        } else if (MatchType.NE.equals(matchType)) {
            criterion = Restrictions.ne(propertyName, propertyValue[0]);
        } else if (MatchType.ISNULL.equals(matchType)) {
            criterion = Restrictions.isNull(propertyName);
        } else if (MatchType.ISNOTNULL.equals(matchType)) {
            criterion = Restrictions.isNotNull(propertyName);
        } else if (MatchType.ISEMPTY.equals(matchType)) {
            criterion = Restrictions.isEmpty(propertyName);
        } else if (MatchType.ISNOTEMPTY.equals(matchType)) {
            criterion = Restrictions.isNotEmpty(propertyName);
        } else if (MatchType.IN.equals(matchType)) {
            criterion = Restrictions.in(propertyName, propertyValue);
        } else if (MatchType.LEN.equals(matchType)) {
            criterion = Restrictions.le(propertyName, propertyValue[0]);
        }
    } catch (Exception e) {
        throw ReflectionUtils.convertReflectionExceptionToUnchecked(e);
    }
    return criterion;
}

From source file:com.algoTrader.CriteriaSearch.java

/**
 * Adds an <code>Restrictions</code> to a <code>Criteria</code>.
 *
 * @param criteria/*from   w ww. j a  v a  2s.  c  o  m*/
 * @param parameterName
 * @param parameterValue
 * @param comparator
 * @param matchMode
 */
private void addExpression(Criteria criteria, String parameterName, Object parameterValue, int comparator,
        MatchMode matchMode) {
    switch (comparator) {
    case SearchParameter.NOT_NULL_COMPARATOR: {
        criteria.add(Restrictions.isNotNull(parameterName));
        break;
    }
    case SearchParameter.NULL_COMPARATOR: {
        criteria.add(Restrictions.isNull(parameterName));
        break;
    }
    case SearchParameter.EMPTY_COMPARATOR: {
        criteria.add(Restrictions.isEmpty(parameterName));
        break;
    }
    case SearchParameter.NOT_EMPTY_COMPARATOR: {
        criteria.add(Restrictions.isNotEmpty(parameterName));
        break;
    }
    default: {
        if (parameterValue != null) {
            switch (comparator) {
            case SearchParameter.LIKE_COMPARATOR: {
                if ((matchMode != null) && (parameterValue instanceof String)) {
                    criteria.add(Restrictions.like(parameterName, (String) parameterValue, matchMode));
                } else {
                    criteria.add(Restrictions.like(parameterName, parameterValue));
                }
                break;
            }
            case SearchParameter.NOT_LIKE_COMPARATOR: {
                SimpleExpression expression;
                if ((matchMode != null) && (parameterValue instanceof String)) {
                    expression = Restrictions.like(parameterName, (String) parameterValue, matchMode);
                } else {
                    expression = Restrictions.like(parameterName, parameterValue);
                }
                criteria.add(Restrictions.not(expression));
                break;
            }
            case SearchParameter.INSENSITIVE_LIKE_COMPARATOR: {
                if ((matchMode != null) && (parameterValue instanceof String)) {
                    criteria.add(Restrictions.ilike(parameterName, (String) parameterValue, matchMode));
                } else {
                    criteria.add(Restrictions.ilike(parameterName, parameterValue));
                }
                break;
            }
            case SearchParameter.NOT_INSENSITIVE_LIKE_COMPARATOR: {
                Criterion criterion;
                if ((matchMode != null) && (parameterValue instanceof String)) {
                    criterion = Restrictions.ilike(parameterName, (String) parameterValue, matchMode);
                } else {
                    criterion = Restrictions.ilike(parameterName, parameterValue);
                }
                criteria.add(Restrictions.not(criterion));
                break;
            }
            case SearchParameter.EQUAL_COMPARATOR: {
                criteria.add(Restrictions.eq(parameterName, parameterValue));
                break;
            }
            case SearchParameter.GREATER_THAN_OR_EQUAL_COMPARATOR: {
                criteria.add(Restrictions.ge(parameterName, parameterValue));
                break;
            }
            case SearchParameter.GREATER_THAN_COMPARATOR: {
                criteria.add(Restrictions.gt(parameterName, parameterValue));
                break;
            }
            case SearchParameter.LESS_THAN_OR_EQUAL_COMPARATOR: {
                criteria.add(Restrictions.le(parameterName, parameterValue));
                break;
            }
            case SearchParameter.LESS_THAN_COMPARATOR: {
                criteria.add(Restrictions.lt(parameterName, parameterValue));
                break;
            }
            case SearchParameter.IN_COMPARATOR: {
                if (parameterValue instanceof Collection) {
                    criteria.add(Restrictions.in(parameterName, (Collection) parameterValue));
                }
                break;
            }
            case SearchParameter.NOT_IN_COMPARATOR: {
                if (parameterValue instanceof Collection) {
                    criteria.add(Restrictions.not(Restrictions.in(parameterName, (Collection) parameterValue)));
                }
                break;
            }
            case SearchParameter.NOT_EQUAL_COMPARATOR: {
                criteria.add(Restrictions.ne(parameterName, parameterValue));
                break;
            }
            }
        } else {
            criteria.add(Restrictions.isNull(parameterName));
        }
    }
    }
}

From source file:com.algoTrader.CriteriaSearch.java

/**
 * Adds an <code>Restrictions</code> to a <code>Criteria</code>. The given <code>parameterValues</code>
 * represents either an array of <code>String</code> or another object. The different values in the
 * array are added to a disjunction or conjunction which is connected with logical and to the other criteria of the
 * search./*  ww w .  j a v a  2 s . com*/
 *
 * @param criteria
 * @param parameterName
 * @param parameterValues
 * @param searchIfNull
 * @param comparator
 * @param matchMode
 */
private void addExpression(Criteria criteria, String parameterName, Object[] parameterValues, int comparator,
        MatchMode matchMode) {
    if (parameterValues != null) {
        Disjunction disjunction = null;
        Conjunction conjunction = null;
        switch (comparator) {
        case SearchParameter.LIKE_COMPARATOR: {
            disjunction = Restrictions.disjunction();
            if ((matchMode != null) && (parameterValues instanceof String[])) {
                String[] stringParameterValues = (String[]) parameterValues;
                for (int index = 0; index < parameterValues.length; index++) {
                    if (stringParameterValues[index] != null) {
                        disjunction
                                .add(Restrictions.like(parameterName, stringParameterValues[index], matchMode));
                    } else {
                        disjunction.add(Restrictions.isNull(parameterName));
                    }
                }
            } else {
                for (int index = 0; index < parameterValues.length; index++) {
                    if (parameterValues[index] != null) {
                        disjunction.add(Restrictions.like(parameterName, parameterValues[index]));
                    } else {
                        disjunction.add(Restrictions.isNull(parameterName));
                    }
                }
            }
            break;
        }
        case SearchParameter.INSENSITIVE_LIKE_COMPARATOR: {
            disjunction = Restrictions.disjunction();
            if ((matchMode != null) && (parameterValues instanceof String[])) {
                String[] stringParameterValues = (String[]) parameterValues;
                for (int index = 0; index < parameterValues.length; index++) {
                    if (stringParameterValues[index] != null) {
                        disjunction.add(
                                Restrictions.ilike(parameterName, stringParameterValues[index], matchMode));
                    } else {
                        disjunction.add(Restrictions.isNull(parameterName));
                    }
                }
            } else {
                for (int index = 0; index < parameterValues.length; index++) {
                    if (parameterValues[index] != null) {
                        disjunction.add(Restrictions.ilike(parameterName, parameterValues[index]));
                    } else {
                        disjunction.add(Restrictions.isNull(parameterName));
                    }
                }
            }
            break;
        }
        case SearchParameter.EQUAL_COMPARATOR: {
            disjunction = Restrictions.disjunction();
            for (int index = 0; index < parameterValues.length; index++) {
                if (parameterValues[index] != null) {
                    disjunction.add(Restrictions.eq(parameterName, parameterValues[index]));
                } else {
                    disjunction.add(Restrictions.isNull(parameterName));
                }
            }
            break;
        }
        case SearchParameter.GREATER_THAN_OR_EQUAL_COMPARATOR: {
            disjunction = Restrictions.disjunction();
            for (int index = 0; index < parameterValues.length; index++) {
                if (parameterValues[index] != null) {
                    disjunction.add(Restrictions.ge(parameterName, parameterValues[index]));
                } else {
                    disjunction.add(Restrictions.isNull(parameterName));
                }
            }
            break;
        }
        case SearchParameter.GREATER_THAN_COMPARATOR: {
            disjunction = Restrictions.disjunction();
            for (int index = 0; index < parameterValues.length; index++) {
                if (parameterValues[index] != null) {
                    disjunction.add(Restrictions.gt(parameterName, parameterValues[index]));
                } else {
                    disjunction.add(Restrictions.isNull(parameterName));
                }
            }
            break;
        }
        case SearchParameter.LESS_THAN_OR_EQUAL_COMPARATOR: {
            disjunction = Restrictions.disjunction();
            for (int index = 0; index < parameterValues.length; index++) {
                if (parameterValues[index] != null) {
                    disjunction.add(Restrictions.le(parameterName, parameterValues[index]));
                } else {
                    disjunction.add(Restrictions.isNull(parameterName));
                }
            }
            break;
        }
        case SearchParameter.LESS_THAN_COMPARATOR: {
            disjunction = Restrictions.disjunction();
            for (int index = 0; index < parameterValues.length; index++) {
                if (parameterValues[index] != null) {
                    disjunction.add(Restrictions.lt(parameterName, parameterValues[index]));
                } else {
                    disjunction.add(Restrictions.isNull(parameterName));
                }
            }
            break;
        }
        case SearchParameter.IN_COMPARATOR: {
            criteria.add(Restrictions.in(parameterName, parameterValues));
            break;
        }
        case SearchParameter.NOT_IN_COMPARATOR: {
            criteria.add(Restrictions.not(Restrictions.in(parameterName, parameterValues)));
            break;
        }
        case SearchParameter.NOT_EQUAL_COMPARATOR: {
            conjunction = Restrictions.conjunction();
            for (int index = 0; index < parameterValues.length; index++) {
                if (parameterValues[index] != null) {
                    conjunction.add(Restrictions.ne(parameterName, parameterValues[index]));
                } else {
                    conjunction.add(Restrictions.isNotNull(parameterName));
                }
            }
            break;
        }
        }

        if (disjunction != null) {
            criteria.add(disjunction);
        }
        if (conjunction != null) {
            criteria.add(conjunction);
        }
    } else {
        switch (comparator) {
        case SearchParameter.EMPTY_COMPARATOR: {
            criteria.add(Restrictions.isEmpty(parameterName));
            break;
        }
        case SearchParameter.NOT_EMPTY_COMPARATOR: {
            criteria.add(Restrictions.isNotEmpty(parameterName));
            break;
        }
        default: {
            criteria.add(Restrictions.isNull(parameterName));
        }
        }
    }
}

From source file:com.apt.facade.AssignmentFacade.java

public List<Assignment> getAssignmentList(AssignmentFinder finder, int page, int recordPerPage) {
    List<Assignment> lst = new ArrayList<>();

    Session session = null;/*from w  ww . j  av a2s.  c o m*/
    Transaction trans = null;

    try {
        session = HibernateUtil.getSessionFactory().getCurrentSession();
        trans = session.beginTransaction();

        Criteria crit = session.createCriteria(Assignment.class);

        crit.add(Restrictions.sqlRestriction("1=1"));
        if (finder.getAssignmentId() != null) {
            crit.add(Restrictions.and(Restrictions.eq("assignmentId", finder.getAssignmentId())));
        }
        if (finder.getAssignmentName() != null) {
            crit.add(Restrictions
                    .and(Restrictions.ilike("assignmentName", "%" + finder.getAssignmentName() + "%")));
        }
        if (finder.getBatch() != null) {
            crit.add(Restrictions.and(Restrictions.eq("batch", finder.getBatch())));
        }
        if (finder.getSubject() != null) {
            crit.add(Restrictions.and(Restrictions.eq("subject", finder.getSubject())));
        }
        if (finder.getStatus() != null) {
            crit.add(Restrictions.and(Restrictions.eq("status", finder.getStatus())));
        }
        if (finder.getStarttime() != null) {
            crit.add(Restrictions.and(Restrictions.ge("startTime", finder.getStarttime())));
        }
        if (finder.getEndtime() != null) {
            crit.add(Restrictions.and(Restrictions.le("endTime", finder.getEndtime())));
        }
        crit.setFirstResult((page - 1) * recordPerPage);
        crit.setMaxResults(recordPerPage);
        lst = crit.list();
        trans.commit();

    } catch (Exception e) {
        e.printStackTrace();
        if (trans != null) {
            trans.rollback();
        }
    } finally {
        if (session != null && session.isConnected()) {
            session.close();
        }
    }

    return lst;
}