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.gvt.eng.vod.dao.IngestDAO.java

public Long countAllDataIngestForRevision(IpvodContentProvider ipvodContentProvider, UriInfo uriInfo) {
    // HQL dos dados, todos os campos devem ter o mesmo nome dos atributos
    // no IngestVO
    StringBuilder hql = new StringBuilder();
    hql.append("select ");
    hql.append("count(ins.id) ");
    hql.append("from ");
    hql.append("IpvodIngestStage ins ");
    hql.append("inner join ins.ipvodAsset as asset ");
    hql.append("inner join ins.ipvodAsset.ipvodCategory1 as assetCategory ");
    hql.append("where ");
    hql.append("ins.stageType.id = 7 ");
    hql.append("and (asset.isRevised is null or asset.isRevised = 0) ");
    hql.append("and asset.licenseWindowEnd > sysdate ");
    if (ipvodContentProvider != null) {
        hql.append(" and asset.ipvodContentProvider.contentProviderId = "
                + ipvodContentProvider.getContentProviderId());
    }//ww w  .  ja  va 2 s .  c om

    if (uriInfo.getQueryParameters().getFirst(IpvodConstants.URLPARAM_NOT_CATEGORIZED) != null) {
        hql.append(" and asset.ipvodVisualMenuAsset is empty ");
    }

    Map<String, Object> parameters = parseUriInfo(uriInfo);
    Filter filter = (Filter) parameters.get("filters");
    if (filter != null && !filter.getRules().isEmpty()) {
        if (filter.getGroupOp().equals("AND")) {
            for (FilterRules rule : filter.getRules()) {
                hql.append(
                        " and  upper(" + rule.getField() + ") like '%" + rule.getData().toUpperCase() + "%' ");
            }
        } else {
            StringBuilder orClause = new StringBuilder();
            orClause.append(" and ( ");
            for (int i = 0; i < filter.getRules().size(); i++) {
                FilterRules rule = filter.getRules().get(i);
                if (i > 0) {
                    orClause.append(" or ");
                }
                orClause.append(
                        " upper(" + rule.getField() + ") like '%" + rule.getData().toUpperCase() + "%' ");
            }
            orClause.append(" ) ");
            hql.append(orClause);
        }
    }

    Query query = getSession().createQuery(String.valueOf(hql));
    return (Long) query.uniqueResult();
}

From source file:br.com.gvt.eng.vod.dao.IngestDAO.java

public Long countDataIngestBeforePlataform(IpvodContentProvider ipvodContentProvider, UriInfo uriInfo) {
    // HQL dos dados, todos os campos devem ter o mesmo nome dos atributos
    // no IngestVO
    StringBuilder hql = new StringBuilder();
    hql.append("select ");
    hql.append("count(ins.id) ");
    hql.append("from ");
    hql.append("IpvodIngestStage ins ");
    hql.append("left outer join ins.ipvodAsset as asset ");
    hql.append("where ");
    hql.append("ins.stageType.id < 7 ");
    if (ipvodContentProvider != null) {
        hql.append(" and asset.ipvodContentProvider.contentProviderId = "
                + ipvodContentProvider.getContentProviderId());
    }/*from w  ww . j a va  2  s .  co m*/

    Map<String, Object> parameters = parseUriInfo(uriInfo);
    Filter filter = (Filter) parameters.get("filters");
    if (filter != null && !filter.getRules().isEmpty()) {
        if (filter.getGroupOp().equals("AND")) {
            for (FilterRules rule : filter.getRules()) {
                hql.append(
                        " and  upper(" + rule.getField() + ") like '%" + rule.getData().toUpperCase() + "%' ");
            }
        } else {
            StringBuilder orClause = new StringBuilder();
            orClause.append(" and ( ");
            for (int i = 0; i < filter.getRules().size(); i++) {
                FilterRules rule = filter.getRules().get(i);
                if (i > 0) {
                    orClause.append(" or ");
                }
                orClause.append(
                        " upper(" + rule.getField() + ") like '%" + rule.getData().toUpperCase() + "%' ");
            }
            orClause.append(" ) ");
            hql.append(orClause);
        }
    }

    Query query = getSession().createQuery(String.valueOf(hql));
    return (Long) query.uniqueResult();
}

From source file:br.com.hadronsoft.websige.model.dao.HibernateDAO.java

@Override
public T getEntityByHQLQuery(String stringQuery) {
    Query query = session.createQuery(stringQuery);
    return (T) query.uniqueResult();
}

