Example usage for org.hibernate.criterion Restrictions lt

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

Introduction

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

Prototype

public static SimpleExpression lt(String propertyName, Object value) 

Source Link

Document

Apply a "less than" constraint to the named property

Usage

From source file:ca.myewb.controllers.common.EventList.java

License:Open Source License

public int visiblePreviousEventCount(String filter, Date fromDate) throws HibernateException {
    Criteria criteria = hibernateSession.createCriteria(EventModel.class);

    if (!currentUser.isAdmin()) {
        criteria.add(Restrictions.in("group", Permissions.visibleGroups(currentUser, true)));
    }//from  www . j  a  va 2s  . com

    criteria.add(Restrictions.lt("startDate", fromDate));
    addFilter(filter, criteria);

    criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);

    return getUniqueEventCount(criteria);
}

From source file:ch.systemsx.cisd.openbis.generic.server.dataaccess.db.search.DefaultFullTextIndexer.java

License:Apache License

private <T> Criteria createCriteriaWithRestrictedId(final FullTextSession fullTextSession, final Class<T> clazz,
        final long minId, final long maxId) {
    return createCriteria(fullTextSession, clazz).add(Restrictions.ge(ID_PROPERTY_NAME, minId))
            .add(Restrictions.lt(ID_PROPERTY_NAME, maxId));
}

From source file:cn.hxh.springside.orm.hibernate.HibernateDao.java

License:Apache License

/**
 * ??Criterion,./*from w  ww.  ja v  a  2 s . c om*/
 */
protected Criterion buildCriterion(final String propertyName, final Object propertyValue,
        final MatchType matchType) {
    AssertUtils.hasText(propertyName, "propertyName?");
    Criterion criterion = null;
    //?MatchTypecriterion
    switch (matchType) {
    case EQ:
        criterion = Restrictions.eq(propertyName, propertyValue);
        break;
    case LIKE:
        criterion = Restrictions.like(propertyName, (String) propertyValue, MatchMode.ANYWHERE);
        break;

    case LE:
        criterion = Restrictions.le(propertyName, propertyValue);
        break;
    case LT:
        criterion = Restrictions.lt(propertyName, propertyValue);
        break;
    case GE:
        criterion = Restrictions.ge(propertyName, propertyValue);
        break;
    case GT:
        criterion = Restrictions.gt(propertyName, propertyValue);
    }
    return criterion;
}

From source file:cn.newtouch.hibernate.dao.StudentDAO.java

License:Open Source License

public static void main(String[] args) {
    try {/*w  ww  .j  a v  a 2s .  co  m*/
        Session session = HibernateUtil.getSession();
        String hql = " from Student";
        List<Student> userList = session.createQuery(hql).list();
        System.out.println("=====1=======" + userList.size());
        Criteria criteria = session.createCriteria(Student.class);
        // 
        criteria.add(Restrictions.eq("name", "HZZ"));
        // map
        criteria.add(Restrictions.allEq(new HashMap<String, String>()));
        // 
        criteria.add(Restrictions.gt("id", new Long(1)));
        // 
        criteria.add(Restrictions.ge("id", new Long(1)));
        // ?
        criteria.add(Restrictions.lt("id", new Long(1)));
        // ?
        criteria.add(Restrictions.le("id", new Long(1)));
        // xxxyyy
        criteria.add(Restrictions.between("id", new Long(1), new Long(2)));
        // ?
        criteria.add(Restrictions.like("name", "H"));
        // and?
        criteria.add(Restrictions.and(Restrictions.ge("id", new Long(1)), Restrictions.ge("id", new Long(1))));
        // or?
        criteria.add(Restrictions.or(Restrictions.ge("id", new Long(1)), Restrictions.ge("id", new Long(1))));
        userList = criteria.list();
        System.out.println("=====2=======" + userList.size());
        Student student = new Student();
        student.setId(123456L);
        student.setName("hzz");
        student.setAge(14);
        save(student);

        System.out.println("OK!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");

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

    }
}

From source file:cn.newtouch.util.hibernate.HibernateDao.java

License:Apache License

