From 60aba1e0d902ec711d6cdcb1150cecd12cd4698c Mon Sep 17 00:00:00 2001 From: leonardo Date: Mon, 27 Jul 2015 20:15:37 +0000 Subject: [PATCH] fixes bug #6507 git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Model/trunk/modelWeb@46365 d1611594-4594-4d17-8e1d-87c2c4800839 --- .../ventaboletos/dao/EscolaDAO.java | 10 +++ .../dao/hibernate/EscolaHibernateDAO.java | 46 +++++++++++ .../ventaboletos/entidad/Escola.java | 82 +++++++++++++++++++ .../ventaboletos/service/EscolaService.java | 22 +++++ .../service/impl/EscolaServiceImpl.java | 69 ++++++++++++++++ 5 files changed, 229 insertions(+) create mode 100644 src/com/rjconsultores/ventaboletos/dao/EscolaDAO.java create mode 100644 src/com/rjconsultores/ventaboletos/dao/hibernate/EscolaHibernateDAO.java create mode 100644 src/com/rjconsultores/ventaboletos/entidad/Escola.java create mode 100644 src/com/rjconsultores/ventaboletos/service/EscolaService.java create mode 100644 src/com/rjconsultores/ventaboletos/service/impl/EscolaServiceImpl.java diff --git a/src/com/rjconsultores/ventaboletos/dao/EscolaDAO.java b/src/com/rjconsultores/ventaboletos/dao/EscolaDAO.java new file mode 100644 index 000000000..329c7e528 --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/dao/EscolaDAO.java @@ -0,0 +1,10 @@ +package com.rjconsultores.ventaboletos.dao; + +import java.util.List; + +import com.rjconsultores.ventaboletos.entidad.Ciudad; +import com.rjconsultores.ventaboletos.entidad.Escola; + +public interface EscolaDAO extends GenericDAO { + public List buscar(String nombescola, Ciudad ciudad); +} diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/EscolaHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/EscolaHibernateDAO.java new file mode 100644 index 000000000..052353e94 --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/EscolaHibernateDAO.java @@ -0,0 +1,46 @@ +package com.rjconsultores.ventaboletos.dao.hibernate; + +import java.util.List; + +import org.hibernate.Criteria; +import org.hibernate.SessionFactory; +import org.hibernate.criterion.Order; +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.EscolaDAO; +import com.rjconsultores.ventaboletos.entidad.Ciudad; +import com.rjconsultores.ventaboletos.entidad.Escola; + +@Repository("escolaDAO") +public class EscolaHibernateDAO extends GenericHibernateDAO + implements EscolaDAO { + + @Autowired + public EscolaHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) { + setSessionFactory(factory); + } + + @Override + public List obtenerTodos() { + Criteria c = getSession().createCriteria(getPersistentClass()); + c.add(Restrictions.eq("activo", Boolean.TRUE)); + c.addOrder(Order.asc("nombEscola")); + + return c.list(); + } + + @Override + public List buscar(String nombescola, Ciudad ciudad) { + Criteria c = getSession().createCriteria(getPersistentClass()); + c.add(Restrictions.eq("activo", Boolean.TRUE)); + c.add(Restrictions.eq("nombescola", nombescola)); + c.add(Restrictions.eq("ciudad", ciudad)); + c.addOrder(Order.asc("nombescola")); + + return c.list(); + } + +} diff --git a/src/com/rjconsultores/ventaboletos/entidad/Escola.java b/src/com/rjconsultores/ventaboletos/entidad/Escola.java new file mode 100644 index 000000000..ef5d6e384 --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/entidad/Escola.java @@ -0,0 +1,82 @@ +package com.rjconsultores.ventaboletos.entidad; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Date; +import java.util.List; + +import javax.persistence.Basic; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.OneToMany; +import javax.persistence.SequenceGenerator; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +@Entity +@SequenceGenerator(name = "ESCOLA_SEQ", sequenceName = "ESCOLA_SEQ", allocationSize = 1) +@Table(name = "ESCOLA") +public class Escola implements Serializable { + + private static final long serialVersionUID = 1L; + @Id + @GeneratedValue(strategy = GenerationType.AUTO, generator = "ESCOLA_SEQ") + @Basic(optional = false) + @Column(name = "ESCOLA_ID") + private Integer escolaId; + @Column(name = "NOMESCOLA") + private String nombescola; + @JoinColumn(name = "CIUDAD_ID", referencedColumnName = "CIUDAD_ID") + @ManyToOne + private Ciudad ciudad; + @Column(name = "ACTIVO") + private Boolean activo; + @Column(name = "FECMODIF") + @Temporal(TemporalType.TIMESTAMP) + private Date fecmodif; + @Column(name = "USUARIO_ID") + private Integer usuarioId; + + public Integer getEscolaId() { + return escolaId; + } + public void setEscolaId(Integer escolaId) { + this.escolaId = escolaId; + } + public String getNombescola() { + return nombescola; + } + public void setNombescola(String nombescola) { + this.nombescola = nombescola; + } + public Ciudad getCiudad() { + return ciudad; + } + public void setCiudad(Ciudad ciudad) { + this.ciudad = ciudad; + } + public Boolean getActivo() { + return activo; + } + public void setActivo(Boolean activo) { + this.activo = activo; + } + public Date getFecmodif() { + return fecmodif; + } + public void setFecmodif(Date fecmodif) { + this.fecmodif = fecmodif; + } + public Integer getUsuarioId() { + return usuarioId; + } + public void setUsuarioId(Integer usuarioId) { + this.usuarioId = usuarioId; + } +} diff --git a/src/com/rjconsultores/ventaboletos/service/EscolaService.java b/src/com/rjconsultores/ventaboletos/service/EscolaService.java new file mode 100644 index 000000000..e7bf3a1e6 --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/service/EscolaService.java @@ -0,0 +1,22 @@ +package com.rjconsultores.ventaboletos.service; + +import java.util.List; + +import com.rjconsultores.ventaboletos.entidad.Ciudad; +import com.rjconsultores.ventaboletos.entidad.Escola; +import com.rjconsultores.ventaboletos.entidad.Estado; +import com.rjconsultores.ventaboletos.utilerias.RegistroConDependenciaException; + +public interface EscolaService { + public List obtenerTodos(); + + public Escola obtenerID(Integer id); + + public Escola suscribir(Escola entidad); + + public Escola actualizacion(Escola entidad); + + public void borrar(Escola entidad) throws RegistroConDependenciaException; + + public List buscar(String nombescola, Ciudad ciudad); +} diff --git a/src/com/rjconsultores/ventaboletos/service/impl/EscolaServiceImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/EscolaServiceImpl.java new file mode 100644 index 000000000..aeaa7a2f6 --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/service/impl/EscolaServiceImpl.java @@ -0,0 +1,69 @@ +package com.rjconsultores.ventaboletos.service.impl; + +import java.util.Calendar; +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import com.rjconsultores.ventaboletos.dao.CiudadDAO; +import com.rjconsultores.ventaboletos.dao.EscolaDAO; +import com.rjconsultores.ventaboletos.entidad.Ciudad; +import com.rjconsultores.ventaboletos.entidad.Escola; +import com.rjconsultores.ventaboletos.service.EscolaService; +import com.rjconsultores.ventaboletos.utilerias.RegistroConDependenciaException; +import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado; + +@Service("escolaService") +public class EscolaServiceImpl implements EscolaService { + + @Autowired + private EscolaDAO EscolaDAO; + @Autowired + private CiudadDAO ciudadDAO; + + public List obtenerTodos() { + return EscolaDAO.obtenerTodos(); + } + + public Escola obtenerID(Integer id) { + return EscolaDAO.obtenerID(id); + } + + @Transactional + public Escola suscribir(Escola entidad) { + entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId()); + entidad.setFecmodif(Calendar.getInstance().getTime()); + entidad.setActivo(Boolean.TRUE); + + return EscolaDAO.suscribir(entidad); + } + + @Transactional + public Escola actualizacion(Escola entidad) { + entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId()); + entidad.setFecmodif(Calendar.getInstance().getTime()); + entidad.setActivo(Boolean.TRUE); + + return EscolaDAO.actualizacion(entidad); + } + + @Transactional + public void borrar(Escola entidad) throws RegistroConDependenciaException { + + if (ciudadDAO.count("Escola", entidad) > 0l) { + throw new RegistroConDependenciaException(); + } + + entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId()); + entidad.setFecmodif(Calendar.getInstance().getTime()); + entidad.setActivo(Boolean.FALSE); + + EscolaDAO.actualizacion(entidad); + } + + public List buscar(String nombEscola, Ciudad ciudad) { + return EscolaDAO.buscar(nombEscola, ciudad); + } +}