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.AuditServiceDAO;
import com.rjconsultores.ventaboletos.entidad.AuditService;

@Repository("auditServiceDAO")
public class AuditServiceHibernateDAO extends GenericHibernateDAO<AuditService, Long>
		implements AuditServiceDAO {
	
	@Autowired
	 public AuditServiceHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) {
		 setSessionFactory(factory);
	 }

	@Override
	public AuditService carregarService(AuditService auditService) {
		AuditService service = null;
		
		Criteria criteriaService = getSession().createCriteria(AuditService.class);
		
		if (auditService.getFuncionSistema() != null && auditService.getFuncionSistema().getDescruta() != null) {
			criteriaService.add(Restrictions.eq("funcionSistema", auditService.getFuncionSistema().getDescruta()));			
			service = (AuditService) criteriaService.uniqueResult();
		}
		
		return service;
	}
}
