/*
 * 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.PtovtaEmpresaDAO;
import com.rjconsultores.ventaboletos.entidad.PtovtaEmpresa;
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("ptovtaEmpresaDAO")
public class PtovtaEmpresaHibernateDAO extends GenericHibernateDAO<PtovtaEmpresa, Integer>
        implements PtovtaEmpresaDAO {

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

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

        return c.list();
    }

    public List<PtovtaEmpresa> buscar(PtovtaEmpresa ptovtaEmpresa) {
        Criteria c = getSession().createCriteria(getPersistentClass());
        c.add(Restrictions.eq(ACTIVO, Boolean.TRUE));

        c.add(Restrictions.eq("empresa", ptovtaEmpresa.getEmpresa()));
        c.add(Restrictions.eq("puntoVenta", ptovtaEmpresa.getPuntoVenta()));

        return c.list();
    }

    public void borrarFisico(PtovtaEmpresa pto) {
        String hql = " delete from PtovtaEmpresa "
                + " where ptovtaempresaId = " + pto.getPtovtaempresaId();
        Query sq = getSession().createQuery(hql);
        sq.executeUpdate();
    }
}
