From 2cd884e910107fc452c5c3a7b3960019c9338b1e Mon Sep 17 00:00:00 2001 From: rafael Date: Fri, 31 Aug 2012 20:10:28 +0000 Subject: [PATCH] Seguro KM git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Model/trunk/modelWeb@20934 d1611594-4594-4d17-8e1d-87c2c4800839 --- .../ventaboletos/dao/SeguroKmDAO.java | 8 ++- .../dao/hibernate/SeguroKmHibernateDAO.java | 36 ++++++----- .../ventaboletos/entidad/SeguroKm.java | 60 +++++++++---------- .../ventaboletos/service/SeguroKmService.java | 8 ++- .../service/impl/SeguroKmServiceImpl.java | 55 +++++++++++++++++ .../service/impl/SeguroServiceKmImpl.java | 17 ------ 6 files changed, 121 insertions(+), 63 deletions(-) create mode 100644 src/com/rjconsultores/ventaboletos/service/impl/SeguroKmServiceImpl.java delete mode 100644 src/com/rjconsultores/ventaboletos/service/impl/SeguroServiceKmImpl.java diff --git a/src/com/rjconsultores/ventaboletos/dao/SeguroKmDAO.java b/src/com/rjconsultores/ventaboletos/dao/SeguroKmDAO.java index 014f74298..17817445d 100644 --- a/src/com/rjconsultores/ventaboletos/dao/SeguroKmDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/SeguroKmDAO.java @@ -1,6 +1,10 @@ package com.rjconsultores.ventaboletos.dao; -public interface SeguroKmDAO { +import com.rjconsultores.ventaboletos.entidad.OrgaoConcedente; +import com.rjconsultores.ventaboletos.entidad.SeguroKm; +import java.util.List; + +public interface SeguroKmDAO extends GenericDAO { /** * Indica se existe seguroKm para o orgaoConcedenteId informado @@ -9,5 +13,7 @@ public interface SeguroKmDAO { * @return */ public boolean existe(Integer orgaoConcedenteId); + + public List buscarPorOrgao(OrgaoConcedente orgao); } diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/SeguroKmHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/SeguroKmHibernateDAO.java index 8cad3a4f3..256231a68 100644 --- a/src/com/rjconsultores/ventaboletos/dao/hibernate/SeguroKmHibernateDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/SeguroKmHibernateDAO.java @@ -1,5 +1,7 @@ package com.rjconsultores.ventaboletos.dao.hibernate; +import com.rjconsultores.ventaboletos.entidad.OrgaoConcedente; +import java.util.List; import org.hibernate.Criteria; import org.hibernate.SessionFactory; import org.hibernate.criterion.Projections; @@ -14,21 +16,27 @@ import com.rjconsultores.ventaboletos.entidad.SeguroKm; @Repository("seguroKmDAO") public class SeguroKmHibernateDAO extends GenericHibernateDAO implements SeguroKmDAO { - @Autowired - public SeguroKmHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) { - setSessionFactory(factory); - } + @Autowired + public SeguroKmHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) { + setSessionFactory(factory); + } - @Override - public boolean existe(Integer orgaoConcedenteId) { - Criteria c= makeCriteria(); - c.add(Restrictions.eq("orgaoconcedente.orgaoConcedenteId", orgaoConcedenteId)); - c.add(Restrictions.eq("activo", Boolean.TRUE)); - c.setProjection(Projections.rowCount()); - - - return HibernateFix.count(c.list()) > 0; - } + @Override + public boolean existe(Integer orgaoConcedenteId) { + Criteria c = makeCriteria(); + c.add(Restrictions.eq("orgaoconcedente.orgaoConcedenteId", orgaoConcedenteId)); + c.add(Restrictions.eq("activo", Boolean.TRUE)); + c.setProjection(Projections.rowCount()); + return HibernateFix.count(c.list()) > 0; + } + + public List buscarPorOrgao(OrgaoConcedente orgao) { + Criteria c = makeCriteria(); + c.add(Restrictions.eq("orgaoconcedente", orgao)); + c.add(Restrictions.eq("activo", Boolean.TRUE)); + + return c.list(); + } } diff --git a/src/com/rjconsultores/ventaboletos/entidad/SeguroKm.java b/src/com/rjconsultores/ventaboletos/entidad/SeguroKm.java index 958c6bb36..bfb6ab565 100644 --- a/src/com/rjconsultores/ventaboletos/entidad/SeguroKm.java +++ b/src/com/rjconsultores/ventaboletos/entidad/SeguroKm.java @@ -11,26 +11,29 @@ import java.util.Date; 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.NamedQueries; -import javax.persistence.NamedQuery; +import javax.persistence.SequenceGenerator; import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; -import javax.xml.bind.annotation.XmlRootElement; /** * * @author gleimar */ @Entity +@SequenceGenerator(name = "SEGURO_KM_SEQ", sequenceName = "SEGURO_KM_SEQ", allocationSize = 1) @Table(name = "SEGURO_KM") public class SeguroKm implements Serializable { + private static final long serialVersionUID = 1L; @Id @Basic(optional = false) + @GeneratedValue(strategy = GenerationType.AUTO, generator = "SEGURO_KM_SEQ") @Column(name = "SEGUROKM_ID") private Integer segurokmId; @Column(name = "KMATE") @@ -79,8 +82,6 @@ public class SeguroKm implements Serializable { this.valortaxa = valortaxa; } - - @Override public int hashCode() { int hash = 0; @@ -106,36 +107,35 @@ public class SeguroKm implements Serializable { return "com.rjconsultores.ventaboletos.entidad.SeguroKm[ segurokmId=" + segurokmId + " ]"; } - public OrgaoConcedente getOrgaoconcedente() { - return orgaoconcedente; - } + public OrgaoConcedente getOrgaoconcedente() { + return orgaoconcedente; + } - public void setOrgaoconcedente(OrgaoConcedente orgaoconcedente) { - this.orgaoconcedente = orgaoconcedente; - } + public void setOrgaoconcedente(OrgaoConcedente orgaoconcedente) { + this.orgaoconcedente = orgaoconcedente; + } - public Boolean getActivo() { - return activo; - } + public Boolean getActivo() { + return activo; + } - public void setActivo(Boolean activo) { - this.activo = activo; - } + public void setActivo(Boolean activo) { + this.activo = activo; + } - public Date getFecmodif() { - return fecmodif; - } + public Date getFecmodif() { + return fecmodif; + } - public void setFecmodif(Date fecmodif) { - this.fecmodif = fecmodif; - } + public void setFecmodif(Date fecmodif) { + this.fecmodif = fecmodif; + } - public Integer getUsuarioId() { - return usuarioId; - } + public Integer getUsuarioId() { + return usuarioId; + } - public void setUsuarioId(Integer usuarioId) { - this.usuarioId = usuarioId; - } - + public void setUsuarioId(Integer usuarioId) { + this.usuarioId = usuarioId; + } } diff --git a/src/com/rjconsultores/ventaboletos/service/SeguroKmService.java b/src/com/rjconsultores/ventaboletos/service/SeguroKmService.java index 1d054f5ec..efb922fa9 100644 --- a/src/com/rjconsultores/ventaboletos/service/SeguroKmService.java +++ b/src/com/rjconsultores/ventaboletos/service/SeguroKmService.java @@ -1,6 +1,12 @@ package com.rjconsultores.ventaboletos.service; +import com.rjconsultores.ventaboletos.entidad.OrgaoConcedente; +import com.rjconsultores.ventaboletos.entidad.SeguroKm; +import java.util.List; -public interface SeguroKmService { + +public interface SeguroKmService extends GenericService{ + + public List buscarPorOrgao(OrgaoConcedente orgao); } diff --git a/src/com/rjconsultores/ventaboletos/service/impl/SeguroKmServiceImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/SeguroKmServiceImpl.java new file mode 100644 index 000000000..8f61c2858 --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/service/impl/SeguroKmServiceImpl.java @@ -0,0 +1,55 @@ +package com.rjconsultores.ventaboletos.service.impl; + +import com.rjconsultores.ventaboletos.entidad.OrgaoConcedente; +import com.rjconsultores.ventaboletos.entidad.SeguroKm; +import java.util.List; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.rjconsultores.ventaboletos.dao.SeguroKmDAO; +import com.rjconsultores.ventaboletos.service.SeguroKmService; +import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado; +import java.util.Calendar; +import org.springframework.transaction.annotation.Transactional; + +@Service("seguroKmService") +public class SeguroKmServiceImpl implements SeguroKmService { + + @Autowired + private SeguroKmDAO seguroKmDAO; + + public List buscarPorOrgao(OrgaoConcedente orgao) { + return seguroKmDAO.buscarPorOrgao(orgao); + } + + public List obtenerTodos() { + return seguroKmDAO.obtenerTodos(); + } + + public SeguroKm obtenerID(Integer id) { + return seguroKmDAO.obtenerID(id); + } + + @Transactional + public SeguroKm suscribir(SeguroKm entidad) { + entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId()); + entidad.setFecmodif(Calendar.getInstance().getTime()); + entidad.setActivo(Boolean.TRUE); + + return seguroKmDAO.suscribir(entidad); + } + + @Transactional + public SeguroKm actualizacion(SeguroKm entidad) { + return seguroKmDAO.actualizacion(entidad); + } + + @Transactional + public void borrar(SeguroKm entidad) { + entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId()); + entidad.setFecmodif(Calendar.getInstance().getTime()); + entidad.setActivo(Boolean.FALSE); + + seguroKmDAO.borrar(entidad); + } +} diff --git a/src/com/rjconsultores/ventaboletos/service/impl/SeguroServiceKmImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/SeguroServiceKmImpl.java deleted file mode 100644 index 7cf49964b..000000000 --- a/src/com/rjconsultores/ventaboletos/service/impl/SeguroServiceKmImpl.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.rjconsultores.ventaboletos.service.impl; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import com.rjconsultores.ventaboletos.dao.SeguroKmDAO; -import com.rjconsultores.ventaboletos.exception.BusinessException; -import com.rjconsultores.ventaboletos.service.SeguroKmService; -import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado; - -@Service("seguroKmService") -public class SeguroServiceKmImpl implements SeguroKmService{ - - @Autowired - private SeguroKmDAO seguroKmDAO; -}