gleimar 2013-01-25 13:47:14 +00:00
parent fcbd6fc97c
commit 84d2a620bb
3 changed files with 238 additions and 218 deletions

View File

@ -5,9 +5,14 @@
package com.rjconsultores.ventaboletos.dao.hibernate; package com.rjconsultores.ventaboletos.dao.hibernate;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List; import java.util.List;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Transformer;
import org.hibernate.Criteria; import org.hibernate.Criteria;
import org.hibernate.FetchMode;
import org.hibernate.Query; import org.hibernate.Query;
import org.hibernate.SessionFactory; import org.hibernate.SessionFactory;
import org.hibernate.criterion.Order; import org.hibernate.criterion.Order;
@ -81,20 +86,23 @@ public class MarcaHibernateDAO extends GenericHibernateDAO<Marca, Short>
public List<Marca> buscarMarcaPorEmpresa(List<Empresa> empresa) { public List<Marca> buscarMarcaPorEmpresa(List<Empresa> empresa) {
String hql = " select new com.rjconsultores.ventaboletos.entidad.Marca(marca.marcaId, marca.descmarca) from Marca marca " + if ( (empresa == null) || (empresa.isEmpty())){
" where "; return Collections.emptyList();
for(Empresa e: empresa){
hql = hql + " marca.empresa.empresaId = "+ e.getEmpresaId() + " or";
} }
Collection idsEmpresa = CollectionUtils.transformedCollection(empresa, new Transformer() {
hql = hql.substring(0,hql.length()-3); @Override
public Object transform(Object input) {
return ((Empresa)input).getEmpresaId();
}
});
Query sq = getSession().createQuery(hql); Criteria c = makeCriteria();
c.add(Restrictions.eq("activo", true));
c.add(Restrictions.in("empresa", idsEmpresa));
c.setFetchMode("logotipomarca", FetchMode.DEFAULT);
List<Marca> lsMarca = sq.list(); return c.list();
return lsMarca;
} }
} }

View File

