/* * 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.PricingEspecificoDAO; import com.rjconsultores.ventaboletos.entidad.ClaseServicio; import com.rjconsultores.ventaboletos.entidad.Empresa; import com.rjconsultores.ventaboletos.entidad.OrgaoConcedente; import com.rjconsultores.ventaboletos.entidad.Parada; import com.rjconsultores.ventaboletos.entidad.PricingEspecifico; import com.rjconsultores.ventaboletos.entidad.Ruta; import com.rjconsultores.ventaboletos.entidad.VigenciaTarifa; import java.util.Date; import java.util.List; import org.hibernate.Criteria; import org.hibernate.Query; import org.hibernate.SessionFactory; 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 Rafius */ @Repository("pricingEspecificoDAO") public class PricingEspecificoHibernateDAO extends GenericHibernateDAO implements PricingEspecificoDAO { @Autowired public PricingEspecificoHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) { setSessionFactory(factory); } @Override public List obtenerTodos() { Criteria c = getSession().createCriteria(getPersistentClass()); c.add(Restrictions.eq("activo", Boolean.TRUE)); return c.list(); } public List buscarPorNome(PricingEspecifico pricingEspecifico) { Criteria c = getSession().createCriteria(getPersistentClass()); c.add(Restrictions.eq("activo", Boolean.TRUE)); c.add(Restrictions.eq("nombPricing", pricingEspecifico.getNombPricing())); return c.list(); } @Override public List buscarPorNome(String nome) { Criteria c = getSession().createCriteria(getPersistentClass()); c.add(Restrictions.eq("activo", Boolean.TRUE)); c.add(Restrictions.eq("nombPricing", nome)); return c.list(); } @Override public List buscar(List empresas, List tipoClasses, List origens, List destinos, Date vigenciaInicial, Date vigenciaFinal) { StringBuilder hql = new StringBuilder(); hql.append("SELECT DISTINCT pe "); hql.append("FROM PricingEspecifico pe "); hql.append(" WHERE pe.activo = 1 "); if (!empresas.isEmpty()) { hql.append(" AND pe.marca.empresa.empresaId IN ("); for (Empresa e : empresas) { hql.append(e.getEmpresaId() + ","); } hql.deleteCharAt(hql.length() - 1); hql.append(")"); } if (!tipoClasses.isEmpty()) { hql.append(" AND pe.claseServicio.claseservicioId IN ("); for (ClaseServicio c : tipoClasses) { hql.append(c.getClaseservicioId() + ","); } hql.deleteCharAt(hql.length() - 1); hql.append(")"); } if (!origens.isEmpty()) { hql.append(" AND pe.parada.paradaId IN ("); for (Parada o : origens) { hql.append(o.getParadaId() + ","); } hql.deleteCharAt(hql.length() - 1); hql.append(")"); } if (!destinos.isEmpty()) { hql.append(" AND pe.parada1.paradaId IN ("); for (Parada o : origens) { hql.append(o.getParadaId() + ","); } hql.deleteCharAt(hql.length() - 1); hql.append(")"); } if (vigenciaInicial != null) { hql.append(" AND YEAR(pe.fechorinicio) >= YEAR(:vigenciaInicial) "); hql.append(" AND MONTH(pe.fechorinicio)>= MONTH(:vigenciaInicial) "); hql.append(" AND DAY(pe.fechorinicio) >= DAY(:vigenciaInicial) "); } if (vigenciaFinal != null) { hql.append(" AND YEAR(pe.fechorfin) <= YEAR(:vigenciaFinal) "); hql.append(" AND MONTH(pe.fechorfin) <= MONTH(:vigenciaFinal) "); hql.append(" AND DAY(pe.fechorfin) <= DAY(:vigenciaFinal) "); } Query query = getSession().createQuery(hql.toString()); if (vigenciaInicial != null) { query.setDate("vigenciaInicial", vigenciaInicial); } if (vigenciaFinal != null) { query.setDate("vigenciaFinal", vigenciaFinal); } return query.list(); } }