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:Anbulategi.GaixoaDAOHibernate.java

@Override
public boolean gaixoaDago(Gaixoa ga) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    try {//from   ww w.ja v  a2 s  .  c o  m
        session.beginTransaction();
        String hql = "From Gaixoa gaixo where gaixo.GSZ = ?";
        Query kontsulta = session.createQuery(hql).setParameter(0, ga.getGSZ());
        List<Gaixoa> lista = kontsulta.list();
        session.getTransaction().commit();
        return !lista.isEmpty();
    } catch (Exception ex) {
        ex.printStackTrace();
        session.getTransaction().rollback();
        return false;
    }
}

From source file:Anbulategi.GaixoaDAOHibernate.java

@Override
public boolean checkGaixoa(int GSZ, String password) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    try {/*from   ww w .ja  va2 s . c om*/
        session.beginTransaction();
        String hql = "From Gaixoa gaixo where gaixo.GSZ = ? and gaixo.pasahitza = ?";
        Query kontsulta = session.createQuery(hql).setParameter(0, GSZ).setParameter(1, password);
        List<Gaixoa> lista = kontsulta.list();
        session.getTransaction().commit();
        return !lista.isEmpty();
    } catch (Exception ex) {
        ex.printStackTrace();
        session.getTransaction().rollback();
        return false;
    }
}

From source file:Anbulategi.IdazkariaDAOHibernate.java

@Override
public boolean checkIdazkari(int id, String password) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    try {/*from  w w w.  j  av a  2s.  com*/
        session.beginTransaction();
        String hql = "From Idazkaria idazkari where idazkari.id = ? and idazkari.pasahitza = ?";
        Query kontsulta = session.createQuery(hql).setParameter(0, id).setParameter(1, password);
        List<Idazkaria> lista = kontsulta.list();
        session.getTransaction().commit();
        return !lista.isEmpty();
    } catch (Exception ex) {
        ex.printStackTrace();
        session.getTransaction().rollback();
        return false;
    }
}

From source file:Anbulategi.SendagileaDAOHibernate.java

@Override
public boolean checkSendagile(int GSZ, String password) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    try {/* w w  w  .  j  ava  2s .c  om*/
        session.beginTransaction();
        String hql = "From Sendagilea sendagile where sendagile.NAN = ? and sendagile.pasahitza = ?";
        Query kontsulta = session.createQuery(hql).setParameter(0, GSZ).setParameter(1, password);
        List<Gaixoa> lista = kontsulta.list();
        session.getTransaction().commit();
        return !lista.isEmpty();
    } catch (Exception ex) {
        ex.printStackTrace();
        session.getTransaction().rollback();
        return false;
    }
}

From source file:apm.common.core.DaoImpl.java

License:Open Source License

/**
 * QL //from w  w w  .  java2  s.c om
 * @param page
 * @param qlString
 * @param parameter
 * @return
 */
@SuppressWarnings("unchecked")
public <E> Page<E> find(Page<E> page, String qlString, Object... parameter) {
    // get count
    if (!page.isDisabled() && !page.isNotCount()) {
        String countQlString = "select count(*) " + removeSelect(removeOrders(qlString));
        //           page.setCount(Long.valueOf(createQuery(countQlString, parameter).uniqueResult().toString()));
        Query query = createQuery(countQlString, parameter);
        List<Object> list = query.list();
        if (list.size() > 0) {
            page.setCount(Long.valueOf(list.get(0).toString()));
        } else {
            page.setCount(list.size());
        }
        if (page.getCount() < 1) {
            return page;
        }
    }
    // order by
    String ql = qlString;
    if (StringUtils.isNotBlank(page.getOrderBy())) {
        ql += " order by " + page.getOrderBy();
    }
    Query query = createQuery(ql, parameter);
    // set page
    if (!page.isDisabled()) {
        query.setFirstResult(page.getFirstResult());
        query.setMaxResults(page.getMaxResults());
    }
    page.setList(query.list());
    return page;
}

From source file:apm.common.core.DaoImpl.java

License:Open Source License

/**
* QL /*from   w w  w . j  a  v  a2  s  .  c  o  m*/
* @param qlString
* @param parameter
* @return
*/
@SuppressWarnings("unchecked")
public <E> List<E> find(String qlString, Object... parameter) {
    Query query = createQuery(qlString, parameter);
    return query.list();
}

From source file:apm.common.core.DaoImpl.java

License:Open Source License

/**
* SQL //  w w w  .ja  v  a  2 s  . c o m
* @param page
* @param sqlString
* @param resultClass
* @param parameter
* @return
*/
@SuppressWarnings("unchecked")
public <E> Page<E> findBySql(Page<E> page, String sqlString, Class<?> resultClass, Object... parameter) {
    // get count
    if (!page.isDisabled() && !page.isNotCount()) {
        String countSqlString = "select count(*) " + removeSelect(removeOrders(sqlString));
        //           page.setCount(Long.valueOf(createSqlQuery(countSqlString, parameter).uniqueResult().toString()));
        Query query = createSqlQuery(countSqlString, parameter);
        List<Object> list = query.list();
        if (list.size() > 0) {
            page.setCount(Long.valueOf(list.get(0).toString()));
        } else {
            page.setCount(list.size());
        }
        if (page.getCount() < 1) {
            return page;
        }
    }
    // order by
    String sql = sqlString;
    if (StringUtils.isNotBlank(page.getOrderBy())) {
        sql += " order by " + page.getOrderBy();
    }
    SQLQuery query = createSqlQuery(sql, parameter);
    // set page
    if (!page.isDisabled()) {
        query.setFirstResult(page.getFirstResult());
        query.setMaxResults(page.getMaxResults());
    }
    setResultTransformer(query, resultClass);
    page.setList(query.list());
    return page;
}

From source file:App.Dao.DaoAbstract.java

protected List getHqlPreparedQuery(String query, String... argc) {
    List resultList = null;/*from ww w  .j  a va 2 s .  c  o m*/
    try {
        session.beginTransaction();
        Query q = session.createQuery(query);
        for (int i = 0; i < argc.length - 1; i += 2) {
            q.setParameter(argc[i], argc[i + 1]);
        }
        resultList = q.list();
        session.getTransaction().commit();
    } catch (HibernateException he) {
        System.err.println(he.getMessage());
    }
    return resultList;
}

From source file:app.dao.EmployeeDAOImpl.java

@Override
public List<Employee> getAllEmployees() {
    List<Employee> employees = new ArrayList<>();
    Session session = getCurrentSession();
    Query query;
    Transaction tx = session.beginTransaction();
    String hql = "FROM Employee";
    query = session.createQuery(hql);/*w ww  .j av  a 2s.co  m*/
    employees = query.list();
    tx.commit();
    return employees;
}

From source file:app.datos.servicios.implementacion.InmuebleServiceImpl.java

License:Open Source License

@Override
@Transactional(readOnly = true, rollbackFor = PersistenciaException.class)
public ArrayList<Inmueble> listarInmuebles(FiltroInmueble filtro) throws PersistenciaException {
    ArrayList<Inmueble> inmuebles = new ArrayList<>();
    Session session = getSessionFactory().getCurrentSession();
    try {//  w w  w  .ja va  2  s  .co  m
        Query query = session.createQuery(filtro.getConsultaDinamica());
        filtro.setParametros(query);
        for (Object o : query.list()) {
            if (o instanceof Inmueble) {
                inmuebles.add((Inmueble) o);
            }
        }
    } catch (Exception e) {
        throw new ConsultaException(e);
    }
    return inmuebles;
}