AdmMono/src/com/rjconsultores/ventaboletos/dao/hibernate/AsientoExclusivoHibernateDA...

55 lines
1.7 KiB
Java

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.rjconsultores.ventaboletos.dao.hibernate;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.SQLQuery;
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.AsientoExclusivoDAO;
import com.rjconsultores.ventaboletos.entidad.AsientoExclusivo;
import com.rjconsultores.ventaboletos.entidad.Corrida;
/**
*
* @author walace
*/
@Repository("asientoExclusivoDAO")
public class AsientoExclusivoHibernateDAO extends GenericHibernateDAO<AsientoExclusivo, Integer>
implements AsientoExclusivoDAO {
@Autowired
public AsientoExclusivoHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) {
setSessionFactory(factory);
}
@Override
public List<AsientoExclusivo> obtenerTodos() {
Criteria c = getSession().createCriteria(getPersistentClass());
c.add(Restrictions.eq("activo", Boolean.TRUE));
return c.list();
}
@Override
public void borrarByCorrida(Corrida corrida) {
StringBuilder sQuery = new StringBuilder("DELETE FROM ASIENTO_EXCLUSIVO 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();
}
}