List of usage examples for org.hibernate Criteria addOrder
public Criteria addOrder(Order order);
From source file:br.gov.jfrj.siga.dp.dao.CpDao.java
License:Open Source License
public <T> List<T> listarAtivos(Class<T> clazz, String orderBy) { Criteria c = getSessao().createCriteria(clazz); if (orderBy != null) { c.addOrder(Order.asc(orderBy)); }//from w ww . j a v a 2 s .co m c.add(Restrictions.eq("hisAtivo", 1)); return c.list(); }
From source file:br.gov.jfrj.siga.dp.dao.CpDao.java
License:Open Source License
public List<CpModelo> listarModelosOrdenarPorNome(String script) throws Exception { final Criteria crit = getSessao().createCriteria(CpModelo.class); crit.add(Property.forName("hisDtFim").isNull()); crit.createAlias("cpOrgaoUsuario", "o", Criteria.LEFT_JOIN); crit.addOrder(Order.desc("o.siglaOrgaoUsu")); List<CpModelo> l = new ArrayList<CpModelo>(); for (CpModelo mod : (List<CpModelo>) crit.list()) if (script != null && script.trim().length() != 0) { if (mod.getConteudoBlobString() != null && mod.getConteudoBlobString().contains(script)) l.add(mod);/*from w w w .j a v a2 s . com*/ } else l.add(mod); return l; }
From source file:br.gov.jfrj.siga.dp.dao.CpDao.java
License:Open Source License
public List<DpPessoa> consultarPorMatriculaEOrgao(Long matricula, Long idOrgaoUsu, boolean pessoasFinalizadas, boolean ordemDesc) { Criteria c = HibernateUtil.getSessao().createCriteria(DpPessoa.class); c.add(Restrictions.eq("matricula", matricula)); c.add(Restrictions.eq("orgaoUsuario.idOrgaoUsu", idOrgaoUsu)); if (pessoasFinalizadas) { c.add(Restrictions.isNotNull("dataFimPessoa")); } else {//from w w w .j a v a2s. com c.add(Restrictions.isNull("dataFimPessoa")); } if (ordemDesc) { c.addOrder(Order.desc("dataInicioPessoa")); } else { c.addOrder(Order.asc("dataInicioPessoa")); } return c.list(); }
From source file:br.gov.jfrj.siga.dp.dao.CpDao.java
License:Open Source License
public List<?> consultarFechadosPorIdExterna(Class<?> clazz, String idExterna, Long idOrgaoUsu) { if (clazz == DpLotacao.class) { Criteria c = HibernateUtil.getSessao().createCriteria(DpLotacao.class); c.add(Restrictions.eq("ideLotacao", idExterna)); c.add(Restrictions.eq("orgaoUsuario.idOrgaoUsu", idOrgaoUsu)); c.add(Restrictions.isNotNull("dataFimLotacao")); c.addOrder(Order.desc("dataInicioLotacao")); return c.list(); }//from w ww.j ava 2 s . c om if (clazz == DpCargo.class) { Criteria c = HibernateUtil.getSessao().createCriteria(DpCargo.class); c.add(Restrictions.eq("ideCargo", idExterna)); c.add(Restrictions.eq("orgaoUsuario.idOrgaoUsu", idOrgaoUsu)); c.add(Restrictions.isNotNull("dataFimCargo")); c.addOrder(Order.desc("dataInicioCargo")); return c.list(); } if (clazz == DpFuncaoConfianca.class) { Criteria c = HibernateUtil.getSessao().createCriteria(DpFuncaoConfianca.class); c.add(Restrictions.eq("ideFuncao", idExterna)); c.add(Restrictions.eq("orgaoUsuario.idOrgaoUsu", idOrgaoUsu)); c.add(Restrictions.isNotNull("dataFimFuncao")); c.addOrder(Order.desc("dataInicioFuncao")); return c.list(); } return null; }
From source file:br.gov.jfrj.siga.ex.bl.ExBL.java
License:Open Source License
public void numerarTudo(int aPartirDe) { List<ExDocumento> list = new ArrayList<ExDocumento>(); final Criteria countCrit = dao().getSessao().createCriteria(ExDocumento.class) .add(Restrictions.gt("idDoc", new Long(aPartirDe))); countCrit.setProjection(Projections.rowCount()); Integer totalDocs = ((Long) countCrit.uniqueResult()).intValue(); final Criteria crit = dao().getSessao().createCriteria(ExDocumento.class) .add(Restrictions.gt("idDoc", new Long(aPartirDe))); crit.setMaxResults(60);/*from w w w . ja v a 2 s . c o m*/ crit.addOrder(Order.asc("idDoc")); int index = 0; do { long inicio = System.currentTimeMillis(); //System.gc(); iniciarAlteracao(); crit.setFirstResult(index); list = crit.list(); for (ExDocumento doc : list) { index++; try { for (ExMovimentacao m : doc.getExMovimentacaoSet()) { m.setNumPaginas(m.getContarNumeroDePaginas()); dao().gravar(m); } } catch (Throwable e) { System.out.println("Erro ao marcar o doc " + doc); e.printStackTrace(); } if (index % 50 == 0) { // System.gc(); } System.out.print(doc.getIdDoc() + " ok - "); } ExDao.commitTransacao(); dao().getSessao().clear(); long duracao = System.currentTimeMillis() - inicio; System.out.println(); System.out.println(new SimpleDateFormat("HH:mm:ss").format(new Date()) + " " + String.valueOf(index) + " numerados de " + totalDocs); } while (list.size() > 0); //System.gc(); }
From source file:br.gov.jfrj.siga.ex.bl.ExBL.java
License:Open Source License
public void marcarTudo(int primeiro, int ultimo, boolean efetivar, boolean apenasTemporalidade, PrintWriter out) {//from w w w .j a v a 2 s. c o m List<ExDocumento> list = new ArrayList<ExDocumento>(); final Criteria countCrit = dao().getSessao().createCriteria(ExDocumento.class) .add(Restrictions.ge("idDoc", new Long(primeiro))); if (ultimo != 0) countCrit.add(Restrictions.le("idDoc", new Long(ultimo))); countCrit.setProjection(Projections.rowCount()); final Criteria crit = dao().getSessao().createCriteria(ExDocumento.class) .add(Restrictions.ge("idDoc", new Long(primeiro))); if (ultimo != 0) crit.add(Restrictions.le("idDoc", new Long(ultimo))); crit.setMaxResults(5); crit.addOrder(Order.asc("idDoc")); out.println("-----------------------------------------------"); out.print(new SimpleDateFormat("HH:mm:ss").format(new Date())); out.print(" - Remarcando documentos."); out.print(" Primeiro: "); out.println(primeiro); if (ultimo != 0) { out.print(" Ultimo: "); out.println(ultimo); } if (efetivar) out.println("***EFETIVAR!!***"); out.println("-----------------------------------------------"); int index = 0; do { long inicio = System.currentTimeMillis(); if (efetivar) iniciarAlteracao(); crit.setFirstResult(index); list = crit.list(); for (ExDocumento doc : list) { index++; StringBuilder msg = new StringBuilder(); try { StringBuilder marcasAnteriores = new StringBuilder(); for (ExMobil mob : doc.getExMobilSet()) { marcasAnteriores.append(mob.isGeral() ? "0" : mob.getNumSequencia()); marcasAnteriores.append(" - "); marcasAnteriores.append(mob.getMarcadoresDescrCompleta(apenasTemporalidade)); } atualizarMarcasTemporalidade(doc); StringBuilder marcasPosteriores = new StringBuilder(); for (ExMobil mob : doc.getExMobilSet()) { marcasPosteriores.append(mob.isGeral() ? "0" : mob.getNumSequencia()); marcasPosteriores.append(" - "); marcasPosteriores.append(mob.getMarcadoresDescrCompleta(apenasTemporalidade)); } if (!marcasAnteriores.toString().equals(marcasPosteriores.toString())) { msg.append("Marcas:"); msg.append("\n\tAntes: "); msg.append(marcasAnteriores); msg.append("\n\tDepois: "); msg.append(marcasPosteriores); } } catch (Throwable e) { msg.append("ERRO: "); msg.append(e.getMessage()); e.printStackTrace(out); } if (msg.length() > 0) { msg.insert(0, "\n"); msg.insert(0, doc.getCodigo()); msg.insert(0, " - "); msg.insert(0, new SimpleDateFormat("HH:mm:ss").format(new Date())); msg.insert(0, "\n"); out.println(msg); } } if (efetivar) { ExDao.commitTransacao(); //System.gc(); } dao().getSessao().clear(); } while (list.size() > 0); out.println("\n-----------------------------------------------"); out.print(new SimpleDateFormat("HH:mm:ss").format(new Date())); out.println(" - Fim"); out.println("-----------------------------------------------"); //System.gc(); }
From source file:br.gov.jfrj.siga.hibernate.ExDao.java
License:Open Source License
public List<ExFormaDocumento> listarTodosOrdenarPorDescricao() { final Criteria crit = getSessao().createCriteria(ExFormaDocumento.class); crit.addOrder(Order.asc("descrFormaDoc")); return crit.list(); }
From source file:br.gov.jfrj.siga.hibernate.ExDao.java
License:Open Source License
public List<ExFormaDocumento> listarTodosOrdenarPorSigla() { final Criteria crit = getSessao().createCriteria(ExFormaDocumento.class); crit.addOrder(Order.asc("siglaFormaDoc")); return crit.list(); }
From source file:br.gov.jfrj.siga.hibernate.ExDao.java
License:Open Source License
public void listarNaoIndexados(int aPartir, boolean irIndexando) throws Exception { long tempoIni = System.currentTimeMillis(); FullTextSession fullTextSession = Search.getFullTextSession(getSessao()); QueryParser parser = new QueryParser(Version.LUCENE_36, "idDoc", new StandardAnalyzer(Version.LUCENE_36)); final Criteria crit = getSessao().createCriteria(ExDocumento.class) .add(Restrictions.gt("idDoc", new Long(aPartir))); crit.setMaxResults(300);//from w w w . ja va2 s.c o m crit.addOrder(Order.asc("idDoc")); List<ExDocumento> list = new ArrayList<ExDocumento>(); int firstResult = 0; do { crit.setFirstResult(firstResult); list = crit.list(); for (ExDocumento doc : list) { firstResult++; if (doc.isIndexavel() && (fullTextSession .createFullTextQuery(new TermQuery(new Term("idDoc", String.valueOf(doc.getIdDoc()))), ExDocumento.class) .getResultSize() == 0)) { if (irIndexando) { System.out.println("listarNaoIndexados - indexando " + doc.getCodigo()); indexar(doc); } else { System.out.println("listarNaoIndexados - nao indexar " + doc.getCodigo()); } } } System.out.println("listarNaoIndexados - " + firstResult + " varridos"); getSessao().clear(); } while (list.size() > 0); System.out.println( "listarNaoIndexados - FIM " + (System.currentTimeMillis() - tempoIni) / 3600000 + " minutos"); }
From source file:br.gov.jfrj.siga.hibernate.ExDao.java
License:Open Source License
public void indexarTudo(Aguarde aguarde) throws Exception { System.out.println("Indexando documentos..."); long inicio = new Date().getTime(); try {/*from w w w. j a v a 2 s . c o m*/ FullTextSession fullTextSession = Search.getFullTextSession(getSessao()); Transaction deleteTx = fullTextSession.beginTransaction(); fullTextSession.purgeAll(ExDocumento.class); deleteTx.commit(); fullTextSession.clear(); getSessao().clear(); } catch (Throwable t) { // No havia documentos a excluir } final Criteria crit = getSessao().createCriteria(ExDocumento.class); int index = 0; FullTextSession fullTextSession = Search.getFullTextSession(getSessao()); fullTextSession.setFlushMode(FlushMode.MANUAL); fullTextSession.setCacheMode(CacheMode.IGNORE); crit.setMaxResults(30); crit.addOrder(Order.desc("idDoc")); List<ExDocumento> list; do { crit.setFirstResult(index); list = crit.list(); Transaction tx = fullTextSession.beginTransaction(); for (ExDocumento doc : list) { index++; // if (aguarde != null) // aguarde.setMensagem(String.valueOf(index) // + " documentos j indexados."); if (doc.isIndexavel()) fullTextSession.index(doc); if (index % 100 == 0) { //System.gc(); // fullTextSession.flush(); // fullTextSession.clear(); } } tx.commit(); fullTextSession.clear(); getSessao().clear(); System.out.print(String.valueOf(index) + " documentos j indexados. -- -- "); } while (list.size() > 0); //System.gc(); // fullTextSession.close(); System.out.println("Durao da indexao de documentos: " + (new Date().getTime() - inicio)); if (aguarde != null) aguarde.setMensagem(String.valueOf(index)); }