From source file:br.com.hslife.catu.dao.GenericDao.java

License:Open Source License

protected Object queryUnique(Class classe, String sqlQuery) {
    //session = HibernateUtil.getSessionFactory().openSession();
    Object resultado = null;//from   w  w w. ja  v  a  2s. com
    try {
        Query queryResult = HibernateUtil.getSession().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.hslife.clickafacil.dao.ProdutoDao.java

License:Open Source License

public Produto buscarPorId(Integer id) throws Exception {
    String hql = "from Produto where idProduto = :id";
    Query q = HibernateUtil.getInstance().createQuery(hql);
    q.setInteger("id", id);
    return (Produto) q.uniqueResult();
}

From source file:br.com.hslife.clickafacil.dao.PromocaoDao.java

License:Open Source License

public Promocao buscarPorId(Integer id) throws Exception {
    String hql = "from Promocao where idPromocao = :id";
    Query q = HibernateUtil.getInstance().createQuery(hql);
    q.setInteger("id", id);
    return (Promocao) q.uniqueResult();
}

From source file:br.com.hslife.imobiliaria.dao.impl.HibernateGenericDao.java

License:Open Source License

public Object queryUnique(String namedQuery, Map<String, Object> params) {
    HibernateUtility.getSession().clear();
    Query query = HibernateUtility.getSession().getNamedQuery(namedQuery);
    for (String key : params.keySet()) {
        if (params.get(key) instanceof String) {
            query.setString(key, (String) params.get(key));
        }//w  w  w . j  a v  a2 s .  c o  m
        if (params.get(key) instanceof Long) {
            query.setLong(key, (Long) params.get(key));
        }
        if (params.get(key) instanceof Integer) {
            query.setInteger(key, (Integer) params.get(key));
        }
        if (params.get(key) instanceof Boolean) {
            query.setBoolean(key, (Boolean) params.get(key));
        }
        if (params.get(key) instanceof Double) {
            query.setDouble(key, (Double) params.get(key));
        }
        if (params.get(key) instanceof Date) {
            query.setDate(key, (Date) params.get(key));
        }
    }
    return query.uniqueResult();
}

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

License:Open Source License

public long countRegistroAuditoriaByUsuario(String usuario) {
    String sql = "select count(*) from orcamento.auditoria where usuario = '" + usuario + "'";
    Query query = getSession().createSQLQuery(sql);
    BigInteger queryResult = (BigInteger) query.uniqueResult();
    return queryResult.longValue();
}

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

License:Open Source License

public boolean existsLinkages(CartaoCredito cartaoCredito) {
    boolean result = true;

    String sqlFatura = "select count(id) from faturacartao where idConta = " + cartaoCredito.getConta().getId()
            + " and statusFaturaCartao <> 'ABERTA'";
    String sqlLancamento = "select count(*) from lancamentoconta l inner join conta cc on cc.id = l.idConta inner join cartaocredito c on c.id = cc.idCartao where c.id = "
            + cartaoCredito.getId();//  w ww.  j ava  2 s . c o m
    String sqlContaCompartilhada = "select count(*) from contacompartilhada cc inner join conta c on c.id = cc.idConta where c.id = "
            + cartaoCredito.getConta().getId();

    Query queryFatura = getSession().createSQLQuery(sqlFatura);
    Query queryLancamento = getSession().createSQLQuery(sqlLancamento);
    Query queryContaCompartilhada = getSession().createSQLQuery(sqlContaCompartilhada);

    BigInteger queryResultFatura = (BigInteger) queryFatura.uniqueResult();
    BigInteger queryResultLancamento = (BigInteger) queryLancamento.uniqueResult();
    BigInteger queryResultContaCompartilhada = (BigInteger) queryContaCompartilhada.uniqueResult();

    if (queryResultFatura.longValue() == 0 && queryResultLancamento.longValue() == 0
            && queryResultContaCompartilhada.longValue() == 0) {
        return false;
    }

    return result;
}

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

License:Open Source License

public boolean existsLinkages(CategoriaDocumento categoriaDocumento) {
    boolean result = true;

    String sql = "select count(id) from documento where idCategoriaDocumento = " + categoriaDocumento.getId();

    Query query = getSession().createSQLQuery(sql);

    BigInteger queryResult = (BigInteger) query.uniqueResult();

    if (queryResult.longValue() == 0) {
        return false;
    }/*from  w ww  . j a v  a2 s.  c  om*/

    return result;
}