List of usage examples for org.hibernate SQLQuery setString
@Deprecated @SuppressWarnings("unchecked") default Query<R> setString(int position, String val)
From source file:boeken.BoekenDao.java
List getBoekenVanSchrijver(String schrijver) { SQLQuery query = sessie.createSQLQuery(""); query.addEntity("BOEKEN", Boek.class);//entities toevoegen juist?? query.setString(0, schrijver); return query.list(); }
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); qtdArq++;/* w w w . java 2 s . c o m*/ } List<Object[]> entities = q.list(); return entities; }
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 ava 2s .com*/ return false; }
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 ww w .j a va 2 s . c o m*/ * 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(); ////from w w w .j a va 2 s .co 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:celepsa.rrcc.da.DocumentoDA.java
public int registrarAdjunto(Tmadjunto objSistema, Tmdocumento objDocumento) throws Exception { String squery = "INSERT INTO Tmadjunto(id, tmDocumento_id, Nombre, eliminado, scodigo)" + "VALUES (:id,:doc, :nom, '0', :scod)"; logger.debug("In registrarStakeholderDocumentoAdjunto"); try {/*from w w w . jav a 2 s . c o m*/ org.hibernate.Transaction tx = session.beginTransaction(); SQLQuery query = session.createSQLQuery(squery); query.setInteger("id", CrearIDAdjunto()); query.setInteger("doc", objDocumento.getId()); query.setString("nom", objSistema.getNombre()); query.setString("scod", objSistema.getScodigo()); int res = query.executeUpdate(); tx.commit(); logger.debug("Out registrarStakeholderDocumentoAdjunto"); return res; } catch (NumberFormatException | HibernateException e) { logger.error(e.getMessage()); throw e; } }
From source file:com.aw.core.db.support.WhereBuilder2.java
License:Open Source License
public void setParams(SQLQuery sqlQuery) { for (int i = 0; i < params.size(); i++) { Object param = params.get(i); if (param instanceof Long) sqlQuery.setLong(i, (Long) param); else if (param instanceof Integer) sqlQuery.setInteger(i, (Integer) param); else if (param instanceof Date) sqlQuery.setDate(i, (Date) param); else if (param instanceof String) sqlQuery.setString(i, (String) param); else if (param instanceof BigDecimal) sqlQuery.setBigDecimal(i, (BigDecimal) param); else if (param == null) sqlQuery.setParameter(i, null); else/* www . j a v a 2 s . co m*/ throw new IllegalArgumentException("Implementar codigo param:" + param.getClass()); } //To change body of created methods use File | Settings | File Templates. }
From source file:com.bitranger.parknshop.common.dao.impl.PersistantMap.java
License:Open Source License
@Override public Object get(final String key) { Assert.notBlank(key);/* w w w.j av a 2s.c o m*/ byte[] b = getHibernateTemplate().execute(new HibernateCallback<byte[]>() { @Override public byte[] doInHibernate(Session arg0) throws HibernateException, SQLException { SQLQuery query = arg0.createSQLQuery("select val from ps_key_values where key = ?"); query.setString(0, key); query.addScalar("val", Hibernate.BLOB); return (byte[]) query.uniqueResult(); } }); return ObjUtils.fromBytes(b); }
From source file:com.bitranger.parknshop.common.dao.impl.PersistantMap.java
License:Open Source License
@Override public void put(final String key, Object value) { Assert.isTrue(value instanceof Serializable, "value must be Serializable"); final byte[] b = ObjUtils.toBytes(value); getHibernateTemplate().execute(new HibernateCallback<Void>() { @Override//from w w w . j a v a2s.c o m public Void doInHibernate(Session arg0) throws HibernateException, SQLException { SQLQuery query = arg0.createSQLQuery("insert into ps_key_value(key, val)values(?,?)"); query.setString(0, key); query.setBinary(1, b); query.executeUpdate(); return null; } }); }
From source file:com.bitranger.parknshop.common.dao.impl.PsItemDAO.java
License:Open Source License
@SuppressWarnings("unchecked") @Override/*from w w w . j a va 2s.c o m*/ public List<PsItem> searchByKeyword(final String q) { return getHibernateTemplate().executeFind(new HibernateCallback<List<PsItem>>() { @Override public List<PsItem> doInHibernate(Session session) throws HibernateException, SQLException { SQLQuery query = session.createSQLQuery(" SELECT IT.*, " + " MATCH (`name`, `introduction`) AGAINST (? IN NATURAL LANGUAGE MODE) AS relevance " + " FROM `ps_item` as IT " + " ORDER BY relevance DESC"); query.setString(0, q); query.addEntity(PsItem.class); return query.list(); } }); }