/*
 * 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.ConvenioDAO;
import com.rjconsultores.ventaboletos.entidad.Convenio;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Order;
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("convenioDAO")
public class ConvenioHibernateDAO extends GenericHibernateDAO<Convenio, Integer>
        implements ConvenioDAO {

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

    @Override
    public List<Convenio> obtenerTodos() {
        Criteria c = getSession().createCriteria(getPersistentClass());
        c.add(Restrictions.eq(ACTIVO, Boolean.TRUE));
        c.addOrder(Order.asc("descconvenio"));

        return c.list();
    }

    public List<Convenio> buscar(String descconvenio, String cveconvenio) {
        Criteria c = getSession().createCriteria(getPersistentClass());
        c.add(Restrictions.eq(ACTIVO, Boolean.TRUE));
        c.add(Restrictions.or(Restrictions.eq("descconvenio", descconvenio), Restrictions.eq("cveconvenio", cveconvenio)));

        c.addOrder(Order.asc("descconvenio"));

        return c.list();
    }
}
