94 lines
3.0 KiB
Java
94 lines
3.0 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.TarjetaFidelidadDAO;
|
|
import com.rjconsultores.ventaboletos.entidad.TarjetaFidelidad;
|
|
import com.rjconsultores.ventaboletos.entidad.TarjetaFidelidadCuenta;
|
|
|
|
import java.io.Serializable;
|
|
import java.util.ArrayList;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
|
|
import org.hibernate.Criteria;
|
|
import org.hibernate.Query;
|
|
import org.hibernate.SessionFactory;
|
|
import org.hibernate.criterion.ProjectionList;
|
|
import org.hibernate.criterion.Projections;
|
|
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 Shiro
|
|
*/
|
|
@Repository("tarjetaFidelidadDAO")
|
|
public class TarjetaFidelidadHibernateDAO extends GenericHibernateDAO<TarjetaFidelidad, Integer>
|
|
implements TarjetaFidelidadDAO {
|
|
|
|
@Autowired
|
|
public TarjetaFidelidadHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) {
|
|
setSessionFactory(factory);
|
|
}
|
|
|
|
@Override
|
|
public List<TarjetaFidelidad> obtenerTodos() {
|
|
Criteria c = getSession().createCriteria(getPersistentClass());
|
|
c.add(Restrictions.eq("activo", Boolean.TRUE));
|
|
|
|
|
|
return c.list();
|
|
}
|
|
|
|
public TarjetaFidelidad obtenerNumTarjeta(Integer numTarjeta){
|
|
Criteria c = getSession().createCriteria(getPersistentClass());
|
|
c.add(Restrictions.eq("activo", Boolean.TRUE));
|
|
c.add(Restrictions.eq("numTarjeta", numTarjeta));
|
|
return (TarjetaFidelidad)c.list().get(0);
|
|
}
|
|
|
|
public List<TarjetaFidelidadCuenta> obtenerCantDesc() {
|
|
|
|
/*Criteria c = getSession().createCriteria(getPersistentClass());
|
|
c.add(Restrictions.eq("activo", Boolean.TRUE));
|
|
ProjectionList projList = Projections.projectionList();
|
|
projList.add(Projections.groupProperty("descGeneracion"));
|
|
projList.add(Projections.rowCount());
|
|
c.setProjection(projList);
|
|
List list = c.list();
|
|
|
|
List<Object[]> list1 =list;
|
|
list.get(0);
|
|
list.get(1); //el la descripcion
|
|
//list.get( 0 )[1] //el la cantidad
|
|
|
|
return list;
|
|
|
|
*/
|
|
List<TarjetaFidelidadCuenta> sumatarjetas = new ArrayList<TarjetaFidelidadCuenta>();
|
|
|
|
String hql = "select count(*),descGeneracion"
|
|
+ " from TarjetaFidelidad where activo = 1 group by descGeneracion";
|
|
|
|
Query qry = getSession().createQuery(hql);
|
|
|
|
for (Iterator it = qry.iterate(); it.hasNext();) {
|
|
Object[] row = (Object[]) it.next();
|
|
TarjetaFidelidadCuenta item = new TarjetaFidelidadCuenta();
|
|
|
|
item.setDescGeneracion((String) row[1]);
|
|
item.setCantidad(HibernateFix.count(row[0]).intValue());
|
|
sumatarjetas.add(item);
|
|
}
|
|
return sumatarjetas;
|
|
|
|
|
|
}
|
|
|
|
}
|