List of usage examples for org.hibernate Query setParameter
@SuppressWarnings("unchecked") Query<R> setParameter(int position, Object val);
From source file:br.com.sescacre.sisrelat.dao.HistoricoChamadaDao.java
public HistoricoChamada pesquisaChamada(Long programa, Long config, Long ocorrencia, Date mes) { Session s = HibernateUtil.getSession(); Query q = s.createQuery("from HistoricoChamada hc where hc.cdprograma = :programa " + "and hc.cdconfig = :config and hc.sqocorrenc = :ocorrencia and hc.mes = :mes"); q.setParameter("programa", programa); q.setParameter("config", config); q.setParameter("ocorrencia", ocorrencia); q.setParameter("mes", mes); return (HistoricoChamada) q.uniqueResult(); }
From source file:br.com.sigen.Dao.ClienteDAO.java
public Cliente buscaPorCNPJ(String cpf) { Transaction tx = session.beginTransaction(); Cliente cliente = null;//from w ww . ja v a 2s . c om String consulta = "FROM Cliente WHERE cli_cpf = :cpf"; Query query = session.createQuery(consulta); query.setParameter("cpf", cpf); if (query.list().size() > 0) { cliente = (Cliente) query.list().get(0); } tx.commit(); return cliente; }
From source file:br.com.suricattus.surispring.framework.service.GenericRetrieveService.java
License:Open Source License
/** * Retorna a lista de entidades de acordo com a namedQuery informada. * @param <T>/*from w w w.j av a 2s. c o m*/ * @param classe * @param namedQuery * @param params * @return */ @SuppressWarnings("unchecked") public <T> List<T> retrieveByNamedQuery(Class<T> classe, String namedQuery, Object... params) { Query query = getSession().getNamedQuery(namedQuery); if (params != null) for (int i = 1; i <= params.length; i++) query.setParameter(i, params[i - 1]); return query.list(); }
From source file:br.com.suricattus.surispring.framework.service.GenericRetrieveService.java
License:Open Source License
/** * Retorna a lista de entidades de acordo com a namedQuery informada. * @param <T>/*from ww w . j a v a 2s.c om*/ * @param classe * @param namedQuery * @param params * @return */ @SuppressWarnings({ "unchecked", "rawtypes" }) public <T> List<T> retrieveByNamedQuery(Class<T> classe, String namedQuery, Map<String, Object> params) { Query query = getSession().getNamedQuery(namedQuery); if (params != null) { for (String paramName : params.keySet()) { Object param = params.get(paramName); if (param instanceof Collection) { query.setParameterList(paramName, (Collection) params.get(paramName)); } else if (param instanceof Object[]) { query.setParameterList(paramName, (Object[]) params.get(paramName)); } else { query.setParameter(paramName, params.get(paramName)); } } } return query.list(); }
From source file:br.com.suricattus.surispring.framework.service.GenericRetrieveService.java
License:Open Source License
/** * Retorna a entidade de acordo com a namedQuery informada. * @param <T>/*from w w w. j a v a2 s.c o m*/ * @param classe * @param namedQuery * @param params * @return */ @SuppressWarnings("unchecked") public <T> T retrieveUniqueByNamedQuery(Class<T> classe, String namedQuery, Object... params) { Query query = getSession().getNamedQuery(namedQuery); if (params != null) { for (int i = 0; i < params.length; i++) { query.setParameter(i, params[i]); } } return (T) query.uniqueResult(); }
From source file:br.com.suricattus.surispring.framework.service.GenericRetrieveService.java
License:Open Source License
/** * Retorna a entidade de acordo com a namedQuery informada. * @param <T>/*from w ww . j a va 2 s . c o m*/ * @param classe * @param namedQuery * @param params * @return */ @SuppressWarnings({ "unchecked", "rawtypes" }) public <T> T retrieveUniqueByNamedQuery(Class<T> classe, String namedQuery, Map<String, Object> params) { Query query = getSession().getNamedQuery(namedQuery); if (params != null) { for (String paramName : params.keySet()) { Object param = params.get(paramName); if (param instanceof Collection) { query.setParameterList(paramName, (Collection) params.get(paramName)); } else if (param instanceof Object[]) { query.setParameterList(paramName, (Object[]) params.get(paramName)); } else { query.setParameter(paramName, params.get(paramName)); } } } return (T) query.uniqueResult(); }
From source file:br.com.suricattus.surispring.framework.service.GenericRetrieveService.java
License:Open Source License
/** * Retorna o resultado de acordo com a namedQuery informada. * @param classe//w w w. ja va 2 s .c o m * @param namedQuery * @param params * @return */ public List<?> retrieveByNamedQuery(String namedQuery, Object... params) { Query query = getSession().getNamedQuery(namedQuery); if (params != null) for (int i = 1; i <= params.length; i++) query.setParameter(i, params[i - 1]); return query.list(); }
From source file:br.com.suricattus.surispring.framework.service.GenericRetrieveService.java
License:Open Source License
/** * Retorna o resultado de acordo com a namedQuery informada. * @param classe/*www.j a va 2s. com*/ * @param namedQuery * @param params * @return */ @SuppressWarnings("rawtypes") public List<?> retrieveByNamedQuery(String namedQuery, Map<String, Object> params) { Query query = getSession().getNamedQuery(namedQuery); if (params != null) { for (String paramName : params.keySet()) { Object param = params.get(paramName); if (param instanceof Collection) { query.setParameterList(paramName, (Collection) params.get(paramName)); } else if (param instanceof Object[]) { query.setParameterList(paramName, (Object[]) params.get(paramName)); } else { query.setParameter(paramName, params.get(paramName)); } } } return query.list(); }
From source file:br.com.suricattus.surispring.framework.service.GenericRetrieveService.java
License:Open Source License
/** * Retorna o resultado unico de acordo com a namedQuery informada. * @param classe//from w w w.ja va 2 s . c o m * @param namedQuery * @param params * @return */ public Object retrieveUniqueByNamedQuery(String namedQuery, Object... params) { Query query = getSession().getNamedQuery(namedQuery); if (params != null) for (int i = 0; i < params.length; i++) query.setParameter(i, params[i]); return query.uniqueResult(); }
From source file:br.com.suricattus.surispring.framework.service.GenericRetrieveService.java
License:Open Source License
/** * Retorna o resultado unico de acordo com a namedQuery informada. * @param classe/*from w w w. j a v a 2s. c o m*/ * @param namedQuery * @param params * @return */ @SuppressWarnings("rawtypes") public Object retrieveUniqueByNamedQuery(String namedQuery, Map<String, Object> params) { Query query = getSession().getNamedQuery(namedQuery); if (params != null) { for (String paramName : params.keySet()) { Object param = params.get(paramName); if (param instanceof Collection) { query.setParameterList(paramName, (Collection) params.get(paramName)); } else if (param instanceof Object[]) { query.setParameterList(paramName, (Object[]) params.get(paramName)); } else { query.setParameter(paramName, params.get(paramName)); } } } return query.uniqueResult(); }