Example usage for org.hibernate Query list

List of usage examples for org.hibernate Query list

Introduction

In this page you can find the example usage for org.hibernate Query list.

Prototype

List<R> list();

Source Link

Document

Return the query results as a List.

Usage

From source file:aes.pica.touresbalon.touresbalonproductosws.servicios.Services.java

public java.util.List<com.touresbalon.productostouresbalon.Producto> consultaTop5Productos(
        java.util.List<java.lang.Integer> idProducto)
        throws ConsultaTop5ProductosFault_Exception, DatatypeConfigurationException {

    Session sessionProductos;/*from   w  ww .j  a v a  2s.  co m*/
    Session sessionOrdenes;
    Transaction txProductos;
    Transaction txOrdenes;

    sessionProductos = ProductosHU.getSessionFactory().getCurrentSession();
    sessionOrdenes = ClientesyOrdenesHU.getSessionFactory().getCurrentSession();

    txProductos = sessionProductos.beginTransaction();
    txOrdenes = sessionOrdenes.beginTransaction();

    List<Producto> lstRankingProductos = new ArrayList<>();
    List<BigDecimal> lstProductos = new ArrayList<>();

    Query query;

    String strsql = "" + "SELECT " + "  PRODID " + "FROM " + "  ( " + "    SELECT " + "      ASOCIADOS.PRODID, "
            + "      COUNT ( ASOCIADOS.PRODID ) AS COUNT_PRODID " + "    FROM " + "      ITEMS SELECCIONADO "
            + "    INNER JOIN ORDERS " + "    ON " + "      ORDERS.ORDID = SELECCIONADO.ORDID "
            + "    AND SELECCIONADO.PRODID = " + idProducto.get(0) + "    INNER JOIN ITEMS ASOCIADOS "
            + "    ON " + "      ORDERS.ORDID = ASOCIADOS.ORDID "
            + "    AND SELECCIONADO.PRODID <> ASOCIADOS.PRODID " + "    GROUP BY " + "      ASOCIADOS.PRODID, "
            + "      ORDERS.ORDID " + "    ORDER BY " + "      COUNT_PRODID DESC " + "  ) " + "WHERE "
            + "  ROWNUM <= 5";

    try {
        query = sessionOrdenes.createSQLQuery(strsql);
        lstProductos = query.list();
    } catch (Exception e) {
        System.out.println("Error al consultar el producto: " + e.getMessage());
    }

    for (BigDecimal p : lstProductos) {
        strsql = "from Producto where idProducto = " + p.intValue();
        List<aes.pica.touresbalon.touresbalonproductosws.entidades.productos.Producto> lstProductEntity = new ArrayList<>();
        try {
            query = sessionProductos.createQuery(strsql);
            lstProductEntity = query.list();
        } catch (Exception e) {
            System.out.println("Error al consultar el producto: " + e.getMessage());
        }

        for (aes.pica.touresbalon.touresbalonproductosws.entidades.productos.Producto prod : lstProductEntity) {
            Producto p1 = new Producto();
            p1.setIdProducto(prod.getIdProducto());
            p1.setEspectaculo(prod.getEspectaculo());
            p1.setDescripcion(prod.getDescripcion());

            TarifaValores tarifaEspectaculo = new TarifaValores();
            tarifaEspectaculo.setId(prod.getTarifaEspectaculo().getIdEspectaculo());
            tarifaEspectaculo.setNombreTipo(prod.getTarifaEspectaculo().getNombreEspectaculo());
            tarifaEspectaculo.setPrecio(prod.getTarifaEspectaculo().getPrecio());
            p1.setTipoEspectaculo(tarifaEspectaculo);

            TarifaValores tarifaTransporte = new TarifaValores();
            tarifaTransporte.setId(prod.getTarifaTransporte().getIdTransporte());
            tarifaTransporte.setNombreTipo(prod.getTarifaTransporte().getNombreTransporte());
            tarifaTransporte.setPrecio(prod.getTarifaTransporte().getPrecio());
            p1.setTipoTransporte(tarifaTransporte);

            TarifaValores tarifaHospedaje = new TarifaValores();
            tarifaHospedaje.setId(prod.getTarifaHospedaje().getIdHospedaje());
            tarifaHospedaje.setNombreTipo(prod.getTarifaHospedaje().getNombreHospedaje());
            tarifaHospedaje.setPrecio(prod.getTarifaHospedaje().getPrecio());
            p1.setTipoHospedaje(tarifaHospedaje);

            p1.setFechaSalida(toGregorian(prod.getFechaSalida()));
            p1.setFechaLlegada(toGregorian(prod.getFechaLlegada()));

            p1.setImagenProducto(prod.getUrlImagen());
            lstRankingProductos.add(p1);
        }
    }

    if (sessionProductos.isOpen()) {
        sessionProductos.close();
    }
    if (sessionOrdenes.isOpen()) {
        sessionOrdenes.close();
    }

    return lstRankingProductos;
}

