Skip to content

Commit

Permalink
SAM-3150 Hibernate 4 fix count for QuestionPoolFacadeQueries.getCount…
Browse files Browse the repository at this point in the history
…ItemFacadesForUser (sakaiproject#3935)
  • Loading branch information
ern authored Feb 17, 2017
1 parent b69a91d commit b5ae1d4
Showing 1 changed file with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ public List<Long[]> getSubPoolSizes(final String agent) {
List<Object[]> objectResult = getHibernateTemplate().execute(hcb);
List<Long[]> longResult = new ArrayList<>(objectResult.size());
for (Object[] array : objectResult) {
longResult.add(new Long[]{(Long) array[0], (Long) array[1]});
longResult.add(new Long[]{((Number) array[0]).longValue(), ((Number) array[1]).longValue()});
}
return longResult;
}
Expand Down Expand Up @@ -1314,7 +1314,7 @@ public Integer getCountItemFacades(final Long questionPoolId) {
* @param agentId Sakai internal user id. Most likely the currently logged in user
*/
public Map<Long, Integer> getCountItemFacadesForUser(final String agentId) {
final HibernateCallback<List> hcb = session -> {
final HibernateCallback<List<Object[]>> hcb = session -> {
Query q = session.createQuery(
"select qpi.questionPoolId, count(ab) from ItemData ab, QuestionPoolItemData qpi, QuestionPoolData qpd, QuestionPoolAccessData qpad " +
"where ab.itemId = qpi.itemId and qpi.questionPoolId = qpd.questionPoolId AND qpd.questionPoolId = qpad.questionPoolId AND qpad.agentId = :agent AND qpad.accessTypeId != :access " +
Expand All @@ -1325,13 +1325,11 @@ public Map<Long, Integer> getCountItemFacadesForUser(final String agentId) {
return q.list();
};

Map<Long, Integer> counts = new HashMap<Long, Integer>();
List list = getHibernateTemplate().execute(hcb);
Map<Long, Integer> counts = new HashMap<>();
List<Object[]> list = getHibernateTemplate().execute(hcb);

Iterator i1 = list.iterator();
while (i1.hasNext()) {
Object[]result = (Object [])i1.next();
counts.put((Long) result[0], (Integer)result[1]);
for (Object[] result : list) {
counts.put(((Number) result[0]).longValue(), ((Number) result[1]).intValue());
}

return counts;
Expand Down

0 comments on commit b5ae1d4

Please sign in to comment.