List of usage examples for org.hibernate Query setParameterList
Query<R> setParameterList(int position, Object[] values);
From source file:gov.nih.nci.caarray.dao.ProjectDaoImpl.java
License:BSD License
/** * {@inheritDoc}/*w ww .ja v a 2s .co m*/ */ @Override @SuppressWarnings("unchecked") public List<Project> getProjectsWithReImportable() { final String q = "select distinct p from " + Project.class.getName() + " p left join p.files f where f.status = :status and f.type in (:types) order by p.id"; final Query query = getCurrentSession().createQuery(q); query.setParameter("status", FileStatus.IMPORTED_NOT_PARSED.name()); query.setParameterList("types", Sets .newHashSet(FileTypeRegistryImpl.namesForTypes(this.typeRegistry.getParseableArrayDataTypes()))); return query.list(); }
From source file:gov.nih.nci.caarray.dao.SampleDaoImpl.java
License:BSD License
private <T extends AbstractBioMaterial> Query getSearchQuery(boolean count, PageSortParams<T> params, String keyword, Set<Class<? extends AbstractBioMaterial>> biomaterialSubclasses, BiomaterialSearchCategory... categories) { @SuppressWarnings("deprecation") JoinableSortCriterion<T> sortCrit = params != null ? (JoinableSortCriterion<T>) params.getSortCriterion() : null;//from ww w . j av a2 s .com StringBuffer sb = new StringBuffer(); if (count) { sb.append("SELECT COUNT(DISTINCT s)"); } else { sb.append(SELECT_DISTINCT + "s"); } sb.append(generateSearchClause(count, sortCrit, biomaterialSubclasses, categories)); if (!count && sortCrit != null) { sb.append(ORDER_BY).append(getOrderByField(sortCrit)); if (params.isDesc()) { sb.append(" desc"); } } Query q = getCurrentSession().createQuery(sb.toString()); q.setString(KEYWORD_SUB, "%" + StringUtils.defaultString(keyword) + "%"); if (biomaterialSubclasses.size() > 1) { Set<String> discriminators = new HashSet<String>(); for (Class<? extends AbstractBioMaterial> bmClass : biomaterialSubclasses) { discriminators.add(getDiscriminator(bmClass)); } q.setParameterList("klass", discriminators); } return q; }
From source file:gov.nih.nci.caarray.dao.VocabularyDaoImpl.java
License:BSD License
/** * {@inheritDoc}/*from ww w .j a va 2s.c o m*/ */ @SuppressWarnings(UNCHECKED) public Set<Term> getTermsRecursive(Category category, String valuePrefix) { Set<Category> searchCategories = new HashSet<Category>(); searchCategories.add(category); addChildren(searchCategories, category); StringBuilder whereClause = new StringBuilder("cat in (:categories)"); if (valuePrefix != null) { whereClause.append(" and upper(t.value) like upper(:valuePrefix)"); } Query query = getCurrentSession().createQuery("select distinct t from " + Term.class.getName() + " t join t.categories cat where " + whereClause.toString() + " order by t.value asc"); query.setParameterList("categories", searchCategories); if (valuePrefix != null) { query.setString("valuePrefix", valuePrefix + "%"); } return new LinkedHashSet<Term>(query.list()); }
From source file:gov.nih.nci.caarray.security.SecurityUtils.java
License:BSD License
/** * @param p the protectable to get the protection group for * @return the UserGroupRoleProtectionGroup. <b>Note: This object is NOT associated with the current hibernate * session.</b>// www. j ava2s . co m */ @SuppressWarnings("unchecked") public static List<UserGroupRoleProtectionGroup> getUserGroupRoleProtectionGroups(Protectable p) { // Unfortunately, CSM doesn't provide a way to find out if the UserGroupRoleProtectionGroup // has been created (down to attribute level). So we need to query for it, // using the known values for various ids from the csm script final String queryString = "SELECT ugrpg FROM " + UserGroupRoleProtectionGroup.class.getName() + " ugrpg, " + ProtectionElement.class.getName() + " pe " + "WHERE pe in elements(ugrpg.protectionGroup.protectionElements) " + " AND size(ugrpg.protectionGroup.protectionElements) = 1" + " AND pe.attribute = 'id' " + " AND pe.objectId = :objectId " + " AND pe.value = :value " + " AND ugrpg.role.name in (:roleNames)"; final Query q = hibernateHelper.getCurrentSession().createQuery(queryString); q.setParameterList("roleNames", new String[] { BROWSE_ROLE, READ_ROLE, WRITE_ROLE, PERMISSIONS_ROLE, PARTIAL_READ_ROLE, PARTIAL_WRITE_ROLE }); q.setString("objectId", getUnderlyingEntityClass(p).getName()); q.setString("value", p.getId().toString()); return q.list(); }
From source file:gov.nih.nci.caarray.util.CaArrayHibernateHelperImpl.java
License:BSD License
/** * {@inheritDoc}//from w w w. j av a 2 s . co m */ public void setQueryParams(final Map<String, Object> params, Query q) { for (String key : params.keySet()) { Object value = params.get(key); if (value instanceof Collection<?>) { q.setParameterList(key, (Collection<?>) value); } else { q.setParameter(key, value); } } }
From source file:gov.nih.nci.cabig.caaers.accesscontrol.query.impl.AbstractIdFetcher.java
License:BSD License
@SuppressWarnings("unchecked") public List<?> search(final AbstractQuery query) { String queryString = query.getQueryString(); if (log.isDebugEnabled()) log.debug("::: " + queryString); return (List<?>) getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(final Session session) throws HibernateException, SQLException { if (query instanceof NativeSQLQuery) { org.hibernate.SQLQuery nativeQuery = session.createSQLQuery(query.getQueryString()); Map<String, org.hibernate.type.Type> scalarMap = ((NativeSQLQuery) query).getScalarMap(); for (String key : scalarMap.keySet()) { nativeQuery.addScalar(key, scalarMap.get(key)); }/*from w ww.j ava 2 s .c om*/ Map<String, Object> queryParameterMap = query.getParameterMap(); for (String key : queryParameterMap.keySet()) { Object value = queryParameterMap.get(key); nativeQuery.setParameter(key, value); } return nativeQuery.list(); } else { org.hibernate.Query hibernateQuery = session.createQuery(query.getQueryString()); Map<String, Object> queryParameterMap = query.getParameterMap(); for (String key : queryParameterMap.keySet()) { Object value = queryParameterMap.get(key); if (value instanceof Collection) { hibernateQuery.setParameterList(key, (Collection) value); } else { hibernateQuery.setParameter(key, value); } } return hibernateQuery.list(); } } }); }
From source file:gov.nih.nci.cabig.caaers.dao.CaaersDao.java
License:BSD License
/** * A paginated query. //from w w w .j a va 2s.com * @param query - The query to be executed. * @param firstResult - The starting index * @param maxResults - The number of objects to be returned. * @return - A list of objects returned by the query, matching the pagination criteria. */ @SuppressWarnings("unchecked") public List<?> search(final AbstractQuery query, final Integer firstResult, final Integer maxResults) { String queryString = query.getQueryString(); if (log.isDebugEnabled()) log.debug("::: " + queryString); return (List<?>) getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(final Session session) throws HibernateException, SQLException { if (query instanceof NativeSQLQuery) { org.hibernate.SQLQuery nativeQuery = session.createSQLQuery(query.getQueryString()); setResultSetBoundaries(nativeQuery, firstResult, maxResults); Map<String, Type> scalarMap = ((NativeSQLQuery) query).getScalarMap(); for (String key : scalarMap.keySet()) { nativeQuery.addScalar(key, scalarMap.get(key)); } Map<String, Object> queryParameterMap = query.getParameterMap(); for (String key : queryParameterMap.keySet()) { Object value = queryParameterMap.get(key); if (value instanceof Collection) { nativeQuery.setParameterList(key, (Collection) value); } else { nativeQuery.setParameter(key, value); } } return nativeQuery.list(); } else { org.hibernate.Query hibernateQuery = session.createQuery(query.getQueryString()); setResultSetBoundaries(hibernateQuery, firstResult, maxResults); Map<String, Object> queryParameterMap = query.getParameterMap(); for (String key : queryParameterMap.keySet()) { Object value = queryParameterMap.get(key); if (value instanceof Collection) { hibernateQuery.setParameterList(key, (Collection) value); } else { hibernateQuery.setParameter(key, value); } } return hibernateQuery.list(); } } }); }
From source file:gov.nih.nci.cabig.caaers.dao.CaaersDao.java
License:BSD License
/** * Will execute the query and return the results. * @param query - An AbstractQuery instance. * @return - List of objects that is fetched by the Query. *//*from ww w .j a v a 2 s . c om*/ @SuppressWarnings("unchecked") public List<Object[]> search(final AbstractAjaxableDomainObjectQuery query) { String queryString = query.getQueryString(); if (log.isDebugEnabled()) log.debug("::: " + queryString.toString()); return (List<Object[]>) getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(final Session session) throws HibernateException, SQLException { org.hibernate.Query hibernateQuery = session.createQuery(query.getQueryString()); Map<String, Object> queryParameterMap = query.getParameterMap(); for (String key : queryParameterMap.keySet()) { Object value = queryParameterMap.get(key); if (value instanceof Collection) { hibernateQuery.setParameterList(key, (Collection) value); } else { hibernateQuery.setParameter(key, value); } } return hibernateQuery.list(); } }); }
From source file:gov.nih.nci.cabig.caaers.dao.ExternalAdverseEventDao.java
License:BSD License
@Transactional(readOnly = false) public void updateStatus(ExternalAEReviewStatus oldStatus, ExternalAEReviewStatus newStatus, List<String> externalIds, Integer domainReportingPeriodId) { UpdatedExternalAdverseEventsStatusQuery updateQuery = new UpdatedExternalAdverseEventsStatusQuery( UpdatedExternalAdverseEventsStatusQuery.UPDATE_AE_STATUS_HQL); Query query = getHibernateTemplate().getSessionFactory().getCurrentSession() .createQuery(updateQuery.getQueryString()); query.setParameter("newStatus", newStatus); query.setParameter("oldStatus", oldStatus); query.setParameter("domainReportingPeriodId", domainReportingPeriodId); query.setParameterList("externalIds", externalIds); query.executeUpdate();/*from ww w. ja v a 2 s . com*/ }
From source file:gov.nih.nci.cabig.caaers.domain.repository.ajax.AbstractAjaxableDomainObjectRepository.java
License:BSD License
/** * Search for objects using query.//from ww w .jav a2 s . co m * * @param query The query for finding organizations. * @return The list of organizations. */ @SuppressWarnings({ "unchecked" }) //must not make this method as public method protected List<Object[]> find(final AbstractAjaxableDomainObjectQuery query) { String queryString = query.getQueryString(); log.debug("::: " + queryString); List<Object[]> objectArray = (List<Object[]>) getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(final Session session) throws HibernateException, SQLException { org.hibernate.Query hiberanteQuery = session.createQuery(query.getQueryString()); Map<String, Object> queryParameterMap = query.getParameterMap(); // hiberanteQuery.setMaxResults(null); for (String key : queryParameterMap.keySet()) { Object value = queryParameterMap.get(key); if (value instanceof List) { hiberanteQuery.setParameterList(key, (List) value); } else { hiberanteQuery.setParameter(key, value); } } return hiberanteQuery.list(); } }); return objectArray; }