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-87c2c4800839
master
leonardo 2014-05-05 17:59:45 +00:00
parent 0bc35b3779
commit c13899dc84
3 changed files with 18 additions and 12 deletions

View File

@ -9,6 +9,7 @@ import java.util.List;
import org.apache.commons.lang.math.NumberUtils; import org.apache.commons.lang.math.NumberUtils;
import org.hibernate.Criteria; import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.SessionFactory; import org.hibernate.SessionFactory;
import org.hibernate.criterion.Disjunction; import org.hibernate.criterion.Disjunction;
import org.hibernate.criterion.Projections; import org.hibernate.criterion.Projections;
@ -49,12 +50,13 @@ public class EsquemaCorridaHibernateDAO extends GenericHibernateDAO<EsquemaCorri
} }
public List<EsquemaCorrida> buscarPorEmpresaCorrida(Empresa empresa){ public List<EsquemaCorrida> buscarPorEmpresaCorrida(Empresa empresa){
Criteria c = getSession().createCriteria(getPersistentClass()); StringBuilder sb = new StringBuilder();
sb.append("select * from Esquema_Corrida where empresacorrida_id = :empresaId and activo = 1" );
c.add(Restrictions.eq("empresa", empresa)); Query qry = getSession().createSQLQuery(sb.toString());
c.add(Restrictions.eq("activo", Boolean.TRUE)); qry.setInteger("empresaId", empresa.getEmpresaId());
return c.list(); return qry.list();
} }
public List<EsquemaCorrida> buscarPorEsquemaOperacional( public List<EsquemaCorrida> buscarPorEsquemaOperacional(

View File

@ -7,6 +7,7 @@ package com.rjconsultores.ventaboletos.dao.hibernate;
import java.util.List; import java.util.List;
import org.hibernate.Criteria; import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.SessionFactory; import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions; import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -31,9 +32,12 @@ public class RutaEmpresaHibernateDAO extends GenericHibernateDAO<RutaEmpresa, In
} }
public List<RutaEmpresa> obtenerPorEmpresa(Empresa empresa){ public List<RutaEmpresa> obtenerPorEmpresa(Empresa empresa){
Criteria c = getSession().createCriteria(getPersistentClass()); StringBuilder sb = new StringBuilder();
c.add(Restrictions.eq("activo", Boolean.TRUE)); sb.append("select * from Ruta_Empresa where empresa_Id = :empresaId and activo = 1" );
c.add(Restrictions.eq("empresa", empresa));
return c.list(); Query qry = getSession().createSQLQuery(sb.toString());
qry.setInteger("empresaId", empresa.getEmpresaId());
return qry.list();
} }
} }

View File

@ -76,8 +76,8 @@ public class EmpresaServiceImpl implements EmpresaService {
@Transactional @Transactional
public void borrar(Empresa entidad) throws RegistroConDependenciaException { public void borrar(Empresa entidad) throws RegistroConDependenciaException {
if ((rutaEmpresaDAO.obtenerPorEmpresa(entidad).size() <= 0) && if ((rutaEmpresaDAO.obtenerPorEmpresa(entidad).size() > 0) ||
(esquemaCorridaDAO.buscarPorEmpresaCorrida(entidad).size() <= 0)){ (esquemaCorridaDAO.buscarPorEmpresaCorrida(entidad).size() > 0)){
throw new RegistroConDependenciaException(); throw new RegistroConDependenciaException();
} }