Example usage for org.hibernate Query uniqueResult

List of usage examples for org.hibernate Query uniqueResult

Introduction

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

Prototype

R uniqueResult();

Source Link

Document

Convenience method to return a single instance that matches the query, or null if the query returns no results.

Usage

From source file:br.luck.dal.LotofacilModelDAO.java

@Override
public int contarTotalRegistros() {
    Query query;
    query = getSession().createQuery(Queries.CONTA_CONCURSOS_LOTOFACIL);
    Number result = (Number) query.uniqueResult();

    return result.intValue();
}

From source file:br.luck.dal.LotomaniaModelDAO.java

@Override
public int contarTotalRegistros() {
    Query query;
    query = getSession().createQuery(Queries.CONTA_CONCURSOS_LOTOMANIA);
    Number result = (Number) query.uniqueResult();

    return result.intValue();
}

From source file:br.luck.dal.MegasenaModelDAO.java

@Override
public int contarTotalRegistros() {
    Query query;
    query = getSession().createQuery(Queries.CONTA_CONCURSOS_MEGASENA);
    Number result = (Number) query.uniqueResult();

    return result.intValue();
}

From source file:br.sp.telesul.dao.FuncionarioDAOImpl.java

@Override
public Funcionario searchById(Long id) {
    Session session = this.sessionFactory.openSession();
    try {//  ww  w. ja  v  a 2 s .c  o  m
        Query query = session.createQuery("From Funcionario f Where idFuncionario = :id").setParameter("id",
                id);
        Funcionario funcionario = (Funcionario) query.uniqueResult();
        return funcionario;
    } catch (Exception e) {
        logger.error("Error in search Single funcionrio(emplyees)" + " ", e);
        System.out.println("erro" + e);
        return null;
    } finally {
        session.close();
    }
}

From source file:br.sp.telesul.dao.FuncionarioDAOImpl.java

@Override
public FilterReturn searchPage(int pageNumber, int pageSize, String filter) {
    String countQ = "Select count (f.id) from Funcionario f";
    Session session = this.sessionFactory.getCurrentSession();

    Query countQuery = session.createQuery(countQ);
    Long countResults = (Long) countQuery.uniqueResult();

    int lastPageNumber = (int) ((countResults / pageSize) + 1);

    FilterReturn filterReturn = new FilterReturn();
    filterReturn.setTotalEntities(countResults);

    Query selectQuery = session.createQuery("From Funcionario f Where nome LIKE :filter");
    selectQuery.setParameter("filter", "%" + filter + "%");
    selectQuery.setFirstResult((pageNumber - 1) * pageSize);
    selectQuery.setMaxResults(pageSize);
    List<Funcionario> funcionarios = selectQuery.list();

    filterReturn.setEmployees(funcionarios);
    return filterReturn;
}

From source file:br.ufc.ivela.commons.dao.GenericDaoImpl.java

License:Open Source License

public int getCount(final String query, final Object[] countParams) {
    HibernateCallback callback = new HibernateCallback() {

        public Object doInHibernate(Session session) throws HibernateException {

            Query q = session.createQuery(query);

            if (countParams != null) {
                for (int i = 0; i < countParams.length; i++) {
                    Object object = countParams[i];

                    q.setParameter(i, object);
                }/*from   www  . j a  va  2s  . co m*/
            }

            return q.uniqueResult();
        }
    };

    return ((Long) getHibernateTemplate().execute(callback)).intValue();
}

From source file:br.ufg.inf.es.fs.contpatri.persistencia.dao.GenericDAOImpl.java

License:GNU General Public License

@Override
public T findOne(Query query) {
    T t;
    t = (T) query.uniqueResult();
    return t;
}

From source file:br.unisal.dao.ConsultaDao.java

public Consulta getById(Consulta c) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    Transaction tx = session.beginTransaction();
    Consulta consulta = new Consulta();
    try {/*from   ww w .  ja  v  a 2s.co  m*/
        tx.begin();
        Query query = session.createQuery("FROM Consulta WHERE idConsulta = :id");
        query.setParameter("id", c.getIdConsulta());
        consulta = (Consulta) query.uniqueResult();
        tx.commit();
    } catch (HibernateException e) {
        System.out.println("Exception ConsultaDao.getById(): " + e.getMessage());
        tx.rollback();
    } finally {
        session.close();
    }
    return consulta;
}

From source file:br.unisal.dao.EquipamentoDao.java

@Override
public Equipamento getById(Integer id) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    Transaction tx = session.beginTransaction();
    Equipamento equipamento = new Equipamento();
    try {//from  w ww  .  j a  v  a2s .  c o  m
        tx.begin();
        Query query = session.createQuery("FROM Equipamento WHERE id_equipamento = :id");
        query.setParameter("id", id);
        equipamento = (Equipamento) query.uniqueResult();
        tx.commit();
    } catch (HibernateException e) {
        System.out.println("Exception EquipamentoDao.getById(): " + e.getMessage());
        tx.rollback();
    } finally {
        session.close();
    }
    return equipamento;
}

From source file:br.unisal.dao.MedicoDao.java

public Medico getById(Medico m) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    Transaction tx = session.beginTransaction();
    Medico medico = new Medico();
    try {//from   www. j a  v a 2  s. c o m
        tx.begin();
        Query query = session.createQuery("FROM Medico WHERE idMedico = :id");
        query.setParameter("id", m.getIdMedico());
        medico = (Medico) query.uniqueResult();
        tx.commit();
    } catch (HibernateException e) {
        System.out.println("Exception MedicoDao.getById(): " + e.getMessage());
        tx.rollback();
    } finally {
        session.close();
    }
    return medico;
}