List of usage examples for org.hibernate Query setCacheRegion
Query<R> setCacheRegion(String cacheRegion);
From source file:br.gov.jfrj.siga.dp.dao.CpDao.java
License:Open Source License
public int consultarQuantidade(final DpLotacaoDaoFiltro o) { try {//ww w .j av a2 s .c o m 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/*from w w w .java2s . c o 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); }
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 ww. j a va2 s. co m*/ 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
@SuppressWarnings("unchecked") public DpPessoa consultarPorIdInicial(final Long idInicial) { try {/* w w w .j av a 2s. c o m*/ final Query query = getSessao().getNamedQuery("consultarPorIdInicialDpPessoa"); query.setLong("idPessoaIni", idInicial); query.setCacheable(true); query.setCacheRegion(CACHE_QUERY_HOURS); 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<CpIdentidade> consultaIdentidadesCadastrante(final String nmUsuario, boolean fAtiva) throws AplicacaoException { try {/*from w w w. j a v a 2 s .c o 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 List<CpOrgaoUsuario> consultaCpOrgaoUsuario() { final Query qry = getSessao().getNamedQuery("consultarCpOrgaoUsuario"); // Renato: Alterei para fazer cache. Nao vejo porque nao possamos fazer // cache dessa consulta. qry.setCacheable(true);/*from w ww. j av a2 s. c o m*/ qry.setCacheRegion(CACHE_QUERY_HOURS); final List<CpOrgaoUsuario> lista = qry.list(); return lista; }
From source file:br.gov.jfrj.siga.dp.dao.CpDao.java
License:Open Source License
public List<CpModelo> consultaCpModelos() { final List<CpOrgaoUsuario> listaOrgUsu = consultaCpOrgaoUsuario(); listaOrgUsu.add(0, null);/* w w w .j a v a 2s . c o m*/ final Query qry = getSessao().getNamedQuery("consultarCpModelos"); qry.setCacheable(true); qry.setCacheRegion(CACHE_QUERY_SECONDS); final List<CpModelo> lista = qry.list(); final List<CpModelo> listaFinal = new ArrayList<CpModelo>(); for (CpOrgaoUsuario orgUsu : listaOrgUsu) { boolean fFound = false; for (CpModelo mod : lista) { if ((mod.getCpOrgaoUsuario() == null && orgUsu == null) || (mod.getCpOrgaoUsuario() != null && orgUsu != null && mod.getCpOrgaoUsuario().getId().equals(orgUsu.getId()))) { listaFinal.add(mod); fFound = true; } } if (!fFound) { CpModelo modNew = new CpModelo(); modNew.setCpOrgaoUsuario(orgUsu); listaFinal.add(modNew); } } return listaFinal; }
From source file:br.gov.jfrj.siga.hibernate.ExDao.java
License:Open Source License
/** * Grava na tabela Ex_Modelo o conteudo do array de byte como um blob. O * mtodo no usa as facilidade do HIBERNATE em virtude da ausencia de * suporte para estes campos./* w ww . ja va2 s.c om*/ * * @param modelo * - O objeto da Classe contendo um array de bytes para gravar. * @return O objeto aps a gravao * @throws SQLException * @throws AplicacaoException */ // public void gravarConteudoBlob(final ExModelo modelo) throws // SQLException, // AplicacaoException { // // final StringBuilder upd = new StringBuilder("UPDATE EX_MODELO " // + "SET CONTEUDO_BLOB_MOD = empty_blob() WHERE ID_MOD = ?"); // final StringBuilder cmd = new StringBuilder( // "SELECT CONTEUDO_BLOB_MOD FROM EX_MODELO " // + "WHERE ID_MOD= ? FOR UPDATE"); // final Connection conn = getSessao().connection(); // PreparedStatement psBlob = conn.prepareStatement(upd.toString()); // psBlob.setLong(1, modelo.getIdMod()); // final int i = psBlob.executeUpdate(); // if (i < 1) // throw new AplicacaoException( // "Ocorreu ao inserir Blob em Documento " + "que no existe"); // psBlob.close(); // psBlob = conn.prepareStatement(cmd.toString()); // psBlob.setLong(1, modelo.getIdMod()); // final ResultSet rset = psBlob.executeQuery(); // rset.next(); // final Blob blob = rset.getBlob("CONTEUDO_BLOB_MOD"); // final OutputStream blobOutputStream = blob.setBinaryStream(0); // try { // blobOutputStream.write(modelo.getConteudoBlobMod2()); // blobOutputStream.close(); // } catch (final IOException e) { // throw new AplicacaoException("Ocorreu um erro ao inserir o blob", // 0, e); // } finally { // psBlob.close(); // } // // } public List<ExNivelAcesso> listarOrdemNivel() { Query query = getSessao().getNamedQuery("listarOrdemNivel"); query.setCacheable(true); query.setCacheRegion("query.ExNivelAcesso"); return query.list(); }
From source file:br.gov.jfrj.siga.hibernate.ExDao.java
License:Open Source License
public List<ExConfiguracao> consultar(final ExConfiguracao exemplo) { CpTipoConfiguracao tpConf = exemplo.getCpTipoConfiguracao(); CpOrgaoUsuario orgao = exemplo.getOrgaoUsuario(); StringBuffer sbf = new StringBuffer(); sbf.append("select * from siga.ex_configuracao ex inner join " + Catalogs.CORPORATIVO + ".cp_configuracao cp on ex.id_configuracao_ex = cp.id_configuracao "); sbf.append("" + "where 1 = 1"); if (tpConf != null && tpConf.getIdTpConfiguracao() != null && tpConf.getIdTpConfiguracao() != 0) { sbf.append(" and cp.id_tp_configuracao = "); sbf.append(exemplo.getCpTipoConfiguracao().getIdTpConfiguracao()); }//from w w w . ja v a2 s.c om if (exemplo.getExTipoMovimentacao() != null && exemplo.getExTipoMovimentacao().getIdTpMov() != null && exemplo.getExTipoMovimentacao().getIdTpMov() != 0) { sbf.append(" and ex.id_tp_mov = "); sbf.append(exemplo.getExTipoMovimentacao().getIdTpMov()); } if (exemplo.getExFormaDocumento() != null && exemplo.getExFormaDocumento().getIdFormaDoc() != null) { sbf.append(" and (ex.id_forma_doc = "); sbf.append(exemplo.getExFormaDocumento().getIdFormaDoc()); sbf.append(" or (ex.id_mod is null and ex.id_forma_doc is null and ex.id_tp_forma_doc is null)"); sbf.append(" or (ex.id_forma_doc is null and ex.id_tp_forma_doc = "); sbf.append(exemplo.getExFormaDocumento().getExTipoFormaDoc().getId()); sbf.append(" ))"); } if (exemplo.getExModelo() != null && exemplo.getExModelo().getIdMod() != null && exemplo.getExModelo().getIdMod() != 0) { sbf.append(" and (ex.id_mod = "); sbf.append(exemplo.getExModelo().getIdMod()); sbf.append(" or (ex.id_mod is null and ex.id_forma_doc is null and ex.id_tp_forma_doc is null)"); sbf.append(" or (ex.id_mod is null and ex.id_forma_doc = "); sbf.append(exemplo.getExModelo().getExFormaDocumento().getId()); sbf.append(")"); sbf.append(" or (ex.id_mod is null and ex.id_forma_doc is null and ex.id_tp_forma_doc = "); sbf.append(exemplo.getExModelo().getExFormaDocumento().getExTipoFormaDoc().getId()); sbf.append(" ))"); } if (orgao != null && orgao.getId() != null && orgao.getId() != 0) { sbf.append(" and (cp.id_orgao_usu = "); sbf.append(orgao.getId()); sbf.append(" or cp.id_lotacao in (select id_lotacao from " + Catalogs.CORPORATIVO + ".dp_lotacao lot where lot.id_orgao_usu= "); sbf.append(orgao.getId()); sbf.append(")"); sbf.append(" or cp.id_pessoa in (select id_pessoa from " + Catalogs.CORPORATIVO + ".dp_pessoa pes where pes.id_orgao_usu = "); sbf.append(orgao.getId()); sbf.append(")"); sbf.append(" or cp.id_cargo in (select id_cargo from " + Catalogs.CORPORATIVO + ".dp_cargo cr where cr.id_orgao_usu = "); sbf.append(orgao.getId()); sbf.append(")"); sbf.append(" or cp.id_funcao_confianca in (select id_funcao_confianca from " + Catalogs.CORPORATIVO + ".dp_funcao_confianca fc where fc.id_orgao_usu = "); sbf.append(orgao.getId()); sbf.append(")"); sbf.append( " or (cp.id_orgao_usu is null and cp.id_lotacao is null and cp.id_pessoa is null and cp.id_cargo is null and cp.id_funcao_confianca is null"); sbf.append(")"); sbf.append(")"); sbf.append("order by ex.id_configuracao_ex"); } Query query = getSessao().createSQLQuery(sbf.toString()).addEntity(ExConfiguracao.class); query.setCacheable(true); query.setCacheRegion("query.ExConfiguracao"); return query.list(); }
From source file:br.gov.jfrj.siga.hibernate.ExDao.java
License:Open Source License
public ExFormaDocumento consultarPorSigla(ExFormaDocumento o) { final Query query = getSessao().getNamedQuery("consultarSiglaForma"); query.setString("sigla", o.getSigla()); query.setCacheable(true);/*from w w w . ja v a 2 s.c om*/ query.setCacheRegion("query.ExFormaDocumento"); final List<ExFormaDocumento> l = query.list(); if (l.size() != 1) return null; return l.get(0); }