From c0d955dbb00f8383487e5ac9670e735eb9b18bed Mon Sep 17 00:00:00 2001 From: "daniel.zauli" Date: Fri, 16 Oct 2015 12:05:32 +0000 Subject: [PATCH] mantis #6716 git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Model/trunk/modelWeb@49063 d1611594-4594-4d17-8e1d-87c2c4800839 --- .../hibernate/ExcepcionPeajeHibernateDAO.java | 18 ++++++++++++++++++ .../ventaboletos/entidad/ExcepcionPeaje.java | 13 +++++++++++-- .../entidad/ExcepcionPeajeVigencia.java | 12 ++++++++++-- 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/ExcepcionPeajeHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/ExcepcionPeajeHibernateDAO.java index a3571b0fb..3c9867885 100644 --- a/src/com/rjconsultores/ventaboletos/dao/hibernate/ExcepcionPeajeHibernateDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/ExcepcionPeajeHibernateDAO.java @@ -3,6 +3,8 @@ package com.rjconsultores.ventaboletos.dao.hibernate; import java.util.List; import org.hibernate.Criteria; +import org.hibernate.Hibernate; +import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.criterion.Order; import org.hibernate.criterion.Restrictions; @@ -11,6 +13,7 @@ import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Repository; import com.rjconsultores.ventaboletos.dao.ExcepcionPeajeDAO; +import com.rjconsultores.ventaboletos.entidad.AbastoCentral; import com.rjconsultores.ventaboletos.entidad.ExcepcionPeaje; @Repository("excepcionPeajeDAO") @@ -32,4 +35,19 @@ implements ExcepcionPeajeDAO { return c.list(); } + + public List obtenerTodos() { + Session session = getSession(); + session.enableFilter("ativo"); + Criteria c = getSession().createCriteria(getPersistentClass()); + c.add(Restrictions.eq("activo", Boolean.TRUE)); + + List list = (List)c.list(); + for (ExcepcionPeaje excepcionPeaje : list) { + if(!Hibernate.isInitialized(excepcionPeaje.getLsExcepcionPeajeVigencia())){ + Hibernate.initialize(excepcionPeaje.getLsExcepcionPeajeVigencia()); + } + } + return list; + } } diff --git a/src/com/rjconsultores/ventaboletos/entidad/ExcepcionPeaje.java b/src/com/rjconsultores/ventaboletos/entidad/ExcepcionPeaje.java index 31c21d3bd..bb4d4c762 100644 --- a/src/com/rjconsultores/ventaboletos/entidad/ExcepcionPeaje.java +++ b/src/com/rjconsultores/ventaboletos/entidad/ExcepcionPeaje.java @@ -21,10 +21,14 @@ import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; + @Entity +@FilterDef(name="ativo") @SequenceGenerator(name = "EXCEPCION_PEAJE_SEQ", sequenceName = "EXCEPCION_PEAJE_SEQ", allocationSize = 1) @Table(name = "EXCEPCION_PEAJE") -public class ExcepcionPeaje implements Serializable { +public class ExcepcionPeaje implements Serializable,Comparable { private static final long serialVersionUID = 1L; @@ -49,7 +53,8 @@ public class ExcepcionPeaje implements Serializable { @OneToOne @JoinColumn(name = "DESTINO_ID") private Parada destino; - @OneToMany(mappedBy = "excepcionPeaje", cascade = CascadeType.ALL, fetch = FetchType.EAGER) + @OneToMany(mappedBy = "excepcionPeaje", cascade = CascadeType.ALL)//, fetch = FetchType.EAGER + @Filter(name="ativo", condition="ACTIVO = 1") private List lsExcepcionPeajeVigencia; public Integer getExcepcionPeajeId() { @@ -105,4 +110,8 @@ public class ExcepcionPeaje implements Serializable { public String toString() { return "com.rjconsultores.ventaboletos.entidad.ExcepcionPeaje[excepcionPeajeId=" + excepcionPeajeId + "]"; } + @Override + public int compareTo(ExcepcionPeaje excepcionPeaje) { + return this.getExcepcionPeajeId().intValue() - excepcionPeaje.getExcepcionPeajeId().intValue(); + } } diff --git a/src/com/rjconsultores/ventaboletos/entidad/ExcepcionPeajeVigencia.java b/src/com/rjconsultores/ventaboletos/entidad/ExcepcionPeajeVigencia.java index 95b4df123..c7569e16c 100644 --- a/src/com/rjconsultores/ventaboletos/entidad/ExcepcionPeajeVigencia.java +++ b/src/com/rjconsultores/ventaboletos/entidad/ExcepcionPeajeVigencia.java @@ -21,7 +21,7 @@ import javax.persistence.TemporalType; @Entity @SequenceGenerator(name = "EXCEPCION_PEAJE_VIGENCIA_SEQ", sequenceName = "EXCEPCION_PEAJE_VIGENCIA_SEQ", allocationSize = 1) @Table(name = "EXCEPCION_PEAJE_VIGENCIA") -public class ExcepcionPeajeVigencia implements Serializable { +public class ExcepcionPeajeVigencia implements Serializable ,Comparable { private static final long serialVersionUID = 1L; @@ -238,9 +238,17 @@ private static final long serialVersionUID = 1L; this.precio = precio; } - @Override public String toString() { return "com.rjconsultores.ventaboletos.entidad.ExcepcionPeajeVigencia[excepcionPeajeVigenciaId=" + excepcionPeajeVigenciaId + "]"; } + + @Override + public int compareTo(ExcepcionPeajeVigencia excepcionPeajeVigencia) { + if(excepcionPeajeVigencia.getExcepcionPeajeVigenciaId() != null){ + return this.getExcepcionPeajeVigenciaId().intValue() - excepcionPeajeVigencia.getExcepcionPeajeVigenciaId().intValue(); + }else{ + return -1; + } + } }