81 lines
2.4 KiB
Java
81 lines
2.4 KiB
Java
/*
|
|
* To change this template, choose Tools | Templates
|
|
* and open the template in the editor.
|
|
*/
|
|
package com.rjconsultores.ventaboletos.dao.hibernate;
|
|
|
|
import com.rjconsultores.ventaboletos.dao.EstadoDAO;
|
|
import com.rjconsultores.ventaboletos.entidad.Empresa;
|
|
import com.rjconsultores.ventaboletos.entidad.Estado;
|
|
import com.rjconsultores.ventaboletos.entidad.Pais;
|
|
|
|
import java.util.List;
|
|
import org.hibernate.Criteria;
|
|
import org.hibernate.Query;
|
|
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;
|
|
|
|
/**
|
|
*
|
|
* @author MCosso
|
|
*/
|
|
@Repository("estadoDAO")
|
|
public class EstadoHibernateDAO extends GenericHibernateDAO<Estado, Integer>
|
|
implements EstadoDAO {
|
|
|
|
@Autowired
|
|
public EstadoHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) {
|
|
setSessionFactory(factory);
|
|
}
|
|
|
|
@Override
|
|
public List<Estado> obtenerTodos() {
|
|
Criteria c = getSession().createCriteria(getPersistentClass());
|
|
c.add(Restrictions.eq("activo", Boolean.TRUE));
|
|
c.addOrder(Order.asc("nombestado"));
|
|
|
|
return c.list();
|
|
}
|
|
|
|
public List<Estado> buscar(String nombestado, Pais pais) {
|
|
Criteria c = getSession().createCriteria(getPersistentClass());
|
|
c.add(Restrictions.eq("activo", Boolean.TRUE));
|
|
c.add(Restrictions.eq("nombestado", nombestado));
|
|
c.add(Restrictions.eq("pais", pais));
|
|
|
|
return c.list();
|
|
}
|
|
|
|
public List<Estado> buscarNotInEmpresaImposto(Empresa empresa) {
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
sb.append(" select es ");
|
|
sb.append(" from Estado es ");
|
|
sb.append(" where es.activo = 1 ");
|
|
sb.append(" and es.estadoId not in ( ");
|
|
sb.append(" select ei.estado.estadoId from EmpresaImposto ei ");
|
|
sb.append(" where ei.activo = 1 and ei.empresa.empresaId =:empresaId ");
|
|
sb.append(" )");
|
|
sb.append(" order by es.nombestado");
|
|
|
|
Query query = getSession().createQuery(sb.toString());
|
|
query.setParameter("empresaId", empresa.getEmpresaId());
|
|
|
|
List<Estado> lsEstado = query.list();
|
|
|
|
return lsEstado;
|
|
}
|
|
|
|
@Override
|
|
public List<Estado> buscarCveEstado(String cveEstado) {
|
|
Criteria c = getSession().createCriteria(getPersistentClass());
|
|
c.add(Restrictions.eq("activo", Boolean.TRUE));
|
|
c.add(Restrictions.eq("cveestado", cveEstado));
|
|
return c.list();
|
|
}
|
|
}
|