Example usage for org.hibernate Query setString

List of usage examples for org.hibernate Query setString

Introduction

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

Prototype

@Deprecated
@SuppressWarnings("unchecked")
default Query<R> setString(String name, String val) 

Source Link

Document

Bind a named String-valued parameter.

Usage

From source file:br.gov.jfrj.siga.dp.dao.CpDao.java

License:Open Source License

@SuppressWarnings("unchecked")
public CpPerfil consultarPorSigla(final CpPerfil o) {
    final Query query = getSessao().getNamedQuery("consultarPorSiglaCpGrupo");
    query.setString("siglaGrupo", o.getSigla());
    if (o.getOrgaoUsuario() != null)
        query.setLong("idOrgaoUsu", o.getOrgaoUsuario().getIdOrgaoUsu());
    else/*from w w w. j  a va  2 s.com*/
        query.setLong("idOrgaoUsu", 0);
    query.setCacheable(true);
    query.setCacheRegion(CACHE_QUERY_HOURS);
    final List<CpPerfil> l = query.list();
    if (l.size() != 1)
        return null;
    return l.get(0);
}

From source file:br.gov.jfrj.siga.dp.dao.CpDao.java

License:Open Source License

public int consultarQuantidade(final CpGrupoDaoFiltro o) {
    try {//  w w w.  j a  v  a 2s  .  c o  m
        final Query query;
        if (o.getNome() != null) {
            query = getSessao().getNamedQuery("consultarQuantidadeCpGrupoPorCpTipoGrupoIdENome");
            query.setString("siglaGrupo", o.getNome());
        } else {
            query = getSessao().getNamedQuery("consultarQuantidadeCpGrupoPorCpTipoGrupoId");
        }

        if (o.getIdTpGrupo() != null) {
            query.setLong("idTpGrupo", o.getIdTpGrupo());
        } else {
            query.setLong("idTpGrupo", 0);
        }
        final int l = ((Long) query.uniqueResult()).intValue();
        return l;
    } catch (final NullPointerException e) {
        return 0;
    }
}

From source file:br.gov.jfrj.siga.dp.dao.CpDao.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<CpGrupo> consultarPorFiltro(final CpGrupoDaoFiltro o, final int offset, final int itemPagina) {
    try {// www . ja v a2  s  .  c o  m
        final Query query;
        if (o.getNome() != null) {
            query = getSessao().getNamedQuery("consultarCpGrupoPorCpTipoGrupoIdENome");
            query.setString("siglaGrupo", o.getNome());
        } else {
            query = getSessao().getNamedQuery("consultarCpGrupoPorCpTipoGrupoId");
        }
        if (offset > 0) {
            query.setFirstResult(offset);
        }
        if (itemPagina > 0) {
            query.setMaxResults(itemPagina);
        }
        if (o.getIdTpGrupo() != null) {
            query.setLong("idTpGrupo", o.getIdTpGrupo());
        } else {
            query.setLong("idTpGrupo", 0);
        }
        final List<CpGrupo> l = query.list();
        return l;
    } catch (final NullPointerException e) {
        return null;
    }
}

From source file:br.gov.jfrj.siga.dp.dao.CpDao.java

License:Open Source License

public DpPessoa consultarPorEmail(final String email) {

    final Query qry = getSessao().getNamedQuery("consultarPorEmail");
    qry.setString("emailPessoa", email);
    final DpPessoa pes = (DpPessoa) qry.uniqueResult();
    return pes;//from  ww w. j av  a2s  . c  o  m
}

From source file:br.gov.jfrj.siga.dp.dao.CpDao.java

License:Open Source License

@SuppressWarnings("unchecked")
public DpPessoa consultarPorSigla(final DpPessoa o) {
    try {//from  w  w w .j  a v a  2s . co m
        final Query query = getSessao().getNamedQuery("consultarPorSiglaDpPessoa");
        query.setString("sesb", o.getSesbPessoa());
        query.setLong("matricula", o.getMatricula());
        /*
         * if (o.getOrgaoUsuario().getIdOrgaoUsu() != null)
         * query.setLong("idOrgaoUsu", o.getOrgaoUsuario().getIdOrgaoUsu());
         * else query.setLong("idOrgaoUsu", 0);
         */

        final List<DpPessoa> l = query.list();
        if (l.size() != 1)
            return null;
        return l.get(0);
    } catch (final NullPointerException e) {
        return null;
    }
}

From source file:br.gov.jfrj.siga.dp.dao.CpDao.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<CpLocalidade> consultarLocalidadesPorUF(final String siglaUF) {

    Query query = getSessao().createQuery("from CpLocalidade l where l.UF.nmUF = :siglaUF");
    query.setString("siglaUF", siglaUF);
    List l = query.list();/*from   ww w. j a v  a  2  s . com*/
    return l;
}

