List of usage examples for org.hibernate Query setParameterList
Query<R> setParameterList(int position, Object[] values);
From source file:com.flipkart.flux.redriver.dao.MessageDao.java
License:Apache License
/** * Deletes the corresponding {@link ScheduledMessage}s from ScheduledMessages table in one shot. * @param messageIdsToDelete List of {@link ScheduledMessage} Ids *//*from w ww . ja v a 2s . c o m*/ @Transactional public void deleteInBatch(List<Long> messageIdsToDelete) { final Query deleteQuery = currentSession() .createQuery("delete ScheduledMessage s where s.taskId in :msgList "); deleteQuery.setParameterList("msgList", messageIdsToDelete); deleteQuery.executeUpdate(); }
From source file:com.flytxt.commons.reporting.parameter.dao.impl.ParameterDaoImpl.java
License:Open Source License
public Collection<ParamComboVO> getParametersAfterExlusion(Collection<Long> exludedParameters) { Collection<ParamComboVO> result = new ArrayList<ParamComboVO>(); Query q = null; if (exludedParameters == null || exludedParameters.isEmpty()) { q = this.session.getNamedQuery("Parameter.findAll"); } else {//from w w w .java2 s.c o m q = this.session.createQuery("SELECT p FROM Parameter p WHERE p.id not in (:parameterIds)"); q.setParameterList("parameterIds", exludedParameters); } List<Parameter> list = q.list(); if (list != null) for (Parameter param : list) { ParamComboVO vo = new ParamComboVO(param.getId(), param.getParameterName()); result.add(vo); } return result; }
From source file:com.gisgraphy.domain.repository.GenericGisDao.java
License:Open Source License
/** * base method for all findNearest* /*from ww w .j a va 2 s . c o m*/ * * @param point * The point from which we want to find GIS Object * @param pointId * the id of the point that we don't want to be include, it * is used to not include the gisFeature from which we want * to find the nearest * @param distance * distance The radius in meters * @param firstResult * the firstResult index (for pagination), numbered from 1, * if < 1 : it will not be taken into account * @param maxResults * The Maximum number of results to retrieve (for * pagination), if <= 0 : it will not be taken into acount * @param requiredClass * the class of the object to be retireved * @param isMunicipality whether we should filter on city that are flag as 'municipality'. act as a filter, if false it doesn't filters( false doesn't mean that we return non municipality) * @return A List of GisFeatureDistance with the nearest elements or an * emptylist (never return null), ordered by distance.<u>note</u> * the specified gisFeature will not be included into results * @see GisFeatureDistance * @return a list of gisFeature (never return null but an empty list) */ @SuppressWarnings("unchecked") protected List<GisFeatureDistance> getNearestAndDistanceFrom(final Point point, final Long pointId, final double distance, final int firstResult, final int maxResults, final boolean includeDistanceField, final Class<? extends GisFeature> requiredClass, final boolean isMunicipality) { Assert.notNull(point); return (List<GisFeatureDistance>) this.getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws PersistenceException { Criteria criteria = session.createCriteria(requiredClass); if (maxResults > 0) { criteria = criteria.setMaxResults(maxResults); } if (firstResult >= 1) { criteria = criteria.setFirstResult(firstResult - 1); } criteria = criteria.add(new DistanceRestriction(point, distance)); List<String> fieldList = IntrospectionHelper.getFieldsAsList(requiredClass); ProjectionList projections = ProjectionBean.fieldList(fieldList, true); if (includeDistanceField) { projections.add(SpatialProjection.distance_sphere(point, GisFeature.LOCATION_COLUMN_NAME) .as("distance")); } criteria.setProjection(projections); if (pointId != 0) { // remove The From Point criteria = criteria.add(Restrictions.not(Restrictions.idEq(pointId))); } if (includeDistanceField) { criteria.addOrder(new ProjectionOrder("distance")); } if (isMunicipality && (requiredClass == City.class || requiredClass == GisFeature.class)) { criteria.add(Restrictions.eq(City.MUNICIPALITY_FIELD_NAME, isMunicipality)); } criteria.setCacheable(true); List<Object[]> queryResults = criteria.list(); String[] aliasList; if (includeDistanceField) { aliasList = (String[]) ArrayUtils.add(IntrospectionHelper.getFieldsAsArray(requiredClass), "distance"); } else { aliasList = IntrospectionHelper.getFieldsAsArray(requiredClass); } int idPropertyIndexInAliasList = 0; for (int i = 0; i < aliasList.length; i++) { if (aliasList[i] == "id") { idPropertyIndexInAliasList = i; break; } } boolean hasZipCodesProperty = ZipCodesAware.class.isAssignableFrom(requiredClass); Map<Long, Set<String>> idToZipCodesMap = null; if (hasZipCodesProperty && queryResults.size() > 0) { List<Long> ids = new ArrayList<Long>(); for (Object[] tuple : queryResults) { ids.add((Long) tuple[idPropertyIndexInAliasList]); } String zipCodeQuery = "SELECT code as code,gisfeature as id FROM " + ZipCode.class.getSimpleName().toLowerCase() + " zip where zip.gisfeature in (:ids)"; Query qry = session.createSQLQuery(zipCodeQuery).addScalar("code", Hibernate.STRING) .addScalar("id", Hibernate.LONG); qry.setCacheable(true); qry.setParameterList("ids", ids); List<Object[]> zipCodes = (List<Object[]>) qry.list(); if (zipCodes.size() > 0) { idToZipCodesMap = new HashMap<Long, Set<String>>(); for (Object[] zipCode : zipCodes) { Long idFromZipcode = (Long) zipCode[1]; Set<String> zipCodesFromMap = idToZipCodesMap.get(idFromZipcode); if (zipCodesFromMap == null) { Set<String> zipCodesToAdd = new HashSet<String>(); idToZipCodesMap.put(idFromZipcode, zipCodesToAdd); zipCodesFromMap = zipCodesToAdd; } zipCodesFromMap.add((String) zipCode[0]); } } } List<GisFeatureDistance> results = ResultTransformerUtil.transformToGisFeatureDistance(aliasList, queryResults, idToZipCodesMap, requiredClass); return results; } }); }
From source file:com.gisgraphy.domain.repository.GenericGisDao.java
License:Open Source License
@SuppressWarnings("unchecked") public List<T> listByFeatureIds(final List<Long> ids) { if (ids == null || ids.size() == 0) { return new ArrayList<T>(); }//from w w w. j a v a2 s . c o m return (List<T>) this.getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(final Session session) throws PersistenceException { final String queryString = "from " + persistentClass.getSimpleName() + " as g where g.featureId in (:ids)"; final Query qry = session.createQuery(queryString); qry.setParameterList("ids", ids); qry.setCacheable(true); List<T> result = (List<T>) qry.list(); if (result == null) { result = new ArrayList<T>(); } return result; } }); }
From source file:com.github.antennaesdk.messageserver.db.dao.impl.HbmDeviceInfoDaoImpl.java
License:Apache License
@Override @Transactional//w ww.jav a2 s . c om public List<DeviceInfo> getDeviceInfos(List<Integer> deviceIds) { Query selectQuery = sessionFactory.getCurrentSession().createQuery("from DeviceInfo where id in ( :ids ) "); selectQuery.setParameterList("ids", deviceIds); return selectQuery.list(); }
From source file:com.glaf.jbpm.dao.JbpmEntityDAO.java
License:Apache License
public void executeUpdate(JbpmContext jbpmContext, String sql, Map<String, Object> params) { Session session = jbpmContext.getSession(); Query query = session.createQuery(sql); if (params != null && params.size() > 0) { Set<Entry<String, Object>> entrySet = params.entrySet(); for (Entry<String, Object> entry : entrySet) { String name = entry.getKey(); Object value = entry.getValue(); if (value != null) { if (value instanceof Collection) { query.setParameterList(name, (Collection<?>) value); } else { query.setParameter(name, value); }//www . ja va2s .c o m } } } query.executeUpdate(); }
From source file:com.glaf.jbpm.dao.JbpmEntityDAO.java
License:Apache License
public List<Object> getList(JbpmContext jbpmContext, SqlExecutor queryExecutor) { Session session = jbpmContext.getSession(); Query query = session.createQuery(queryExecutor.getSql()); Object parameter = queryExecutor.getParameter(); if (parameter instanceof Map) { Map<String, Object> params = (Map<String, Object>) parameter; if (params != null && params.size() > 0) { Set<Entry<String, Object>> entrySet = params.entrySet(); for (Entry<String, Object> entry : entrySet) { String name = entry.getKey(); Object value = entry.getValue(); if (value != null) { if (value instanceof Collection) { query.setParameterList(name, (Collection<?>) value); } else { query.setParameter(name, value); }// w w w . ja v a 2 s .c om } } } } List<Object> rows = query.list(); return rows; }
From source file:com.glaf.jbpm.dao.JbpmEntityDAO.java
License:Apache License
public List<Object> getList(JbpmContext jbpmContext, int currPageNo, int maxResults, SqlExecutor queryExecutor) {/*from w w w . j av a2 s. c om*/ Session session = jbpmContext.getSession(); Query query = session.createQuery(queryExecutor.getSql()); Object parameter = queryExecutor.getParameter(); if (parameter instanceof Map) { Map<String, Object> params = (Map<String, Object>) parameter; if (params != null && params.size() > 0) { Set<Entry<String, Object>> entrySet = params.entrySet(); for (Entry<String, Object> entry : entrySet) { String name = entry.getKey(); Object value = entry.getValue(); if (value != null) { if (value instanceof Collection) { query.setParameterList(name, (Collection<?>) value); } else { query.setParameter(name, value); } } } } } query.setFirstResult((currPageNo - 1) * maxResults); query.setMaxResults(maxResults); List<Object> rows = query.list(); return rows; }
From source file:com.glaf.jbpm.dao.JbpmEntityDAO.java
License:Apache License
public Paging getPage(JbpmContext jbpmContext, int currPageNo, int pageSize, SqlExecutor countExecutor, SqlExecutor queryExecutor) {//w w w .j a va2 s . c o m Session session = jbpmContext.getSession(); Paging page = new Paging(); if (pageSize <= 0) { pageSize = Paging.DEFAULT_PAGE_SIZE; } if (currPageNo <= 0) { currPageNo = 1; } int totalCount = 0; if (countExecutor != null) { Object obj = null; String hql = countExecutor.getSql(); hql = removeOrders(hql); Query q = session.createQuery(hql); Object parameter = queryExecutor.getParameter(); if (parameter instanceof Map) { Map<String, Object> params = (Map<String, Object>) parameter; if (params != null && params.size() > 0) { Set<Entry<String, Object>> entrySet = params.entrySet(); for (Entry<String, Object> entry : entrySet) { String name = entry.getKey(); Object value = entry.getValue(); if (value != null) { if (value instanceof Collection) { q.setParameterList(name, (Collection<?>) value); } else { q.setParameter(name, value); } } } } } obj = q.iterate().next(); if (obj instanceof Integer) { Integer iCount = (Integer) obj; totalCount = iCount.intValue(); } else if (obj instanceof Long) { Long iCount = (Long) obj; totalCount = iCount.intValue(); } else if (obj instanceof BigDecimal) { BigDecimal bg = (BigDecimal) obj; totalCount = bg.intValue(); } else if (obj instanceof BigInteger) { BigInteger bi = (BigInteger) obj; totalCount = bi.intValue(); } } else { List<Object> list = null; Query q = session.createQuery(queryExecutor.getSql()); Object parameter = queryExecutor.getParameter(); if (parameter instanceof Map) { Map<String, Object> params = (Map<String, Object>) parameter; if (params != null && params.size() > 0) { Set<Entry<String, Object>> entrySet = params.entrySet(); for (Entry<String, Object> entry : entrySet) { String name = entry.getKey(); Object value = entry.getValue(); if (value != null) { if (value instanceof Collection) { q.setParameterList(name, (Collection<?>) value); } else { q.setParameter(name, value); } } } } } list = q.list(); if (list != null) { totalCount = list.size(); } } if (totalCount == 0) { page.setRows(new java.util.ArrayList<Object>()); page.setCurrentPage(0); page.setPageSize(0); page.setTotal(0); return page; } page.setTotal(totalCount); int maxPageNo = (page.getTotal() + (pageSize - 1)) / pageSize; if (currPageNo > maxPageNo) { currPageNo = maxPageNo; } Query query = session.createQuery(queryExecutor.getSql()); Object parameter = queryExecutor.getParameter(); if (parameter instanceof Map) { Map<String, Object> params = (Map<String, Object>) parameter; if (params != null && params.size() > 0) { Set<Entry<String, Object>> entrySet = params.entrySet(); for (Entry<String, Object> entry : entrySet) { String name = entry.getKey(); Object value = entry.getValue(); if (value != null) { if (value instanceof Collection) { query.setParameterList(name, (Collection<?>) value); } else { query.setParameter(name, value); } } } } } query.setFirstResult((currPageNo - 1) * pageSize); query.setMaxResults(pageSize); List<Object> list = query.list(); page.setRows(list); page.setPageSize(pageSize); page.setCurrentPage(currPageNo); return page; }
From source file:com.glaf.jbpm.util.HibernateUtils.java
License:Apache License
@SuppressWarnings("rawtypes") public static void fillParameters(Query query, Map<String, Object> params) { if (params == null || params.size() == 0) { return;/* w ww . ja va2 s. c o m*/ } Set<Entry<String, Object>> entrySet = params.entrySet(); for (Entry<String, Object> entry : entrySet) { String name = entry.getKey(); Object value = entry.getValue(); query.setParameter(name, value); if (value instanceof Collection) { Collection values = (Collection) value; query.setParameterList(name, values); } } }