/**
 * ??Criterion,.//w  w w.j  a  va  2s . c  om
 */
protected Criterion buildCriterion(final String propertyName, final Object propertyValue,
        final MatchType matchType) {
    Assert.hasText(propertyName, "propertyName?");
    Criterion criterion = null;
    // ?MatchTypecriterion
    switch (matchType) {
    case EQ:
        criterion = Restrictions.eq(propertyName, propertyValue);
        break;
    case LIKE:
        criterion = Restrictions.like(propertyName, (String) propertyValue, MatchMode.ANYWHERE);
        break;

    case LE:
        criterion = Restrictions.le(propertyName, propertyValue);
        break;
    case LT:
        criterion = Restrictions.lt(propertyName, propertyValue);
        break;
    case GE:
        criterion = Restrictions.ge(propertyName, propertyValue);
        break;
    case GT:
        criterion = Restrictions.gt(propertyName, propertyValue);
    }
    return criterion;
}

From source file:cn.newtouch.util.orm.hibernate.HibernateDao.java

License:Apache License

/**
 * ??Criterion,.//from  w ww .  j av  a2s. c o m
 */
protected Criterion buildCriterion(final String propertyName, final Object propertyValue,
        final MatchType matchType) {
    Assert.hasText(propertyName, "propertyName?");
    Criterion criterion = null;
    //?MatchTypecriterion
    switch (matchType) {
    case EQ:
        criterion = Restrictions.eq(propertyName, propertyValue);
        break;
    case LIKE:
        criterion = Restrictions.like(propertyName, (String) propertyValue, MatchMode.ANYWHERE);
        break;

    case LE:
        criterion = Restrictions.le(propertyName, propertyValue);
        break;
    case LT:
        criterion = Restrictions.lt(propertyName, propertyValue);
        break;
    case GE:
        criterion = Restrictions.ge(propertyName, propertyValue);
        break;
    case GT:
        criterion = Restrictions.gt(propertyName, propertyValue);
    }
    return criterion;
}

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

/**
 * funcion que consulta las facturas por filtros
 *
 * @param idProveedor//w  w  w  .j ava 2  s.co  m
 * @param fechaInicial
 * @param fechaFinal
 * @param estado
 * @param imagen
 * @return
 */
public List<FacturaCompraTotalEntity> consultaFacturas(Integer idProveedor, Date fechaInicial, Date fechaFinal,
        String estado, String imagen, String digitalizado) {
    List<FacturaCompraTotalEntity> lista = null;
    try {
        initOperation();
        Criteria criteria = sesion.createCriteria(FacturaCompraTotalEntity.class).setFetchMode("proveedor",
                FetchMode.JOIN);
        if (idProveedor != -1) {
            criteria.createAlias("proveedor", "pr").add(Restrictions.eq("pr.id", idProveedor));
        }
        if (fechaInicial != null && fechaFinal != null) {
            criteria.add(Restrictions.ge("fechaCreacion", fechaInicial));
            criteria.add(Restrictions.lt("fechaCreacion", fechaFinal));
        }
        if (estado != null && "".equalsIgnoreCase(estado) && "-1".equalsIgnoreCase(estado)) {
            criteria.add(Restrictions.eq("estado", estado));
        }
        if (imagen != null && "".equalsIgnoreCase(imagen) && "-1".equalsIgnoreCase(imagen)) {
            criteria.add(Restrictions.eq("rutaImagen", imagen));
        }
        if ("S".equalsIgnoreCase(digitalizado)) {
            criteria.add(Restrictions
                    .sqlRestriction(" exists (select 1 from fa_timfac where imfac_facom = facom_facom) "));
        } else if ("N".equalsIgnoreCase(digitalizado)) {
            criteria.add(Restrictions
                    .sqlRestriction(" not exists (select 1 from fa_timfac where imfac_facom = facom_facom) "));
        }
        lista = criteria.list();

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

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

/**
 * Funcion con la cual busco el/*from  w w w  .j  av  a 2  s .  c  o  m*/
 *
 * @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//ww w.  j av  a 2 s  . c  om
 * @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 .java2  s  .  c om*/
 * @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;
}