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; package com.rjconsultores.ventaboletos.dao.hibernate;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.sql.DataSource;
import org.hibernate.Criteria; import org.hibernate.Criteria;
import org.hibernate.Query; import org.hibernate.Query;
import org.hibernate.Session; import org.hibernate.Session;
@ -31,6 +35,9 @@ import com.rjconsultores.ventaboletos.entidad.PuntoVenta;
public class EmpresaHibernateDAO extends GenericHibernateDAO<Empresa, Integer> public class EmpresaHibernateDAO extends GenericHibernateDAO<Empresa, Integer>
implements EmpresaDAO { implements EmpresaDAO {
@Autowired
private DataSource dataSource;
@Autowired @Autowired
public EmpresaHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) { public EmpresaHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) {
setSessionFactory(factory); setSessionFactory(factory);
@ -77,7 +84,6 @@ public class EmpresaHibernateDAO extends GenericHibernateDAO<Empresa, Integer>
return c.list(); return c.list();
} }
public List<Empresa> obtenerIndTipo2() { public List<Empresa> obtenerIndTipo2() {
Criteria c = getSession().createCriteria(getPersistentClass()); Criteria c = getSession().createCriteria(getPersistentClass());
c.add(Restrictions.eq("activo", Boolean.TRUE)); c.add(Restrictions.eq("activo", Boolean.TRUE));
@ -91,7 +97,6 @@ public class EmpresaHibernateDAO extends GenericHibernateDAO<Empresa, Integer>
return c.list(); return c.list();
} }
public List<Empresa> buscarNotInPuntoVtaComissao(PuntoVenta puntoVenta) { public List<Empresa> buscarNotInPuntoVtaComissao(PuntoVenta puntoVenta) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
@ -104,13 +109,11 @@ public class EmpresaHibernateDAO extends GenericHibernateDAO<Empresa, Integer>
sb.append(" )"); sb.append(" )");
sb.append(" order by em.nombempresa"); sb.append(" order by em.nombempresa");
Query query = getSession().createQuery(sb.toString()); Query query = getSession().createQuery(sb.toString());
query.setParameter("puntoventaId", puntoVenta.getPuntoventaId()); query.setParameter("puntoventaId", puntoVenta.getPuntoventaId());
List<Empresa> lsEmpresa = query.list(); List<Empresa> lsEmpresa = query.list();
return lsEmpresa; return lsEmpresa;
} }
@ -143,4 +146,28 @@ public class EmpresaHibernateDAO extends GenericHibernateDAO<Empresa, Integer>
return c.list(); 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);
}
}
} }