@ -24,6 +24,9 @@ import javax.persistence.Table;
import javax.persistence.Temporal; import javax.persistence.Temporal;
import javax.persistence.TemporalType; import javax.persistence.TemporalType;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
/** /**
* *
* @author Administrador * @author Administrador
@ -57,16 +60,20 @@ public class Marca implements Serializable {
@Column(name = "USUARIO_ID") @Column(name = "USUARIO_ID")
private Integer usuarioId; private Integer usuarioId;
@OneToMany(mappedBy = "marca") @OneToMany(mappedBy = "marca")
@Fetch(FetchMode.SELECT)
private List<CategoriaMarca> categoriaMarcaList; private List<CategoriaMarca> categoriaMarcaList;
@OneToMany(mappedBy = "marca") @OneToMany(mappedBy = "marca")
@Fetch(FetchMode.SELECT)
private List<ReservacionMarca> reservacionMarcaList; private List<ReservacionMarca> reservacionMarcaList;
@OneToMany(mappedBy = "marca") @OneToMany(mappedBy = "marca")
private List<CancelacionCtrl> cancelacionCtrlList; private List<CancelacionCtrl> cancelacionCtrlList;
@Column(name = "EQUIVALENCIA_ID") @Column(name = "EQUIVALENCIA_ID")
private String equivalenciaId; private String equivalenciaId;
@OneToMany(mappedBy = "marca") @OneToMany(mappedBy = "marca")
@Fetch(FetchMode.SELECT)
private List<TarifaHist> tarifaHistList; private List<TarifaHist> tarifaHistList;
@OneToMany(mappedBy = "marca") @OneToMany(mappedBy = "marca")
@Fetch(FetchMode.SELECT)
private List<Corrida> corridaList; private List<Corrida> corridaList;
public Marca() { public Marca() {

View File

@ -26,6 +26,8 @@ import javax.persistence.Table;
import javax.persistence.Temporal; import javax.persistence.Temporal;
import javax.persistence.TemporalType; import javax.persistence.TemporalType;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.springframework.security.core.Authentication; import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetails;
@ -65,14 +67,15 @@ public class Usuario implements Serializable, Authentication, UserDetails {
@Column(name = "DESCCORREO") @Column(name = "DESCCORREO")
private String descCorreo; private String descCorreo;
@OneToMany(mappedBy = "usuario", cascade = CascadeType.ALL) @OneToMany(mappedBy = "usuario", cascade = CascadeType.ALL)
@Fetch(FetchMode.SELECT)
private List<UsuarioPerfil> usuarioPerfilList; private List<UsuarioPerfil> usuarioPerfilList;
@Column(name = "INDCORTEAUTOMATICO") @Column(name = "INDCORTEAUTOMATICO")
private Boolean indCorteAutomatico; private Boolean indCorteAutomatico;
@OneToOne @OneToOne
@JoinColumn(name = "EMPLEADO_ID") @JoinColumn(name = "EMPLEADO_ID")
private Empleado empleado; private Empleado empleado;
@OneToMany(mappedBy = "usuarioLog", cascade = CascadeType.ALL,fetch=FetchType.EAGER) @OneToMany(mappedBy = "usuarioLog", cascade = CascadeType.ALL,fetch=FetchType.EAGER)
@Fetch(FetchMode.SELECT)
private List<UsuarioEmpresa> usuarioEmpresaList; private List<UsuarioEmpresa> usuarioEmpresaList;
public String getClaveUsuario() { public String getClaveUsuario() {
@ -154,6 +157,7 @@ public class Usuario implements Serializable, Authentication, UserDetails {
this.senha = senha; this.senha = senha;
} }
public List<UsuarioEmpresa> getUsuarioEmpresaList() { public List<UsuarioEmpresa> getUsuarioEmpresaList() {
List<UsuarioEmpresa> tmp = new ArrayList<UsuarioEmpresa>(); List<UsuarioEmpresa> tmp = new ArrayList<UsuarioEmpresa>();
if (usuarioEmpresaList != null) { if (usuarioEmpresaList != null) {
@ -184,6 +188,7 @@ public class Usuario implements Serializable, Authentication, UserDetails {
return tmp; return tmp;
} }
public List<Empresa> getEmpresa() { public List<Empresa> getEmpresa() {
List<Empresa> tmp = new ArrayList<Empresa>(); List<Empresa> tmp = new ArrayList<Empresa>();
if (usuarioEmpresaList != null) { if (usuarioEmpresaList != null) {
@ -209,6 +214,31 @@ public class Usuario implements Serializable, Authentication, UserDetails {
this.empleado = empleado; this.empleado = empleado;
} }
@Override
public int hashCode() {
int hash = 0;
hash += (usuarioId != null ? usuarioId.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Usuario)) {
return false;
}
Usuario other = (Usuario) object;
if ((this.usuarioId == null && other.usuarioId != null) || (this.usuarioId != null && !this.usuarioId.equals(other.usuarioId))) {
return false;
}
return true;
}
@Override
public String toString() {
return "com.rjconsultores.ventaboletos.entidad.Usuario[usuarioId=" + usuarioId + "]";
}
public Collection<GrantedAuthority> getAuthorities() { public Collection<GrantedAuthority> getAuthorities() {
return new ArrayList<GrantedAuthority>(); return new ArrayList<GrantedAuthority>();
} }
@ -267,7 +297,6 @@ public class Usuario implements Serializable, Authentication, UserDetails {
public void setDescCorreo(String descCorreo) { public void setDescCorreo(String descCorreo) {
this.descCorreo = descCorreo; this.descCorreo = descCorreo;
} }
public Boolean getIndCorteAutomatico() { public Boolean getIndCorteAutomatico() {
return indCorteAutomatico; return indCorteAutomatico;
} }
@ -275,28 +304,4 @@ public class Usuario implements Serializable, Authentication, UserDetails {
public void setIndCorteAutomatico(Boolean indCorteAutomatico) { public void setIndCorteAutomatico(Boolean indCorteAutomatico) {
this.indCorteAutomatico = indCorteAutomatico; this.indCorteAutomatico = indCorteAutomatico;
} }
@Override
public int hashCode() {
int hash = 0;
hash += (usuarioId != null ? usuarioId.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
if (!(object instanceof Usuario)) {
return false;
}
Usuario other = (Usuario) object;
if ((this.usuarioId == null && other.usuarioId != null) || (this.usuarioId != null && !this.usuarioId.equals(other.usuarioId))) {
return false;
}
return true;
}
@Override
public String toString() {
return "com.rjconsultores.ventaboletos.entidad.Usuario[usuarioId=" + usuarioId + "]";
}
} }