package com.rjconsultores.ventaboletos.dao.hibernate;

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;

import com.rjconsultores.ventaboletos.dao.HeaderEsquemaCorridaDAO;
import com.rjconsultores.ventaboletos.entidad.HeaderTabelaEsquemaCorrida;

@Repository("headerEsquemaCorridaHibernateDAO")
public class HeaderEsquemaCorridaHibernateDAO extends GenericHibernateDAO<HeaderTabelaEsquemaCorrida, Integer> implements HeaderEsquemaCorridaDAO {

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

    @Override
	public HeaderTabelaEsquemaCorrida buscarHeader() {
    	try {
    		Criteria c = getSession().createCriteria(getPersistentClass());
    		c.add(Restrictions.eq("headerEsquemaCorridaId", 1));
    		
    		c.setMaxResults(1);
    		
    		return (HeaderTabelaEsquemaCorrida) c.uniqueResult();
		} catch (Exception e) {
			return null;
		}
	}

}
