AdmMono/src/com/rjconsultores/ventaboletos/dao/hibernate/UsuarioEmpresaHibernateDAO....

76 lines
2.5 KiB
Java

package com.rjconsultores.ventaboletos.dao.hibernate;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Projections;
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.UsuarioEmpresaDAO;
import com.rjconsultores.ventaboletos.entidad.Empresa;
import com.rjconsultores.ventaboletos.entidad.Usuario;
import com.rjconsultores.ventaboletos.entidad.UsuarioEmpresa;
@Repository("usuarioEmpresaDAO")
public class UsuarioEmpresaHibernateDAO extends GenericHibernateDAO<UsuarioEmpresa, Integer>
implements UsuarioEmpresaDAO {
@Autowired
public UsuarioEmpresaHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) {
setSessionFactory(factory);
}
@Override
public List<UsuarioEmpresa> obtenerTodos() {
Criteria c = getSession().createCriteria(getPersistentClass());
c.add(Restrictions.eq("activo", Boolean.TRUE));
return c.list();
}
public List<UsuarioEmpresa> obtenerPorUsuario(Usuario usuario) {
Criteria c = getSession().createCriteria(getPersistentClass());
c.add(Restrictions.eq("activo", Boolean.TRUE));
c.add(Restrictions.eq("usuarioLog", usuario));
return c.list();
}
public Boolean obtenerPorEmpresaUsuario(Empresa empresa, Usuario usuario) {
Criteria c = getSession().createCriteria(getPersistentClass());
c.add(Restrictions.eq("activo", Boolean.TRUE));
c.add(Restrictions.eq("empresa", empresa));
c.add(Restrictions.eq("usuarioLog", usuario));
if(!c.list().isEmpty()){
return true;
}else{
return false;
}
}
public List<Empresa> obtenerEmpresa(Usuario usuario) {
Criteria c = getSession().createCriteria(getPersistentClass());
c.add(Restrictions.eq("activo", Boolean.TRUE));
c.add(Restrictions.eq("usuarioLog", usuario));
List<UsuarioEmpresa> usuarioEmpresaList = c.list();
List<Empresa> empresaList = new ArrayList<Empresa>();
if(!usuarioEmpresaList.isEmpty()){
for(UsuarioEmpresa ue : usuarioEmpresaList){
empresaList.add(ue.getEmpresa());
}
}
return empresaList;
}
}