/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.rjconsultores.ventaboletos.dao.hibernate;

import com.rjconsultores.ventaboletos.dao.RedondeoDAO;
import com.rjconsultores.ventaboletos.entidad.Redondeo;
import java.math.BigDecimal;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

/**
 *
 * @author Administrador
 */
@Repository("redondeoDAO")
public class RedondeoHibernateDAO extends GenericHibernateDAO<Redondeo, Integer>
        implements RedondeoDAO {

    @Autowired
    public RedondeoHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) {
        setSessionFactory(factory);
    }

    @Override
    public List<Redondeo> obtenerTodos() {
        Criteria c = getSession().createCriteria(getPersistentClass());
        c.add(Restrictions.eq(ACTIVO, Boolean.TRUE));

        return c.list();
    }

    public List<Redondeo> buscar(BigDecimal valorInicial, BigDecimal valorFinal,
            BigDecimal valorRedondeo) {
        Criteria c = getSession().createCriteria(getPersistentClass());
        c.add(Restrictions.eq(ACTIVO, Boolean.TRUE));

        c.add(Restrictions.eq("valorinicial", valorInicial));
        c.add(Restrictions.eq("valorfinal", valorFinal));
        c.add(Restrictions.eq("valorredondeo", valorRedondeo));

        return c.list();
    }

    public List<Redondeo> buscar(BigDecimal valorInicial, BigDecimal valorFinal) {
          Criteria c = getSession().createCriteria(getPersistentClass());
        c.add(Restrictions.eq(ACTIVO, Boolean.TRUE));

        c.add(Restrictions.ge("valorinicial", valorInicial));
        c.add(Restrictions.le("valorfinal", valorFinal));
        
        return c.list();
    }
}
