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.com.hslife.orcamento.repository.FaturaCartaoRepository.java

License:Open Source License

public boolean existsFaturaCartao(Conta conta) {
    boolean result = true;

    String sqlLancamento = "select count(id) from faturacartao where idConta = " + conta.getId();

    Query queryLancamento = getSession().createSQLQuery(sqlLancamento);

    BigInteger queryResultLancamento = (BigInteger) queryLancamento.uniqueResult();

    if (queryResultLancamento.longValue() == 0) {
        return false;
    }/*from  w  w w . ja v  a 2s.c o  m*/

    return result;
}

From source file:br.com.hslife.orcamento.repository.FaturaCartaoRepository.java

License:Open Source License

public boolean existsFaturaCartaoByContaAndDataVencimento(Conta conta, Date dataVencimento) {
    boolean result = true;

    String sqlLancamento = "select count(id) from faturacartao where idConta = " + conta.getId()
            + " and dataVencimento = '" + Util.formataDataHora(dataVencimento, Util.DATABASE) + "'";

    Query queryLancamento = getSession().createSQLQuery(sqlLancamento);

    BigInteger queryResultLancamento = (BigInteger) queryLancamento.uniqueResult();

    if (queryResultLancamento.longValue() == 0) {
        return false;
    }/*w ww  .j av a2s.  c o  m*/

    return result;
}

From source file:br.com.hslife.orcamento.repository.LancamentoContaRepository.java

License:Open Source License

public boolean existsLinkageFaturaCartao(LancamentoConta lancamento) {
    boolean result = true;

    String sqlLancamento = "select count(*) from detalhefatura where idLancamento = " + lancamento.getId();

    Query queryLancamento = getSession().createSQLQuery(sqlLancamento);

    BigInteger queryResultLancamento = (BigInteger) queryLancamento.uniqueResult();

    if (queryResultLancamento.longValue() == 0) {
        return false;
    }/* ww w  .j a  v  a 2  s. c o  m*/

    return result;
}

From source file:br.com.hslife.orcamento.repository.LancamentoContaRepository.java

License:Open Source License

public boolean existsLinkagePagamentoFaturaCartao(LancamentoConta lancamento) {
    boolean result = true;

    String sqlLancamento = "select count(*) from faturacartao where idLancamento = " + lancamento.getId();

    Query queryLancamento = getSession().createSQLQuery(sqlLancamento);

    BigInteger queryResultLancamento = (BigInteger) queryLancamento.uniqueResult();

    if (queryResultLancamento.longValue() == 0) {
        return false;
    }/*from   w  w w .j  a v a  2  s .  co m*/

    return result;
}

From source file:br.com.hslife.sirce.persistencia.GenericDao.java

License:Open Source License

protected Object queryUnique(Class classe, String sqlQuery) {
    session = HibernateUtil.getSessionFactory().openSession();
    Object resultado = null;/*from w  ww  . ja v  a  2s  . com*/
    try {
        Query queryResult = session.createSQLQuery(sqlQuery).addEntity(classe);
        resultado = queryResult.uniqueResult();
    } catch (Exception e) {
        errorMessage = e.getMessage();
        stackTrace = e.getStackTrace().toString();
        e.printStackTrace();
    } finally {
        if (session.isOpen()) {
            session.close();
        }
    }
    return resultado;
}

From source file:br.com.livraria.dao.AutorDAO.java

public Autor buscarPorCodigo(Long codigo) {
    Session sessao = HibernateUtil.getSessionFactory().openSession();
    Autor autor = null;//from  www  . j  a  va  2 s .co  m

    try {
        Query consulta = sessao.getNamedQuery("Autor.buscarPorCodigo");
        consulta.setLong("codigo", codigo);

        autor = (Autor) consulta.uniqueResult();
    } catch (RuntimeException ex) {
        throw ex;
    } finally {
        sessao.close();
    }
    return autor;
}

From source file:br.com.livraria.dao.FuncionarioDAO.java

public Funcionario buscarPorCodigo(Long codigo) {
    Session sessao = HibernateUtil.getSessionFactory().openSession();
    Funcionario funcionario = null;//from  ww  w. ja  v a 2s  . co m

    try {
        Query consulta = sessao.getNamedQuery("Funcionario.buscarPorCodigo");
        consulta.setLong("codigo", codigo);

        funcionario = (Funcionario) consulta.uniqueResult();
    } catch (RuntimeException ex) {
        throw ex;
    } finally {
        sessao.close();
    }
    return funcionario;
}

From source file:br.com.livraria.dao.ItemDAO.java

public Item buscarPorCodigo(Long codigo) {
    Session sessao = HibernateUtil.getSessionFactory().openSession();
    Item item = null;//from ww  w  .  ja  v  a 2  s.  c o  m

    try {

        Query consulta = sessao.getNamedQuery("Item.buscarPorCodigo");
        consulta.setLong("codigo", codigo);
        item = (Item) consulta.uniqueResult();
    } catch (RuntimeException ex) {
        throw ex;
    } finally {
        sessao.close();
    }
    return item;
}

From source file:br.com.livraria.dao.VendaDAO.java

public Venda buscarPorCodigo(Long codigo) {
    Session sessao = HibernateUtil.getSessionFactory().openSession();
    Venda venda = null;/*from  w  w w  .j  a  va  2  s . c  o m*/

    try {
        Query consulta = sessao.getNamedQuery("Venda.buscarPorCodigo");
        consulta.setLong("codigo", codigo);
        venda = (Venda) consulta.uniqueResult();
    } catch (RuntimeException ex) {
        throw ex;
    } finally {
        sessao.close();
    }
    return venda;
}

From source file:br.com.mandado.dao.BairroDAO.java

/**
 * @param codigo//www .  j  a v a  2 s.  com
 * @return
 */
public Bairro buscarPorCodigo(Long codigo) {
    Session sessao = HibernateUtil.getSessionFactory().openSession();
    Bairro bairro = null;

    try {
        Query consulta = sessao.getNamedQuery("Bairro.buscarPorCodigo");
        consulta.setLong("codigo", codigo);
        bairro = (Bairro) consulta.uniqueResult();
    } catch (RuntimeException ex) {
        throw ex;
    } finally {
        sessao.close();
    }

    return bairro;
}