B23 - Não permitir excluir uma empresa quando tiver cadastros associados a ela (fixed bug #5253)
git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Model/trunk/modelWeb@35270 d1611594-4594-4d17-8e1d-87c2c4800839master
parent
0bc35b3779
commit
c13899dc84
|
@ -9,6 +9,7 @@ import java.util.List;
|
|||
|
||||
import org.apache.commons.lang.math.NumberUtils;
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.criterion.Disjunction;
|
||||
import org.hibernate.criterion.Projections;
|
||||
|
@ -49,12 +50,13 @@ public class EsquemaCorridaHibernateDAO extends GenericHibernateDAO<EsquemaCorri
|
|||
}
|
||||
|
||||
public List<EsquemaCorrida> buscarPorEmpresaCorrida(Empresa empresa){
|
||||
Criteria c = getSession().createCriteria(getPersistentClass());
|
||||
|
||||
c.add(Restrictions.eq("empresa", empresa));
|
||||
c.add(Restrictions.eq("activo", Boolean.TRUE));
|
||||
|
||||
return c.list();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("select * from Esquema_Corrida where empresacorrida_id = :empresaId and activo = 1" );
|
||||
|
||||
Query qry = getSession().createSQLQuery(sb.toString());
|
||||
qry.setInteger("empresaId", empresa.getEmpresaId());
|
||||
|
||||
return qry.list();
|
||||
}
|
||||
|
||||
public List<EsquemaCorrida> buscarPorEsquemaOperacional(
|
||||
|
|
|
@ -7,6 +7,7 @@ package com.rjconsultores.ventaboletos.dao.hibernate;
|
|||
import java.util.List;
|
||||
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.criterion.Restrictions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -31,9 +32,12 @@ public class RutaEmpresaHibernateDAO extends GenericHibernateDAO<RutaEmpresa, In
|
|||
}
|
||||
|
||||
public List<RutaEmpresa> obtenerPorEmpresa(Empresa empresa){
|
||||
Criteria c = getSession().createCriteria(getPersistentClass());
|
||||
c.add(Restrictions.eq("activo", Boolean.TRUE));
|
||||
c.add(Restrictions.eq("empresa", empresa));
|
||||
return c.list();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("select * from Ruta_Empresa where empresa_Id = :empresaId and activo = 1" );
|
||||
|
||||
Query qry = getSession().createSQLQuery(sb.toString());
|
||||
qry.setInteger("empresaId", empresa.getEmpresaId());
|
||||
|
||||
return qry.list();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -76,8 +76,8 @@ public class EmpresaServiceImpl implements EmpresaService {
|
|||
|
||||
@Transactional
|
||||
public void borrar(Empresa entidad) throws RegistroConDependenciaException {
|
||||
if ((rutaEmpresaDAO.obtenerPorEmpresa(entidad).size() <= 0) &&
|
||||
(esquemaCorridaDAO.buscarPorEmpresaCorrida(entidad).size() <= 0)){
|
||||
if ((rutaEmpresaDAO.obtenerPorEmpresa(entidad).size() > 0) ||
|
||||
(esquemaCorridaDAO.buscarPorEmpresaCorrida(entidad).size() > 0)){
|
||||
throw new RegistroConDependenciaException();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue