List of usage examples for org.hibernate Query setParameterList
Query<R> setParameterList(int position, Object[] values);
From source file:org.apache.shindig.social.opensocial.hibernate.services.PersonServiceImpl.java
License:Apache License
Map<String, Object> getPeople(Set<String> ids, Set<String> fields, CollectionOptions collectionOptions, SecurityToken token) {/*w w w . j ava 2 s. c o m*/ Map<String, Object> resultMap = new HashMap<String, Object>(); Session session = HibernateUtils.currentSession(); int first = collectionOptions.getFirst(); resultMap.put("startIndex", first); int max = collectionOptions.getMax(); // get totalSize Query query = session.createQuery("select count(*) from PersonImpl p where p.id in (:ids)"); query.setParameterList("ids", ids); int totalSize = ((Long) query.uniqueResult()).intValue(); resultMap.put("totalSize", totalSize); // get people query = session.createQuery("select p from PersonImpl p where p.id in (:ids) order by p.id"); query.setParameterList("ids", ids); query.setFirstResult(first); query.setMaxResults(max); List<Person> people = (List<Person>) query.list(); if (people != null) { for (Person person : people) { person.setIsOwner(person.getId().equals(token.getOwnerId())); person.setIsViewer(person.getId().equals(token.getViewerId())); } } resultMap.put("people", people); // return resultMap; }
From source file:org.apache.usergrid.apm.service.SessionDBServiceImpl.java
License:Apache License
@SuppressWarnings("unchecked") @Override//from w w w.j a v a2 s .c om public List<SummarySessionMetrics> getSummarySessionsForDevices(Long applicationId, List<String> deviceIds, Date sessionExpiryTime) throws HibernateException { log.info("getting summary session metrics with for " + deviceIds.toString() + " sessionExpiryTime " + sessionExpiryTime.toString()); if (deviceIds == null || deviceIds.size() == 0 || sessionExpiryTime == null) { log.info( "List of deviceIds is null or sessionExpiryTime is null. Going to return an empty summary session metrics"); return null; } // String queryString = "FROM SummarySessionMetrics m where m.appId = :appId and m.deviceId in (:devices) " + // "and m.sessionEndTime >= :sessionExpTime "; String queryString = "FROM SummarySessionMetrics m where m.appId = :appId and m.deviceId in (:devices) "; List<SummarySessionMetrics> metrics = null; Session session = null; Transaction transaction = null; try { session = ServiceFactory.getAnalyticsHibernateSession(); transaction = session.beginTransaction(); Query query = session.createQuery(queryString); query.setParameter("appId", applicationId); query.setParameterList("devices", deviceIds); //This doesn't make any sense - need to eliminate because session expiry time is different for each session //query.setParameter("sessionExpTime", sessionExpiryTime); /*Criteria crit = session.createCriteria(SummarySessionMetrics.class); session.createQuery(arg0) crit.add(Restrictions.eq("appId", applicationId)); crit.add(Restrictions.in("deviceId", deviceIds)); crit.add(Restrictions.le("sessionEndTime", sessionExpiryTime)); crit.setProjection(Projections.groupProperty("deviceId")); crit.setProjection(Projections.property("sessionStartTime")); crit.addOrder(Order.desc("sessionEndTime")); log.info("getting summary session metrics with for " + deviceIds.toString() + " sessionExpiryTime " + sessionExpiryTime.toString()); metrics = (List<SummarySessionMetrics>) crit.list();*/ metrics = query.list(); transaction.commit(); } catch (Exception e) { e.printStackTrace(); transaction.rollback(); throw new HibernateException("Cannot get metrics from Summary SessionMetrics ", e); } return metrics; }
From source file:org.apache.usergrid.apm.service.SessionDBServiceImpl.java
License:Apache License
@SuppressWarnings("unchecked") @Override//w w w. j av a 2 s . c om public List<SummarySessionMetrics> getSummarySessionsBySessionId(Long appId, Collection<String> sessionIds) throws HibernateException { // TODO Auto-generated method stub log.info("getting summary sessions matching " + sessionIds.toString()); String queryString = "FROM SummarySessionMetrics m where m.appId = :appId and m.sessionId in (:sessions) "; List<SummarySessionMetrics> metrics = null; Session session = null; Transaction transaction = null; try { session = ServiceFactory.getAnalyticsHibernateSession(); transaction = session.beginTransaction(); Query query = session.createQuery(queryString); query.setParameter("appId", appId); query.setParameterList("sessions", sessionIds); metrics = query.list(); transaction.commit(); } catch (Exception e) { e.printStackTrace(); transaction.rollback(); throw new HibernateException("Cannot get metrics from Summary SessionMetrics ", e); } return metrics; }
From source file:org.beanfuse.query.hibernate.HibernateQuerySupport.java
License:Open Source License
/** * ?/*ww w. ja v a 2 s . c o m*/ * * @param query * @param conditions */ public static void bindValues(final Query query, final List conditions) { int position = 0; boolean hasInterrogation = false; // ?? for (final Iterator iter = conditions.iterator(); iter.hasNext();) { final Condition condition = (Condition) iter.next(); if (StringUtils.contains(condition.getContent(), "?")) { hasInterrogation = true; } if (hasInterrogation) { for (final Iterator iterator = condition.getValues().iterator(); iterator.hasNext();) { query.setParameter(position++, iterator.next()); } } else { final List paramNames = condition.getNamedParams(); for (int i = 0; i < paramNames.size(); i++) { final String name = (String) paramNames.get(i); final Object value = condition.getValues().get(i); if (value.getClass().isArray()) { query.setParameterList(name, (Object[]) value); } else if (value instanceof Collection) { query.setParameterList(name, (Collection) value); } else { query.setParameter(name, value); } } } } }
From source file:org.beanfuse.query.hibernate.HibernateQuerySupport.java
License:Open Source License
/** * query?/*from w ww. j a v a 2s . c om*/ * * @param query * @param argument * @return */ public static Query setParameter(final Query query, final Map parameterMap) { if (parameterMap != null && !parameterMap.isEmpty()) { final Set parameterNameSet = parameterMap.keySet(); for (final Iterator ite = parameterNameSet.iterator(); ite.hasNext();) { final String parameterName = (String) ite.next(); if (null == parameterName) { break; } final Object parameterValue = parameterMap.get(parameterName); if (null == parameterValue) { query.setParameter(parameterName, (Object) null); } else if (parameterValue.getClass().isArray()) { query.setParameterList(parameterName, (Object[]) parameterValue); } else if (parameterValue instanceof Collection) { query.setParameterList(parameterName, (Collection) parameterValue); } else { query.setParameter(parameterName, parameterValue); } } } return query; }
From source file:org.beanfuse.security.dao.UserDaoHibernate.java
License:Apache License
public List get(Long[] userIds) { String hql = "from User where id in(:ids)"; Query query = getSession().createQuery(hql); query.setParameterList("ids", userIds); return query.list(); }
From source file:org.bonitasoft.engine.persistence.AbstractHibernatePersistenceService.java
License:Open Source License
protected void setParameters(final Query query, final Map<String, Object> inputParameters) { for (final Map.Entry<String, Object> entry : inputParameters.entrySet()) { final Object value = entry.getValue(); if (value instanceof Collection<?>) { query.setParameterList(entry.getKey(), (Collection<?>) value); } else {/* w w w . j a va 2 s . co m*/ query.setParameter(entry.getKey(), value); } } }
From source file:org.bonitasoft.engine.persistence.AbstractHibernatePersistenceService.java
License:Open Source License
@Override public void delete(final List<Long> ids, final Class<? extends PersistentObject> entityClass) throws SPersistenceException { final Class<? extends PersistentObject> mappedClass = getMappedClass(entityClass); final Query query = getSession(true).getNamedQuery("deleteByIds" + mappedClass.getSimpleName()); query.setParameterList("ids", ids); try {/* www . j av a2 s . co m*/ query.executeUpdate(); } catch (final AssertionFailure | LockAcquisitionException | StaleStateException e) { throw new SRetryableException(e); } catch (final HibernateException sse) { throw new SPersistenceException(sse); } }
From source file:org.bonitasoft.engine.test.persistence.repository.ProcessInstanceRepository.java
License:Open Source License
@SuppressWarnings("unchecked") public List<SAProcessInstance> getArchivedProcessInstancesInAllStates( final List<Long> sourceProcessInstanceIds) { getSession().enableFilter("tenantFilter").setParameter("tenantId", PersistentObjectBuilder.DEFAULT_TENANT_ID); final Query namedQuery = getNamedQuery("getArchivedProcessInstancesInAllStates"); namedQuery.setParameterList("sourceObjectIds", sourceProcessInstanceIds); return namedQuery.list(); }
From source file:org.bonitasoft.engine.test.persistence.repository.SADataInstanceRepository.java
License:Open Source License
public List<SADataInstance> getSADataInstancesByDataInstanceIdAndArchiveDate(final List<Long> dataInstanceIds, final long time, final long tenantId) { getSession().enableFilter("tenantFilter").setParameter("tenantId", tenantId); final Query namedQuery = getNamedQuery("getSADataInstancesByDataInstanceIdAndArchiveDate"); namedQuery.setParameterList("dataInstanceIds", dataInstanceIds); namedQuery.setParameter("time", time); return namedQuery.list(); }