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

public int consultarQuantidade(final CpOrgaoUsuarioDaoFiltro o) {
    try {/*from   w  w w . j  a  v a2 s . c  o  m*/
        final Query query = getSessao().getNamedQuery("consultarQuantidadeCpOrgao");
        String s = o.getNome();
        if (s != null)
            s = s.replace(' ', '%');
        query.setString("nome", s);

        query.setCacheable(true);
        query.setCacheRegion(CACHE_QUERY_HOURS);

        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<DpCargo> consultarPorFiltro(final DpCargoDaoFiltro o, final int offset, final int itemPagina) {
    try {//from ww  w . j  a  v a 2 s . c  o  m
        final Query query = getSessao().getNamedQuery("consultarPorFiltroDpCargo");
        if (offset > 0) {
            query.setFirstResult(offset);
        }
        if (itemPagina > 0) {
            query.setMaxResults(itemPagina);
        }
        String s = o.getNome();
        if (s != null)
            s = s.replace(' ', '%');
        query.setString("nome", s);

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

        final List<DpCargo> 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

@SuppressWarnings("unchecked")
public DpCargo consultarPorSigla(final DpCargo o) {
    final Query query = getSessao().getNamedQuery("consultarPorSiglaDpCargo");
    query.setString("siglaCargo", o.getSiglaCargo());

    final List<DpCargo> 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 DpCargoDaoFiltro o) {
    try {/*from   ww w. j  av a  2s  . c  om*/
        final Query query = getSessao().getNamedQuery("consultarQuantidadeDpCargo");
        String s = o.getNome();
        if (s != null)
            s = s.replace(' ', '%');
        query.setString("nome", s);

        if (o.getIdOrgaoUsu() != null)
            query.setLong("idOrgaoUsu", o.getIdOrgaoUsu());
        else
            query.setLong("idOrgaoUsu", 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<DpFuncaoConfianca> consultarPorFiltro(final DpFuncaoConfiancaDaoFiltro o, final int offset,
        final int itemPagina) {
    try {/*from  w w w . ja v a  2s .co  m*/
        final Query query = getSessao().getNamedQuery("consultarPorFiltroDpFuncaoConfianca");
        if (offset > 0) {
            query.setFirstResult(offset);
        }
        if (itemPagina > 0) {
            query.setMaxResults(itemPagina);
        }
        String s = o.getNome();
        if (s != null)
            s = s.replace(' ', '%');
        query.setString("nome", s);

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

        final List<DpFuncaoConfianca> 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 DpFuncaoConfiancaDaoFiltro o) {
    try {/*from  w  ww  .j a  v  a  2 s .com*/
        final Query query = getSessao().getNamedQuery("consultarQuantidadeDpFuncaoConfianca");
        String s = o.getNome();
        if (s != null)
            s = s.replace(' ', '%');
        query.setString("nome", s);
        if (o.getIdOrgaoUsu() != null)
            query.setLong("idOrgaoUsu", o.getIdOrgaoUsu());
        else
            query.setLong("idOrgaoUsu", 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<DpLotacao> consultarPorFiltro(final DpLotacaoDaoFiltro o, final int offset, final int itemPagina) {
    try {//  ww  w .  j ava 2 s  .co  m
        final Query query;

        if (!o.isBuscarFechadas())
            query = getSessao().getNamedQuery("consultarPorFiltroDpLotacao");
        else
            query = getSessao().getNamedQuery("consultarPorFiltroDpLotacaoInclusiveFechadas");
        if (offset > 0) {
            query.setFirstResult(offset);
        }
        if (itemPagina > 0) {
            query.setMaxResults(itemPagina);
        }
        query.setString("nome", o.getNome() == null ? "" : o.getNome().replace(' ', '%'));

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

        query.setCacheable(true);
        query.setCacheRegion(CACHE_QUERY_CONFIGURACAO);
        final List<DpLotacao> 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

@SuppressWarnings("unchecked")
public DpLotacao consultarPorSigla(final DpLotacao o) {
    final Query query = getSessao().getNamedQuery("consultarPorSiglaDpLotacao");
    query.setString("siglaLotacao", o.getSigla());
    if (o.getOrgaoUsuario() != null)
        if (o.getOrgaoUsuario().getIdOrgaoUsu() != null)
            query.setLong("idOrgaoUsu", o.getOrgaoUsuario().getIdOrgaoUsu());
        else//from w  w  w  . j a  va  2 s .co  m
            query.setLong("idOrgaoUsu", consultarPorSigla(o.getOrgaoUsuario()).getId());
    else
        query.setLong("idOrgaoUsu", 0);

    query.setCacheable(true);
    query.setCacheRegion(CACHE_QUERY_CONFIGURACAO);
    final List<DpLotacao> 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 DpLotacaoDaoFiltro o) {
    try {/*from  w  w  w .j av a2  s . c  om*/
        final Query query;

        if (!o.isBuscarFechadas())
            query = getSessao().getNamedQuery("consultarQuantidadeDpLotacao");
        else
            query = getSessao().getNamedQuery("consultarQuantidadeDpLotacaoInclusiveFechadas");

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

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

        query.setCacheable(true);
        query.setCacheRegion(CACHE_QUERY_CONFIGURACAO);
        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 CpGrupo consultarPorSigla(final CpGrupo o) {
    final Query query = getSessao().getNamedQuery("consultarPorSiglaCpGrupo");
    query.setString("siglaGrupo", o.getSigla());
    if (o.getOrgaoUsuario() != null)
        query.setLong("idOrgaoUsu", o.getOrgaoUsuario().getIdOrgaoUsu());
    else//  w w  w .  j a  va  2s . co m
        query.setLong("idOrgaoUsu", 0);
    query.setCacheable(true);
    query.setCacheRegion(CACHE_QUERY_HOURS);
    final List<CpGrupo> l = query.list();
    if (l.size() != 1)
        return null;
    return l.get(0);
}