List of usage examples for org.hibernate SQLQuery list
List<R> list();
From source file:br.com.muranodesign.dao.impl.NativeQueryDAOImpl.java
License:Creative Commons License
@SuppressWarnings("unchecked") public List<Object[]> listAll(String query) { SQLQuery q = getSession().createSQLQuery(query); List<Object[]> entities = q.list(); return entities; }
From source file:br.com.muranodesign.dao.impl.NativeQueryDAOImpl.java
License:Creative Commons License
@SuppressWarnings("unchecked") public List<Object[]> listArgs(String query, String... args) { SQLQuery q = getSession().createSQLQuery(query); int qtdArq = 0; for (String string : args) { q.setString(qtdArq, string);//from ww w . j a v a 2s. c o m qtdArq++; } List<Object[]> entities = q.list(); return entities; }
From source file:br.com.sgejs.dao.DaoDependente.java
public List<Dependente> listDependentes(long id) { SQLQuery q = sessao.createSQLQuery( "select * from Dependente d where d.id in (select sd.aluno_id from servidor_dependente sd where sd.servidor_id=:id)") .addEntity(classe);/* w w w. ja v a 2s .c o m*/ q.setParameter("id", id); return q.list(); }
From source file:br.com.sgejs.dao.DaoServidor.java
public Servidor getEscolaridade(Long id) { Criteria cri = sessao.createCriteria(classe, "s"); cri.add(Restrictions.eq("s.id", id)); cri.setProjection(Projections.projectionList().add(Projections.property("s.nome").as("nome")) .add(Projections.property("s.instrucao").as("instrucao")) .add(Projections.property("s.posGraduacao").as("posGraduacao"))) .setResultTransformer(new AliasToBeanResultTransformer(Servidor.class)); Servidor u = (Servidor) cri.uniqueResult(); SQLQuery q1 = sessao.createSQLQuery("select * from graduacao where servidor_id=" + id) .addEntity(Graduacao.class); List list = q1.list(); System.out.println("Graduacoes: " + list); u.setGraduacoes(list);//from w ww.j a v a 2 s . co m return u; }
From source file:br.com.sgejs.dao.DaoServidor.java
public boolean seExiste(String nome) throws HibernateException { SQLQuery query = sessao.createSQLQuery("select id from servidor where nome = :n"); query.setString("n", nome); if (query.list().size() > 0) { return true; }// w w w . j a va 2 s. c om return false; }
From source file:br.gov.jfrj.siga.dp.dao.CpDao.java
License:Open Source License
public Date consultarDataEHoraDoServidor() throws AplicacaoException { SQLQuery sql = (SQLQuery) getSessao().getNamedQuery("consultarDataEHoraDoServidor"); List result = sql.list(); if (result.size() != 1) throw new AplicacaoException("Nao foi possivel obter a data e a hora atuais do servidor."); return (Date) ((result.get(0))); }
From source file:br.gov.jfrj.siga.hibernate.ExDao.java
License:Open Source License
/** * Le da tabela o campo do tipo BLOB e converte para um array de bytes. * mtodo no usa as facilidade do HIBERNATE em virtude da ausencia de * suporte para estes campos.//from w ww .j a v a2s .com */ // public ExModelo consultarConteudoBlob(final ExModelo modelo) // throws SQLException { // final StringBuilder cmd = new StringBuilder( // "SELECT CONTEUDO_BLOB_MOD FROM EX_MODELO " + "WHERE ID_MOD= ? "); // final Connection conn = getSessao().connection(); // final PreparedStatement 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"); // if (blob != null) { // final byte[] ba = blob.getBytes(1, (int) blob.length()); // modelo.setConteudoBlobMod2(ba); // } // return modelo; // } public List consultarPaginaInicial(DpPessoa pes, DpLotacao lot, Integer idTipoForma) { try { SQLQuery sql = (SQLQuery) getSessao().getNamedQuery("consultarPaginaInicial"); sql.setLong("idPessoaIni", pes.getIdPessoaIni()); sql.setLong("idLotacaoIni", lot.getIdLotacaoIni()); sql.setInteger("idTipoForma", idTipoForma); List result = sql.list(); return result; } catch (final NullPointerException e) { return null; } }
From source file:br.gov.jfrj.siga.wf.relatorio.RelTempoDoc.java
License:Open Source License
/** * Retorna os docs no perodo indicado, ordenadas pelo tempo de * demora, podendo estar ou no finalizados. * /*from www . j av a2s . com*/ * Exemplo da query: * * SELECT PI.START_,PI.END_,VI.STRINGVALUE_,PI.ID_ FROM * SIGAWF.JBPM_PROCESSINSTANCE PI, (SELECT DISTINCT PROCESSINSTANCE_, * STRINGVALUE_ FROM SIGAWF.JBPM_VARIABLEINSTANCE WHERE NAME_ LIKE 'doc_%' * AND STRINGVALUE_ LIKE '%-_' AND STRINGVALUE_ IS NOT NULL) VI, (SELECT * * FROM SIGAWF.JBPM_PROCESSDEFINITION WHERE NAME_ = 'Contratao: fase de * anlise') PD WHERE PI.PROCESSDEFINITION_=PD.ID_ AND PI.END_ IS NOT NULL * AND PI.ID_ = VI.PROCESSINSTANCE_ AND (PI.START_ >= To_Date('01/03/2011') * and PI.START_ <= To_Date('31/03/2011')) AND (PI.END_ >= * To_Date('01/03/2011') and PI.END_ <= To_Date('31/05/2011')) ; * * * @param dataInicial * @param dataFinal * @param dataFinalAte * @param dataFinalDe * @param incluirAbertos * @return */ private Set<Doc> consultarDocs(String nomeProcedimento, Date dataInicialDe, Date dataInicialAte, Date dataFinalDe, Date dataFinalAte, Boolean incluirAbertos) { SQLQuery query = null; if (incluirAbertos) { query = (SQLQuery) WfDao.getInstance().getSessao() .createSQLQuery(getSQLConsultarDocumentosFinalizadosEAbertosNoPeriodo()); } else { query = (SQLQuery) WfDao.getInstance().getSessao() .createSQLQuery(getSQLConsultarDocumentosFinalizadosNoPeriodo()); } query.addScalar("START_", new CalendarType()); query.addScalar("END_", new CalendarType()); query.addScalar("STRINGVALUE_", new StringType()); query.addScalar("ID_", new LongType()); dataInicialAte = inclusiveData(dataInicialAte); dataFinalAte = inclusiveData(dataFinalAte); query.setString("nomeProcedimento", nomeProcedimento); query.setDate("dataInicialDe", dataInicialDe); query.setDate("dataInicialAte", dataInicialAte); query.setDate("dataFinalDe", dataFinalDe); query.setDate("dataFinalAte", dataFinalAte); List<Object[]> resultado = query.list(); Set<Doc> docs = new TreeSet<Doc>(new DocComparator()); for (Object[] o : resultado) { Doc s = new Doc(); Calendar inicio = (Calendar) o[0]; Calendar fim = (Calendar) o[1]; s.setNumeroDoc(o[2].toString()); s.setInicio(inicio); s.setFim(fim); s.setProcessInstanceID((Long) (o[3])); docs.add(s); } return docs; }
From source file:br.gov.jfrj.siga.wf.relatorio.RelTempoDocDetalhado.java
License:Open Source License
private Set<Tarefa> consultarTarefas(String nomeProcedimento, Date dataInicialDe, Date dataInicialAte, Date dataFinalDe, Date dataFinalAte, Boolean incluirAbertos) { // ArrayList<Tarefa> tarefas = new ArrayList<Tarefa>(); // Tarefa t1 = new Tarefa(); // Tarefa t2 = new Tarefa(); //// w w w . j av a 2s .c o m // t1.setNome("t1"); // t1.setDataFim("01/01/2000"); // t1.setDataInicio("01/01/2000"); // t1.setDuracao("5 seg"); // // t2.setNome("t2"); // t2.setDataFim("01/01/1999"); // t2.setDataInicio("01/01/1888"); // t2.setDuracao("5 seg"); // // tarefas.add(t1); // tarefas.add(t2); // return tarefas; // String sql = // "SELECT PI.START_,PI.END_,VI.STRINGVALUE_,PI.ID_ FROM JBPM_PROCESSINSTANCE PI, (SELECT DISTINCT PROCESSINSTANCE_, STRINGVALUE_ FROM JBPM_VARIABLEINSTANCE WHERE NAME_ LIKE 'doc_%' AND STRINGVALUE_ LIKE '%-_' AND STRINGVALUE_ IS NOT NULL) VI, (SELECT ID_ FROM JBPM_PROCESSDEFINITION WHERE NAME_ = :nomeProcedimento) PD WHERE PI.PROCESSDEFINITION_=PD.ID_ AND PI.END_ IS NOT NULL AND PI.ID_ = VI.PROCESSINSTANCE_ AND (PI.START_ >= :dataInicialDe and PI.START_ <= :dataInicialAte) AND (PI.END_ >= :dataFinalDe and PI.END_ <= :dataFinalAte)"; SQLQuery query = null; if (incluirAbertos) { query = (SQLQuery) WfDao.getInstance().getSessao() .createSQLQuery(getSQLConsultarDocumentosFinalizadosEAbertosNoPeriodo()); } else { query = (SQLQuery) WfDao.getInstance().getSessao() .createSQLQuery(getSQLConsultarDocumentosFinalizadosNoPeriodo()); } query.addScalar("stringvalue_", new StringType()); query.addScalar("pd_name", new StringType()); query.addScalar("p_start", new CalendarType()); query.addScalar("p_end", new CalendarType()); query.addScalar("t_name", new StringType()); query.addScalar("t_create", new CalendarType()); query.addScalar("t_end", new CalendarType()); query.setString("nomeProcedimento", nomeProcedimento); query.setDate("dataInicialDe", dataInicialDe); query.setDate("dataInicialAte", dataInicialAte); query.setDate("dataFinalDe", dataFinalDe); query.setDate("dataFinalAte", dataFinalAte); List<Object[]> resultado = query.list(); Set<Tarefa> tarefas = new TreeSet<Tarefa>(new TarefaComparator()); for (Object[] o : resultado) { Tarefa t = new Tarefa(); t.setDataInicioProcedimento((Calendar) o[2]); t.setDataFimProcedimento((Calendar) o[3]); t.setNumeroDocumento((String) o[0]); t.setNome((String) o[4]); t.setDataInicio((Calendar) o[5]); t.setDataFim((Calendar) o[6]); tarefas.add(t); } // Set<Doc> secs = new TreeSet<Doc>(new DocComparator()); // for (Object[] o : resultado) { // Doc s = new Doc(); // Calendar inicio = (Calendar) o[0]; // Calendar fim = (Calendar) o[1]; // s.setNumeroDoc(o[2].toString()); // s.setInicio(inicio); // s.setFim(fim); // s.setProcessInstanceID((Long) (o[3])); // secs.add(s); // } // return tarefas; }
From source file:ca.myewb.controllers.actions.csv.GlobalMemberList.java
License:Open Source License
public void handle(Context ctx) throws Exception { Vector<String[]> csvData = new Vector<String[]>(); csvData.add(new String[] { "First name", "Last name", "Email", "Phone", "Address1", "Suite", "Address2", "City", "Province", "Postal Code", "Country", "Student?", "Language", "Current?" }); String query = "select " + "u.firstname, " + "u.lastname, " + "u.email, " + "u.phone, " + "u.address1, " + "u.suite, " + "u.address2, " + "u.city, " + "u.province, " + "u.postalcode, " + "u.country, " + "(case when u.student = 'n' then 'no' else 'yes' end) as student, " + "(case when u.language = 'fr' then 'fr' else 'en' end) as language, " + "(case when u.expiry is null then 'no' else 'yes' end) as current " + "from users u, roles r " + "where u.id=r.userid and r.groupid=6 " + "and u.email is not null and u.email !='' " + "group by u.id"; SQLQuery hibQuery = hibernateSession.createSQLQuery(query).addScalar("firstname", Hibernate.STRING) .addScalar("lastname", Hibernate.STRING).addScalar("email", Hibernate.STRING) .addScalar("phone", Hibernate.STRING).addScalar("address1", Hibernate.STRING) .addScalar("suite", Hibernate.STRING).addScalar("address2", Hibernate.STRING) .addScalar("city", Hibernate.STRING).addScalar("province", Hibernate.STRING) .addScalar("postalcode", Hibernate.STRING).addScalar("country", Hibernate.STRING) .addScalar("student", Hibernate.STRING).addScalar("language", Hibernate.STRING) .addScalar("current", Hibernate.STRING); List memberList = hibQuery.list(); Iterator members = memberList.iterator(); while (members.hasNext()) { csvData.add(toStringArray((Object[]) members.next())); }/*from w ww . jav a 2 s . c o m*/ try { this.setInterpageVar("csvData", csvData); this.setInterpageVar("csvFileName", "members.csv"); } catch (IllegalStateException e) { //session timeout! throw new IllegalStateException("Session timeout on CSV!", e); } throw new RedirectionException(path + "/csvfile/members.csv"); }