/*
 * 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.CategoriaTipoPtoVtaDAO;
import com.rjconsultores.ventaboletos.entidad.CategoriaTipoPtoVta;
import com.rjconsultores.ventaboletos.entidad.TipoPuntoVenta;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.Query;
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 Desenvolvimento
 */
@Repository("categoriaTipoPtoVtaDAO")
public class CategoriaTipoPtoVtaHibernateDAO extends GenericHibernateDAO<CategoriaTipoPtoVta, Integer>
        implements CategoriaTipoPtoVtaDAO {

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

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

        return c.list();
    }

    public List<CategoriaTipoPtoVta> buscarPorPuntoVenta(TipoPuntoVenta tipoPuntoVenta) {
        Criteria c = getSession().createCriteria(getPersistentClass());
        c.add(Restrictions.eq(ACTIVO, Boolean.TRUE));
        c.add(Restrictions.eq("tipoPuntoVenta", tipoPuntoVenta));

        return c.list();
    }

    public void borrarFisico(CategoriaTipoPtoVta cd) {

        String hql = " delete from CategoriaTipoPtoVta where categoriatipoptovtaId = " + cd.getCategoriatipoptovtaId();
        Query sq = getSession().createQuery(hql);
        sq.executeUpdate();

    }
}
