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 int consultarQuantidade(final DpLotacaoDaoFiltro o) { try {/*from w w w.j a va2s . 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/*from ww w . j a v a2s . com*/ 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/*www.jav a2 s.c o 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 {//from w ww. j a va 2s.co 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 {//w ww. j ava 2s .com 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
@SuppressWarnings("unchecked") public List<CpIdentidade> consultaIdentidades(final DpPessoa pessoa) { final Query qry = getSessao().getNamedQuery("consultarIdentidades"); qry.setLong("idPessoaIni", pessoa.getIdInicial()); qry.setCacheable(false); final List<CpIdentidade> lista = qry.list(); return lista; }
From source file:br.gov.jfrj.siga.dp.dao.CpDao.java
License:Open Source License
public Date consultarDataUltimaAtualizacao() throws AplicacaoException { // Query sql = (Query) getSessao().getNamedQuery("consultarDataUltimaAtualizacao"); Query sql = (Query) HibernateUtil.getSessionFactory().openStatelessSession() .getNamedQuery("consultarDataUltimaAtualizacao"); sql.setCacheable(false); List result = sql.list();/*from ww w . ja v a2s. c o m*/ if (result.size() != 1) throw new AplicacaoException( "Nao foi possivel obter a data e a hora de atualizacao das configuracoes."); Date dtIni = (Date) ((Object[]) (result.get(0)))[0]; Date dtFim = (Date) ((Object[]) (result.get(0)))[1]; return DateUtils.max(dtIni, dtFim); }
From source file:br.gov.jfrj.siga.dp.dao.CpDao.java
License:Open Source License
public List<CpConfiguracao> consultar(final CpConfiguracao exemplo) { Query query = getSessao().getNamedQuery("consultarCpConfiguracoes"); query.setLong("idTpConfiguracao", exemplo.getCpTipoConfiguracao().getIdTpConfiguracao()); query.setCacheable(false); // query.setCacheRegion(CACHE_QUERY_CONFIGURACAO); return query.list(); }
From source file:br.gov.jfrj.siga.dp.dao.CpDao.java
License:Open Source License
public List<CpConfiguracao> consultarConfiguracoesPorTipo(final Long idTipoConfig) { Query query = getSessao().getNamedQuery("consultarCpConfiguracoesPorTipo"); query.setLong("idTpConfiguracao", idTipoConfig); query.setCacheable(false); return query.list(); }
From source file:br.gov.jfrj.siga.dp.dao.CpDao.java
License:Open Source License
public List<CpConfiguracao> porLotacaoPessoaServicoTipo(final CpConfiguracao exemplo) { Query query = getSessao().getNamedQuery("consultarCpConfiguracoesPorLotacaoPessoaServicoTipo"); query.setLong("idPessoa", exemplo.getDpPessoa().getIdPessoa()); query.setLong("idLotacao", exemplo.getLotacao().getIdLotacao()); query.setLong("idTpConfiguracao", exemplo.getCpTipoConfiguracao().getIdTpConfiguracao()); query.setLong("idServico", exemplo.getCpServico().getIdServico()); // kpf: com o cache true, as configuracoes sao exibidas de forma forma // errada apos a primeira query.setCacheable(false); // query.setCacheRegion(CACHE_QUERY_CONFIGURACAO); return query.list(); }