From source file:br.gov.jfrj.siga.dp.dao.CpDao.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<DpPessoa> consultarPorFiltro(final DpPessoaDaoFiltro flt, final int offset, final int itemPagina) {
    try {//from   w  w w .  j a v a 2  s.c  om
        final Query query;

        if (!flt.isBuscarFechadas())
            query = getSessao().getNamedQuery("consultarPorFiltroDpPessoa");
        else
            query = getSessao().getNamedQuery("consultarPorFiltroDpPessoaInclusiveFechadas");

        if (offset > 0) {
            query.setFirstResult(offset);
        }
        if (itemPagina > 0) {
            query.setMaxResults(itemPagina);
        }
        query.setString("nome", flt.getNome().toUpperCase().replace(' ', '%'));

        if (!flt.isBuscarFechadas())
            query.setString("situacaoFuncionalPessoa", flt.getSituacaoFuncionalPessoa());

        if (flt.getIdOrgaoUsu() != null)
            query.setLong("idOrgaoUsu", flt.getIdOrgaoUsu());
        else
            query.setLong("idOrgaoUsu", 0);

        if (flt.getLotacao() != null)
            query.setLong("lotacao", flt.getLotacao().getId());
        else
            query.setLong("lotacao", 0);

        final List<DpPessoa> l = query.list();
        return l;
    } catch (final NullPointerException e) {
        return null;
    }
}

From source file:br.gov.jfrj.siga.dp.dao.CpDao.java

License:Open Source License

public int consultarQuantidade(final DpPessoaDaoFiltro flt) {
    try {//  w  ww  .j  a v  a 2s.co  m
        final Query query;

        if (!flt.isBuscarFechadas())
            query = getSessao().getNamedQuery("consultarQuantidadeDpPessoa");
        else
            query = getSessao().getNamedQuery("consultarQuantidadeDpPessoaInclusiveFechadas");

        query.setString("nome", flt.getNome().toUpperCase().replace(' ', '%'));

        if (!flt.isBuscarFechadas())
            query.setString("situacaoFuncionalPessoa", flt.getSituacaoFuncionalPessoa());

        if (flt.getIdOrgaoUsu() != null)
            query.setLong("idOrgaoUsu", flt.getIdOrgaoUsu());
        else
            query.setLong("idOrgaoUsu", 0);
        if (flt.getLotacao() != null)
            query.setLong("lotacao", flt.getLotacao().getId());
        else
            query.setLong("lotacao", 0);

        final int l = ((Long) query.uniqueResult()).intValue();
        return l;
    } catch (final NullPointerException e) {
        return 0;
    }
}

From source file:br.gov.jfrj.siga.dp.dao.CpDao.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<CpIdentidade> consultaIdentidadesCadastrante(final String nmUsuario, boolean fAtiva)
        throws AplicacaoException {
    try {//  www  .  j a v a  2s. co  m
        final Query qry = getSessao().getNamedQuery(
                fAtiva ? "consultarIdentidadeCadastranteAtiva" : "consultarIdentidadeCadastrante");
        qry.setString("nmUsuario", nmUsuario);
        // Verifica se existe numeros no login do usuario
        if (nmUsuario.substring(2).matches("^[0-9]*$"))
            qry.setString("sesbPessoa", nmUsuario.substring(0, 2));
        else
            qry.setString("sesbPessoa", "RJ"); // se nnao ha numeros atribui
        // RJ
        // por default

        // Cache was disabled because it would interfere with the
        // "change password" action.
        qry.setCacheable(true);
        qry.setCacheRegion(CACHE_QUERY_SECONDS);
        final List<CpIdentidade> lista = (List<CpIdentidade>) qry.list();
        if (lista.size() == 0) {
            throw new AplicacaoException(
                    "Nao foi possivel localizar a identidade do usuario '" + nmUsuario + "'.");
        }
        return lista;
    } catch (Throwable e) {
        throw new AplicacaoException(
                "Ocorreu um erro tentando localizar a identidade do usuario '" + nmUsuario + "'.", 0, e);
    }
}

From source file:br.gov.jfrj.siga.dp.dao.CpDao.java

License:Open Source License

public CpOrgao getOrgaoFromSiglaExata(String sigla) {
    CpOrgao o = new CpOrgao();
    o.setSigla(sigla);//  w w w . ja va 2s . c  om

    final Query query = getSessao().getNamedQuery("consultarPorSiglaExataCpOrgao");
    query.setString("siglaOrgao", o.getSiglaOrgao());

    final List<CpOrgao> l = query.list();
    if (l.size() > 0)
        return l.get(0);

    return null;
}