package com.rjconsultores.ventaboletos.dao.hibernate;

import org.hibernate.SQLQuery;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

import com.rjconsultores.ventaboletos.dao.IntegracaoTotvsDAO;
import com.rjconsultores.ventaboletos.entidad.Corrida;
import com.rjconsultores.ventaboletos.entidad.IntegracaoTotvs;

@Repository("integracaoTotvsDAO")
public class IntegracaoTotvsHibernateDAO extends GenericHibernateDAO<IntegracaoTotvs, Integer>	implements IntegracaoTotvsDAO {

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

	@Override
	public void borrarByCorrida(Corrida corrida) {

			StringBuilder sQuery = new StringBuilder("update INTEGRACAO_TOTVS_CORRIDA set integradototvs = 0  WHERE  corrida_Id = :corridaId AND TRUNC(feccorrida) = :feccorrida ");
			SQLQuery qrUpdate = getSession().createSQLQuery(sQuery.toString());
			
			qrUpdate.setParameter("feccorrida", corrida.getId().getFeccorrida());
			qrUpdate.setParameter("corridaId", corrida.getId().getCorridaId());
			qrUpdate.executeUpdate();
			
		
	}
}

