List of usage examples for org.hibernate SQLQuery setParameterList
@Override NativeQuery<T> setParameterList(String name, Object[] values);
From source file:ubic.gemma.persistence.util.CommonQueries.java
License:Apache License
/** * @param session session/*w w w .j av a 2 s.c o m*/ * @param genes genes * @param arrayDesigns array design * @return map of probe IDs to collections of gene IDs. */ public static Map<Long, Collection<Long>> getCs2GeneIdMap(Collection<Long> genes, Collection<Long> arrayDesigns, Session session) { Map<Long, Collection<Long>> cs2genes = new HashMap<>(); String queryString = "SELECT CS AS csid, GENE AS geneId FROM GENE2CS g WHERE g.GENE IN (:geneIds) AND g.AD IN (:ads)"; SQLQuery queryObject = session.createSQLQuery(queryString); queryObject.addScalar("csid", LongType.INSTANCE); queryObject.addScalar("geneId", LongType.INSTANCE); queryObject.setParameterList("ads", arrayDesigns); queryObject.setParameterList("geneIds", genes); queryObject.setReadOnly(true); queryObject.setFlushMode(FlushMode.MANUAL); ScrollableResults results = queryObject.scroll(ScrollMode.FORWARD_ONLY); CommonQueries.addGeneIds(cs2genes, results); results.close(); return cs2genes; }
From source file:ubic.gemma.persistence.util.EntityUtils.java
License:Apache License
/** * Populates parameters in query created using addGroupAndUserNameRestriction(boolean, boolean). * * @param queryObject the query object created using the sql query with group and username restrictions. * @param sessionFactory session factory from the DAO that is using this method. *///from w ww.j a va 2 s.c om public static void addUserAndGroupParameters(SQLQuery queryObject, SessionFactory sessionFactory) { if (SecurityUtil.isUserAnonymous()) { return; } String sqlQuery = queryObject.getQueryString(); String userName = SecurityUtil.getCurrentUsername(); // if user is member of any groups. if (sqlQuery.contains(":groups")) { //noinspection unchecked Collection<String> groups = sessionFactory.getCurrentSession().createQuery( "select ug.name from UserGroup ug inner join ug.groupMembers memb where memb.userName = :user") .setParameter("user", userName).list(); queryObject.setParameterList("groups", groups); } if (sqlQuery.contains(":userName")) { queryObject.setParameter("userName", userName); } }