eduardo.dicarde 2015-07-14 13:19:41 +00:00
parent c588e44905
commit eb8984ffea
1 changed files with 105 additions and 78 deletions

View File

@ -4,9 +4,13 @@
*/
package com.rjconsultores.ventaboletos.dao.hibernate;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.sql.DataSource;
import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.Session;
@ -31,6 +35,9 @@ import com.rjconsultores.ventaboletos.entidad.PuntoVenta;
public class EmpresaHibernateDAO extends GenericHibernateDAO<Empresa, Integer>
implements EmpresaDAO {
@Autowired
private DataSource dataSource;
@Autowired
public EmpresaHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) {
setSessionFactory(factory);
@ -55,10 +62,10 @@ public class EmpresaHibernateDAO extends GenericHibernateDAO<Empresa, Integer>
return c.list();
}
public List<Empresa> buscarTodosExceto(List<Empresa> empresa,Integer... idEmpresa) {
public List<Empresa> buscarTodosExceto(List<Empresa> empresa, Integer... idEmpresa) {
List<Empresa> empresaList = new ArrayList<Empresa>();
for (Integer id : idEmpresa) {
for(Empresa e : empresa){
for (Empresa e : empresa) {
e.getEmpresaId().equals(id);
}
}
@ -77,13 +84,12 @@ public class EmpresaHibernateDAO extends GenericHibernateDAO<Empresa, Integer>
return c.list();
}
public List<Empresa> obtenerIndTipo2() {
Criteria c = getSession().createCriteria(getPersistentClass());
c.add(Restrictions.eq("activo", Boolean.TRUE));
c.add(Restrictions.eq("indTipo", new Short("2")));
//Nao Buscar Empresa todas
// Nao Buscar Empresa todas
c.add(Restrictions.ne("empresaId", -1));
c.addOrder(Order.asc("nombempresa"));
@ -91,8 +97,7 @@ public class EmpresaHibernateDAO extends GenericHibernateDAO<Empresa, Integer>
return c.list();
}
public List<Empresa> buscarNotInPuntoVtaComissao(PuntoVenta puntoVenta){
public List<Empresa> buscarNotInPuntoVtaComissao(PuntoVenta puntoVenta) {
StringBuilder sb = new StringBuilder();
sb.append(" select em ");
@ -104,13 +109,11 @@ public class EmpresaHibernateDAO extends GenericHibernateDAO<Empresa, Integer>
sb.append(" )");
sb.append(" order by em.nombempresa");
Query query = getSession().createQuery(sb.toString());
query.setParameter("puntoventaId", puntoVenta.getPuntoventaId());
List<Empresa> lsEmpresa = query.list();
return lsEmpresa;
}
@ -143,4 +146,28 @@ public class EmpresaHibernateDAO extends GenericHibernateDAO<Empresa, Integer>
return c.list();
}
@Override
public Empresa suscribir(Empresa entity) throws RuntimeException {
super.suscribir(entity);
gerarSeqNumFolioSistema(entity.getEmpresaId());
return entity;
}
private void gerarSeqNumFolioSistema(Integer idEmpresa) throws RuntimeException {
try {
Connection conn = dataSource.getConnection();
if (!conn.createStatement().executeQuery("select SEQUENCE_NAME from DBA_SEQUENCES where SEQUENCE_NAME like 'FOLIO_SISTEMA_" + idEmpresa + "_SEQ%'").next()) {
String[] sequences = { "", "AC", "AL", "AM", "AP", "BA", "CE", "DF", "ES", "GO", "MA", "MG", "MS", "MT", "PA", "PB", "PE", "PI", "PR", "RJ", "RN", "RO", "RR", "RS", "SC", "SE", "SP", "TO" };
for (String sequence : sequences) {
conn.createStatement().execute("CREATE SEQUENCE VTABOL.FOLIO_SISTEMA_" + (sequence == "" ? sequence : (sequence + "_") + idEmpresa + "_SEQ"));
}
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}