From source file:agama.AgamaHelper.java

public List getListAgama() {
    List<Agama> agamaList = null;

    Transaction tx = session.beginTransaction();
    Query q = session.createQuery("from Agama");
    agamaList = (List<Agama>) q.list();

    return agamaList;
}

From source file:agenda_hibernate.controlador.Operaciones.java

public DefaultListModel obtenerNoticiasUser(String user) {
    SessionFactory sesion = NewHibernateUtil.getSessionFactory();
    Session session = sesion.openSession();
    Transaction tx = session.beginTransaction();
    Query q = session.createQuery("from noticias where noticias.usuario=" + user + "");
    List<Noticias> lista = q.list();
    Iterator<Noticias> iter = lista.iterator();
    tx.commit();/*from  ww w. j  a v a2 s.co  m*/
    session.close();
    DefaultListModel dlm = new DefaultListModel();
    while (iter.hasNext()) {
        Noticias noti = (Noticias) iter.next();

        dlm.addElement(noti);
    }
    return dlm;
}

From source file:agenda_hibernate.controlador.Operaciones.java

public DefaultListModel mostrarNoticias() {
    SessionFactory sesion = NewHibernateUtil.getSessionFactory();
    Session session = sesion.openSession();
    Transaction tx = session.beginTransaction();
    Query q = session.createQuery("from Noticias");
    List<Noticias> lista = q.list();
    Iterator<Noticias> iter = lista.iterator();
    tx.commit();//from w  ww . j  av a  2  s . c om
    session.close();
    DefaultListModel dlm = new DefaultListModel();
    while (iter.hasNext()) {
        Noticias noti = (Noticias) iter.next();
        dlm.addElement(noti);
    }
    return dlm;
}

From source file:Agente.altaAgente.java

private List<Object[]> executeHQLQuery(String hql) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    try {//from  w ww .  j a va 2s  .c  om
        session.beginTransaction();
        Query q = session.createQuery(hql);
        List resultList = q.list();
        session.getTransaction().commit();
        session.disconnect();
        return resultList;
    } catch (HibernateException he) {
        he.printStackTrace();
        List lista = null;
        return lista;
    }
}

From source file:Agente.buscaAgentes.java

private List<Object[]> executeHQLQuery(String hql) {
    try {//from  w w w. j  av  a  2 s . c om
        Session session = HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();
        Query q = session.createQuery(hql);
        List resultList = q.list();
        session.getTransaction().commit();
        session.disconnect();
        return resultList;
    } catch (HibernateException he) {
        he.printStackTrace();
        List lista = null;//new List(5);
        return lista;
    }
}

From source file:agh.musicapplication.mappdao.MAlbumRepository.java

@Override
public List<MAlbum> getAlbumsOfSomeBandSortedAlphabetically(MBand band) {
    Query query = getSession().createQuery("from MAlbum where band =:band ORDER BY name ASC");
    query.setParameter("band", band);
    return query.list();
}

From source file:ai.test.service.DeparmentService.java

public List<Department> getAll() {
    try {/*from   www .j  av  a  2 s  . c o m*/
        Query q = session.createQuery("From Department ");

        List<Department> resultList = q.list();
        return resultList;

    } catch (Exception ex) {
        ex.printStackTrace();
    }

    return null;
}

From source file:ai.test.service.DeparmentService.java

public Department getById(Long id) {
    try {/*w  w w .j a  va2s .  co m*/
        Query q = session.createQuery("From Department d WHERE d.id=" + id);

        List<Department> resultList = q.list();
        if (resultList != null && resultList.size() > 0)
            return resultList.get(0);

    } catch (Exception ex) {
        ex.printStackTrace();
    }

    return null;
}

From source file:ai.test.service.EmployeeService.java

public List<Employee> getAll() {
    try {/*  w  ww.  j  a  va 2 s  . co m*/
        Query q = session.createQuery("From Employee ");

        List<Employee> resultList = q.list();
        return resultList;

    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return null;
}