From 67410e166f76cdd6e5d8e6096d866b017d57c24d Mon Sep 17 00:00:00 2001 From: changelogweb Date: Wed, 13 Jan 2021 15:10:27 +0000 Subject: [PATCH] fixes bug#21410 qua:wally dev: git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Model/trunk/modelWeb@105006 d1611594-4594-4d17-8e1d-87c2c4800839 --- .../dao/hibernate/FeriadoHibernateDAO.java | 32 +++++++++++++------ .../ventaboletos/utilerias/FeriadoCache.java | 6 +++- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/FeriadoHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/FeriadoHibernateDAO.java index f7ec04fe4..dc2b8b1a9 100644 --- a/src/com/rjconsultores/ventaboletos/dao/hibernate/FeriadoHibernateDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/FeriadoHibernateDAO.java @@ -1,13 +1,13 @@ package com.rjconsultores.ventaboletos.dao.hibernate; import java.sql.Date; +import java.text.SimpleDateFormat; 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.Projections; import org.hibernate.criterion.Restrictions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; @@ -21,6 +21,8 @@ import com.rjconsultores.ventaboletos.entidad.Feriado; @Repository("feriadoDAO") public class FeriadoHibernateDAO extends GenericHibernateDAO implements FeriadoDAO { + private static SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); + @Autowired public FeriadoHibernateDAO( @Qualifier("sessionFactory") SessionFactory factory) { @@ -48,15 +50,25 @@ public class FeriadoHibernateDAO extends GenericHibernateDAO i @Override public boolean ehFeriado(Date fecFeriado, Empresa empresa, Estado estadoOrigem) { - Criteria c = makeCriteria(); - - c.add(Restrictions.eq("activo", true)); - c.add(Restrictions.eq("fecferiado", fecFeriado)); - c.add(Restrictions.or(Restrictions.eq("estado", estadoOrigem), Restrictions.isNull("estado"))); - c.add(Restrictions.or(Restrictions.eq("empresa", empresa), Restrictions.isNull("empresa"))); - c.setProjection(Projections.rowCount()); - - return HibernateFix.count(c.uniqueResult()) > 0; + + StringBuilder sb = new StringBuilder(""); + + sb.append(" select count(*) "); + sb.append(" from "); + sb.append(" Feriado f "); + sb.append(" where "); + sb.append(" f.activo = 1 "); + sb.append(" and f.fecferiado = TO_DATE(:fecFeriado,'dd/MM/yyyy') "); + sb.append(" and (f.estado is null or f.estado = :estado) "); + sb.append(" and (f.empresa is null or f.empresa = :empresa) "); + + + Query query = this.getSession().createQuery(sb.toString()); + query.setString("fecFeriado", sdf.format(fecFeriado)); + query.setParameter("estado",estadoOrigem); + query.setParameter("empresa",empresa); + + return HibernateFix.count(query.uniqueResult()) > 0; } @Override diff --git a/src/com/rjconsultores/ventaboletos/utilerias/FeriadoCache.java b/src/com/rjconsultores/ventaboletos/utilerias/FeriadoCache.java index cbe609f8b..c110849f2 100644 --- a/src/com/rjconsultores/ventaboletos/utilerias/FeriadoCache.java +++ b/src/com/rjconsultores/ventaboletos/utilerias/FeriadoCache.java @@ -35,7 +35,9 @@ public class FeriadoCache { KeyFeriadoMap key = new KeyFeriadoMap(strDataFeriado, empresa.getEmpresaId(), estadoOrigem.getEstadoId()); Boolean ehFeriado = mapFeriado.get(key); - + + log.debug("ehFeriado="+ehFeriado); + if (ehFeriado == null) { ehFeriado = feriadoDAO.ehFeriado(new java.sql.Date(dataFeriado.getTime()), empresa, estadoOrigem); @@ -48,6 +50,8 @@ public class FeriadoCache { } public void limpar() { + log.debug("limpeza de cache de feriados"); + mapFeriado.clear(); }