69 lines
2.2 KiB
Java
69 lines
2.2 KiB
Java
package com.rjconsultores.ventaboletos.dao.hibernate;
|
|
|
|
import java.util.Calendar;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
|
|
import org.hibernate.Criteria;
|
|
import org.hibernate.Query;
|
|
import org.hibernate.Session;
|
|
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.AbastoHistoDAO;
|
|
import com.rjconsultores.ventaboletos.entidad.AbastoCentral;
|
|
import com.rjconsultores.ventaboletos.entidad.AbastoHisto;
|
|
import com.rjconsultores.ventaboletos.entidad.Aidf;
|
|
import com.rjconsultores.ventaboletos.entidad.TipoMovimentacion;
|
|
import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado;
|
|
|
|
@Repository("abastoHistoDAO")
|
|
public class AbastoHistoHibernateDAO extends GenericHibernateDAO<AbastoHisto, Long> implements AbastoHistoDAO {
|
|
|
|
@Autowired
|
|
public AbastoHistoHibernateDAO(
|
|
@Qualifier("sessionFactory") SessionFactory factory) {
|
|
setSessionFactory(factory);
|
|
}
|
|
|
|
@Override
|
|
public List<AbastoHisto> obtenerTodos() {
|
|
Criteria c = getSession().createCriteria(getPersistentClass());
|
|
c.add(Restrictions.eq("activo", Boolean.TRUE));
|
|
|
|
return (List<AbastoHisto>)c.list();
|
|
}
|
|
|
|
@Override
|
|
public void borrarLosQueTienenAIDF(Aidf aidf){
|
|
String hql = " delete from AbastoHisto where aidf.aidfId = " + aidf.getAidfId();
|
|
Query sq = getSession().createQuery(hql);
|
|
sq.executeUpdate();
|
|
}
|
|
|
|
public void grabaHistoricoBilhetes(List<AbastoCentral> bilhetes, TipoMovimentacion tipoMovimentacion) {
|
|
Session session = getSessionFactory().getCurrentSession();
|
|
|
|
int count = 0;
|
|
|
|
for(AbastoCentral bilhete : bilhetes){
|
|
|
|
Date dataActual = Calendar.getInstance().getTime();
|
|
AbastoHisto nuevoHistorico = new AbastoHisto(bilhete, tipoMovimentacion, dataActual, true, dataActual, UsuarioLogado.getUsuarioLogado().getUsuarioId());
|
|
|
|
session.save(nuevoHistorico);
|
|
|
|
if(++count % 20 == 0){
|
|
session.flush();
|
|
session.clear();
|
|
}
|
|
}
|
|
|
|
session.flush();
|
|
session.clear();
|
|
}
|
|
}
|