List of usage examples for org.hibernate Query setParameterList
Query<R> setParameterList(int position, Object[] values);
From source file:gov.nih.nci.caintegrator.studyQueryService.ihc.LevelOfExpressionIHCFindingHandler.java
License:BSD License
public Collection<LevelOfExpressionIHCFinding> getLevelExpFindings( LevelOfExpressionIHCFindingCriteria inCriteria) { logger.debug("Entering getFindings"); Session theSession = sessionFactory.getCurrentSession(); Set<LevelOfExpressionIHCFinding> theResults = new HashSet<LevelOfExpressionIHCFinding>(); try {//w ww.j av a 2 s. c om //theSession = HibernateUtil.getSession(); //HibernateUtil.beginTransaction(); HashMap<String, Object> theParams = new HashMap<String, Object>(); StringBuilder theHQL = handleCriteria(inCriteria, theParams, null); ProteinBiomarkerCriteia theProteinCriteria = inCriteria.getProteinBiomarkerCrit(); SpecimenCriteria theSpecimenCriteria = inCriteria.getSpecimenCriteria(); if (theProteinCriteria != null) { if (theHQL.toString().contains("WHERE")) { theHQL.append(" AND levelIHC.proteinBiomarker IN ("); } else { theHQL.append(" WHERE levelIHC.proteinBiomarker IN ("); } ProteinBiomarkerHandler theProteinHandler = theProteinCriteria.getHandler(); StringBuilder theProteinHQL = theProteinHandler.handleCriteria(theProteinCriteria, theParams); theHQL.append(theProteinHQL + ")"); } if (theSpecimenCriteria != null) { if (theHQL.toString().contains("WHERE")) { theHQL.append(" AND levelIHC.specimen IN ("); } else { theHQL.append(" WHERE levelIHC.specimen IN ("); } SpecimenHandler theSpecimenHandler = theSpecimenCriteria.getHandler(); StringBuilder theSpecimenHQL = theSpecimenHandler.handleCriteria(theSpecimenCriteria, theParams); theHQL.append(theSpecimenHQL + ")"); } logger.info("HQL7777777777: " + theHQL.toString()); Query q = theSession.createQuery(theHQL.toString()); long start = System.currentTimeMillis(); HQLHelper.setParamsOnQuery(theParams, q); /*this returns my "initial query" to bring back objects that met my criteria. Next I would like to find out about the other timepoint data for the objects that were just found.*/ List<String> theObjects = q.list(); //check to see if objects exceed 1000, so that the statemnt can be segmented if (theObjects.size() > 1000) { List<List<String>> segmentedObjects = new ArrayList<List<String>>(); List<String> myObjects = new ArrayList<String>(); for (int i = 0; i < theObjects.size(); i++) { if (i != 0 && i % 1000 == 0) { List<String> tempObjects = new ArrayList<String>(myObjects); segmentedObjects.add(tempObjects); myObjects.clear(); } else { myObjects.add(theObjects.get(i)); } } if (!myObjects.isEmpty()) { segmentedObjects.add(myObjects); } /* now I should have segemented groups of 1000 (or less) to iterate over and populate into my "in" clause for each group. When the queries complete, I add the results into my results object. */ for (List list : segmentedObjects) { String theFinalHQL = "select levelIHC from LevelOfExpressionIHCFinding as levelIHC LEFT JOIN FETCH levelIHC.proteinBiomarker LEFT JOIN FETCH levelIHC.specimen " + " WHERE levelIHC.specimen.patientDID||levelIHC.proteinBiomarker.id IN (:levelIHC_objects)"; System.out.println(theFinalHQL); Query theFinalQuery = null; theFinalQuery = theSession.createQuery(theFinalHQL); theFinalQuery.setParameterList("levelIHC_objects", list); Collection<LevelOfExpressionIHCFinding> objs = theFinalQuery.list(); theResults.addAll(objs); } } //if the objects do not exceed 1000, procedd with a regular in clause else { String theFinalHQL = "select levelIHC from LevelOfExpressionIHCFinding as levelIHC LEFT JOIN FETCH levelIHC.proteinBiomarker LEFT JOIN FETCH levelIHC.specimen " + " WHERE levelIHC.specimen.patientDID||levelIHC.proteinBiomarker.id IN (:levelIHC_objects)"; System.out.println(theFinalHQL); Query theFinalQuery = null; theFinalQuery = theSession.createQuery(theFinalHQL); theFinalQuery.setParameterList("levelIHC_objects", theObjects); Collection<LevelOfExpressionIHCFinding> objs = theFinalQuery.list(); theResults.addAll(objs); } } catch (Exception e) { e.printStackTrace(); logger.error("Error getting findings: ", e); } logger.debug("Exiting getFindings"); return theResults; }
From source file:gov.nih.nci.caintegrator.studyQueryService.ihc.LossOfExpressionIHCFindingHandler.java
License:BSD License
public Collection<LossOfExpressionIHCFinding> getLossExpFindings( LossOfExpressionIHCFindingCriteria inCriteria) { logger.debug("Entering getFindings"); Session theSession = sessionFactory.getCurrentSession(); Set<LossOfExpressionIHCFinding> theResults = new HashSet<LossOfExpressionIHCFinding>(); try {// w ww . j a va 2 s. c om HashMap<String, Object> theParams = new HashMap<String, Object>(); StringBuilder theHQL = handleCriteria(inCriteria, theParams, null); ProteinBiomarkerCriteia theProteinCriteria = inCriteria.getProteinBiomarkerCrit(); SpecimenCriteria theSpecimenCriteria = inCriteria.getSpecimenCriteria(); if (theProteinCriteria != null) { if (theHQL.toString().contains("WHERE")) { theHQL.append(" AND lossIHC.proteinBiomarker IN ("); } else { theHQL.append(" WHERE lossIHC.proteinBiomarker IN ("); } ProteinBiomarkerHandler theProteinHandler = theProteinCriteria.getHandler(); StringBuilder theProteinHQL = theProteinHandler.handleCriteria(theProteinCriteria, theParams); theHQL.append(theProteinHQL + ")"); } if (theSpecimenCriteria != null) { if (theHQL.toString().contains("WHERE")) { theHQL.append(" AND lossIHC.specimen IN ("); } else { theHQL.append(" WHERE lossIHC.specimen IN ("); } SpecimenHandler theSpecimenHandler = theSpecimenCriteria.getHandler(); StringBuilder theSpecimenHQL = theSpecimenHandler.handleCriteria(theSpecimenCriteria, theParams); theHQL.append(theSpecimenHQL + ")"); } logger.info("HQL7777777777: " + theHQL.toString()); Query q = theSession.createQuery(theHQL.toString()); HQLHelper.setParamsOnQuery(theParams, q); List<String> theObjects = q.list(); if (theObjects.size() > 1000) { List<List<String>> segmentedObjects = new ArrayList<List<String>>(); List<String> myObjects = new ArrayList<String>(); for (int i = 0; i < theObjects.size(); i++) { if (i != 0 && i % 1000 == 0) { List<String> tempObjects = new ArrayList<String>(myObjects); segmentedObjects.add(tempObjects); myObjects.clear(); } else { myObjects.add(theObjects.get(i)); } } if (!myObjects.isEmpty()) { segmentedObjects.add(myObjects); } /* now I should have segemented groups of 1000 (or less) to iterate over and populate into my "in" clause for each group. When the queries complete, I add the results into my results object. */ for (List list : segmentedObjects) { String theFinalHQL = "select levelIHC from LevelOfExpressionIHCFinding as levelIHC LEFT JOIN FETCH levelIHC.proteinBiomarker LEFT JOIN FETCH levelIHC.specimen " + " WHERE levelIHC.specimen.patientDID||levelIHC.proteinBiomarker.id IN (:levelIHC_objects)"; System.out.println(theFinalHQL); Query theFinalQuery = null; theFinalQuery = theSession.createQuery(theFinalHQL); theFinalQuery.setParameterList("levelIHC_objects", list); Collection<LossOfExpressionIHCFinding> objs = theFinalQuery.list(); theResults.addAll(objs); } } //if the objects do not exceed 1000, procedd with a regular in clause else { String theFinalHQL = "select lossIHC from LossOfExpressionIHCFinding as lossIHC LEFT JOIN FETCH lossIHC.proteinBiomarker LEFT JOIN FETCH lossIHC.specimen " + " WHERE lossIHC.specimen.patientDID||lossIHC.proteinBiomarker.id IN (:lossIHC_objects)"; System.out.println(theFinalHQL); Query theFinalQuery = null; theFinalQuery = theSession.createQuery(theFinalHQL); theFinalQuery.setParameterList("lossIHC_objects", theObjects); Collection<LossOfExpressionIHCFinding> objs = theFinalQuery.list(); theResults.addAll(objs); } } catch (Exception e) { e.printStackTrace(); logger.error("Error getting findings: ", e); } logger.debug("Exiting getFindings"); return theResults; }
From source file:gov.nih.nci.caintegrator.studyQueryService.p53.P53FindingHandler.java
License:BSD License
public Collection<P53MutationFinding> getP53Findings(P53FindingCriteria inCriteria) { logger.debug("Entering getFindings"); Session theSession = sessionFactory.getCurrentSession(); Set<P53MutationFinding> theResults = new HashSet<P53MutationFinding>(); try {/*from w ww .j av a 2 s . c o m*/ HashMap<String, Object> theParams = new HashMap<String, Object>(); StringBuilder theHQL = handleCriteria(inCriteria, theParams, null); SpecimenCriteria theSpecimenCriteria = inCriteria.getSpecimenCriteria(); if (theSpecimenCriteria != null) { if (theHQL.toString().contains("WHERE")) { theHQL.append(" AND p53Mutation.specimen IN ("); } else { theHQL.append(" WHERE p53Mutation.specimen IN ("); } SpecimenHandler theSpecimenHandler = theSpecimenCriteria.getHandler(); StringBuilder theSpecimenHQL = theSpecimenHandler.handleCriteria(theSpecimenCriteria, theParams); theHQL.append(theSpecimenHQL + ")"); } logger.info("HQL7777777777: " + theHQL.toString()); Query q = theSession.createQuery(theHQL.toString()); HQLHelper.setParamsOnQuery(theParams, q); List<String> theObjects = q.list(); if (theObjects.size() > 1000) { List<List<String>> segmentedObjects = new ArrayList<List<String>>(); List<String> myObjects = new ArrayList<String>(); for (int i = 0; i < theObjects.size(); i++) { if (i != 0 && i % 1000 == 0) { List<String> tempObjects = new ArrayList<String>(myObjects); segmentedObjects.add(tempObjects); myObjects.clear(); } else { myObjects.add(theObjects.get(i)); } } if (!myObjects.isEmpty()) { segmentedObjects.add(myObjects); } /* now I should have segemented groups of 1000 (or less) to iterate over and populate into my "in" clause for each group. When the queries complete, I add the results into my results object. */ for (List list : segmentedObjects) { String theFinalHQL = "select p53Mutation from P53MutationFinding as p53Mutation LEFT JOIN FETCH p53Mutation.specimen " + " WHERE p53Mutation.specimen.patientDID IN (:p53Mutation_objects)"; System.out.println(theFinalHQL); Query theFinalQuery = null; theFinalQuery = theSession.createQuery(theFinalHQL); theFinalQuery.setParameterList("p53Mutation_objects", list); Collection<P53MutationFinding> objs = theFinalQuery.list(); theResults.addAll(objs); } } //if the objects do not exceed 1000, procedd with a regular in clause else { String theFinalHQL = "select p53Mutation from P53MutationFinding as p53Mutation LEFT JOIN FETCH p53Mutation.specimen " + " WHERE p53Mutation.specimen.patientDID IN (:p53Mutation_objects)"; System.out.println(theFinalHQL); Query theFinalQuery = null; theFinalQuery = theSession.createQuery(theFinalHQL); theFinalQuery.setParameterList("p53Mutation_objects", theObjects); Collection<P53MutationFinding> objs = theFinalQuery.list(); theResults.addAll(objs); } } catch (Exception e) { e.printStackTrace(); logger.error("Error getting findings: ", e); } logger.debug("Exiting getFindings"); return theResults; }
From source file:gov.nih.nci.caintegrator.util.HQLHelper.java
License:BSD License
public static void setParamsOnQuery(HashMap params, Query q) { Set paramKeys = params.keySet(); Iterator iter = paramKeys.iterator(); while (iter.hasNext()) { String key = (String) iter.next(); Object value = params.get(key); if (value instanceof List) q.setParameterList(key, (ArrayList) value); else if (value instanceof Set) q.setParameterList(key, (HashSet) value); else/* w ww. jav a 2 s . com*/ q.setParameter(key, value); } }
From source file:gov.nih.nci.caintegrator.util.HQLHelper.java
License:BSD License
public static void setParamsOnQuery(Hashtable params, Query q) { Set paramKeys = params.keySet(); Iterator iter = paramKeys.iterator(); while (iter.hasNext()) { String key = (String) iter.next(); Object value = params.get(key); Class c = value.getClass(); if (value instanceof List) q.setParameterList(key, (ArrayList) value); else if (value instanceof Set) q.setParameterList(key, (HashSet) value); else//from w ww . j a v a2 s .c o m q.setParameter(key, value); } }
From source file:gov.nih.nci.firebird.service.protocol.ProtocolServiceBean.java
License:Open Source License
@Override @SuppressWarnings("unchecked") // Hibernate only returns untyped collections public List<Protocol> getProtocols(FirebirdUser user, Set<String> groupNames) { checkNotNull(user);/* ww w . j a v a2 s . c o m*/ checkNotNull(groupNames); List<Organization> verifiedSponsorOrganizations = user.getVerifiedSponsorOrganizations(groupNames); if (verifiedSponsorOrganizations.isEmpty()) { return Collections.emptyList(); } else { String protocolQueryHql = HQL_FROM_BASE + Protocol.class.getName() + " where sponsor in (:sponsors)"; Query query = getSession().createQuery(protocolQueryHql); query.setParameterList("sponsors", verifiedSponsorOrganizations); return query.list(); } }
From source file:gov.nih.nci.firebird.service.registration.ProtocolRegistrationServiceBean.java
License:Open Source License
@SuppressWarnings("unchecked") // Hibernate's list() method is untyped @Override/*from w ww . j av a 2 s . c om*/ public List<AbstractProtocolRegistration> getByStatusForUser(RegistrationStatus status, FirebirdUser user, Set<String> groupNames) { checkNotNull(status); checkNotNull(user); checkNotNull(groupNames); List<Organization> verifiedSponsorOrganizations = user.getVerifiedSponsorOrganizations(groupNames); if (verifiedSponsorOrganizations.isEmpty()) { return Collections.emptyList(); } else { String registrationQueryHql = "from " + AbstractProtocolRegistration.class.getName() + " where status = :status and protocol.sponsor in (:sponsors)"; Query query = getSession().createQuery(registrationQueryHql); query.setParameter("status", status); query.setParameterList("sponsors", verifiedSponsorOrganizations); return query.list(); } }
From source file:gr.abiss.calipso.hibernate.HibernateDao.java
License:Open Source License
/** {@inheritDoc} */ @Override/*from w ww .j ava 2s . c o m*/ public ItemRenderingTemplate getItemRenderingTemplateForUser(final User user, final Integer itemStatus, final Long spaceId) { if (user == null) { throw new IllegalArgumentException("User cannot be null"); } if (itemStatus == null) { throw new IllegalArgumentException("Item status cannot be null"); } if (spaceId == null) { throw new IllegalArgumentException("Space id cannot be null"); } return (ItemRenderingTemplate) getHibernateTemplate().execute(new HibernateCallback() { @Override public Object doInHibernate(Session session) { // TreeSet<ItemRenderingTemplate> templs = new TreeSet<ItemRenderingTemplate>(); // if(CollectionUtils.isNotEmpty(user.getSpaceRoles(item.getSpace()))){ // Query query = session.createQuery("from "); // } String queryString = "select distinct tmpl from SpaceRole as spaceRole " + " join spaceRole.itemRenderingTemplates as tmpl " + "where spaceRole.space.id = :spaceId " + " and spaceRole in(:spaceRoles) and index(tmpl) = :itemStatus " + "order by tmpl.priority asc"; Query query = session.createQuery(queryString); //logger.info("item space: "+item.getSpace()); query.setLong("spaceId", spaceId); query.setString("itemStatus", itemStatus.toString()); query.setParameterList("spaceRoles", user.getSpaceRoles(spaceId)); query.setMaxResults(1); // TODO: A hack until we implement the custom attribute subclass hierarchy. ItemRenderingTemplate tmpl = null; List<ItemRenderingTemplate> templates = query.list(); //logger.info("Got "+templates.size()+" results for quesry: "+queryString); if (CollectionUtils.isNotEmpty(templates)) { tmpl = templates.get(0); } return tmpl; } }); }
From source file:gr.interamerican.bo2.impl.open.hibernate.AbstractHqlQuery.java
License:Open Source License
/** * Sets a parameter to a query.// w w w . ja va 2s. co m * * If the parameter is of a type that is handled with a custom Bo2 * hibernate user type, then it is handled accordingly. The association * between Bo2 hibernate user types and types they handle can be found * in {@link UserTypeUtil}. * * If a parameter of such as type is passed to the query that is not handled * as a custom user type in the corresponding mappings, an error will ensue. * * For example: * Branch is {@link TypedSelectable} (i.e. a type represented with the * custom hibernate user type {@link EntryUserType}, but is also a * {@link PersistentObject} that has its own hibernate mapping file. * Therefore, a {@link Parameter} of type Branch should not be passed * in an {@link AbstractHqlQuery}!!! * * @param query * Query on which the parameter is set. * @param name * Name of the parameter. * @param parm * Value of the parameter. */ private void setParameter(org.hibernate.Query query, String name, Object parm) { if (UserTypeUtil.isUserType(parm)) { query.setParameter(name, parm); } else if (parm instanceof List<?>) { query.setParameterList(name, (List<?>) parm); } else if (parm instanceof Object[]) { query.setParameterList(name, (Object[]) parm); } else { @SuppressWarnings("rawtypes") Type type = TypeUtils.getType(parm); @SuppressWarnings("unchecked") Object parameter = type.statementParameter(parm); query.setParameter(name, parameter); /* * ?? * query.setEntity(name, parm); */ } }
From source file:io.datalayer.sql.dao.impl.GenericDaoHibernateImpl.java
License:Apache License
private void setNamedParams(String[] namedParameters, Object[] queryArgs, Query namedQuery) { // Set parameter. Use custom Hibernate Type if necessary if (queryArgs != null) { for (int i = 0; i < queryArgs.length; i++) { Object arg = queryArgs[i]; Type argType = getArgumentTypeFactory().getArgumentType(arg); if (argType != null) { namedQuery.setParameter(namedParameters[i], arg, argType); } else { if (arg instanceof Collection) { namedQuery.setParameterList(namedParameters[i], (Collection) arg); } else { namedQuery.setParameter(namedParameters[i], arg); }//from w w w . j a va 2 s . co m } } } }