List of usage examples for org.hibernate Query setCacheable
Query<R> setCacheable(boolean cacheable);
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); 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);//from w ww. j a va2 s .c om 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./*from www . ja va2s .c o m*/ * * @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 ww. j a v a2 s. c o m*/ 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); query.setCacheRegion("query.ExFormaDocumento"); final List<ExFormaDocumento> l = query.list(); if (l.size() != 1) return null; return l.get(0); }
From source file:br.gov.jfrj.siga.wf.dao.WfDao.java
License:Open Source License
/** * Pesquisa as configuraes que so semelhantes ao exemplo * /*from ww w .ja v a 2 s . c o m*/ * @param exemplo * Uma configurao de exemplo para a pesquisa. * @return Lista de configuraes encontradas. */ public List<WfConfiguracao> consultar(final WfConfiguracao exemplo) { Query query = getSessao().getNamedQuery("consultarWfConfiguracoes"); query.setLong("idTpConfiguracao", exemplo.getCpTipoConfiguracao().getIdTpConfiguracao()); query.setCacheable(true); query.setCacheRegion(CACHE_QUERY_CONFIGURACAO); return query.list(); }
From source file:br.mdarte.exemplo.academico.cd.CursoDAO.java
/** * Lista todos os objetos./*from w ww .j a va2 s. co m*/ * * @return Lista de objetos */ public List<AbstractEntity> list(PaginationStrategy paginacao, String propriedade, Boolean desc) throws DAOException { try { Session session = currentSession(); String hql = "from br.mdarte.exemplo.academico.cd.Curso"; if (propriedade != null && !propriedade.equals("")) { String order = desc.booleanValue() ? " desc" : " asc"; hql += " order by " + propriedade + order; } org.hibernate.Query qry = session.createQuery(hql); if (paginacao == null) paginacao = new NoPagination(); paginacao.paginateResult(qry); qry.setCacheable(true); return qry.list(); } catch (HibernateException h) { throw new DAOException(h); } }
From source file:br.mdarte.exemplo.academico.cd.CursoDAO.java
public List<AbstractEntity> list() throws DAOException { try {/*from w ww . j a v a 2 s .c om*/ Session session = currentSession(); org.hibernate.Query qry = session.createQuery("from br.mdarte.exemplo.academico.cd.Curso"); qry.setCacheable(true); List res = qry.list(); return res; } catch (HibernateException h) { throw new DAOException(h); } }
From source file:br.mdarte.exemplo.academico.cd.CursoDAO.java
public List<AbstractEntity> filter(DataObject vo, PaginationStrategy paginacao) throws DAOException { try {//from w ww .ja v a 2s.c om Object obj = handleFilter(vo); if (paginacao == null) paginacao = new NoPagination(); if (obj instanceof org.hibernate.Query) { org.hibernate.Query res = (org.hibernate.Query) obj; paginacao.paginateResult(res); res.setCacheable(true); return res.list(); } else if (obj instanceof org.hibernate.Criteria) { org.hibernate.Criteria res = (org.hibernate.Criteria) obj; paginacao.paginateResult(res); res.setCacheable(true); return res.list(); } else return null; } catch (HibernateException h) { throw new DAOException(h); } }
From source file:br.mdarte.exemplo.academico.cd.CursoDAO.java
/** * /*from w w w. ja v a 2 s.c om*/ */ public static java.util.Collection getEstudantesByCurso(long id, PaginationStrategy paginacao) throws DAOException { try { Session session = currentSession(); //org.hibernate.Query qry = session.createQuery("select t2 from br.mdarte.exemplo.academico.cd.Curso as t1 inner join t1.estudantes as t2 where t1.id = " + id); org.hibernate.Query qry = session.createQuery( "select elements(t1.estudantes) from br.mdarte.exemplo.academico.cd.Curso as t1 where t1.id = " + id); if (paginacao == null) paginacao = new NoPagination(); paginacao.paginateResult(qry); qry.setCacheable(true); return qry.list(); } catch (HibernateException h) { throw new DAOException(h); } }