public CountsHolder loadCountsForUser(User user) {
Collection<Space> spaces = user.getSpaces();
if (spaces.size() == 0) {
return null;
}
CountsHolder ch = new CountsHolder();
HibernateTemplate ht = getHibernateTemplate();
List<Object[]> loggedByList = ht.find("select item.space.id, count(item) from Item item"
+ " where item.loggedBy.id = ? group by item.space.id", user.getId());
List<Object[]> assignedToList = ht.find("select item.space.id, count(item) from Item item"
+ " where item.assignedTo.id = ? group by item.space.id", user.getId());
List<Object[]> statusList = ht.findByNamedParam("select item.space.id, count(item) from Item item"
+ " where item.space in (:spaces) group by item.space.id", "spaces", spaces);
for(Object[] oa : loggedByList) {
ch.addLoggedByMe((Long) oa[0], (Long) oa[1]);
}
for(Object[] oa : assignedToList) {
ch.addAssignedToMe((Long) oa[0], (Long) oa[1]);
}
for(Object[] oa : statusList) {
ch.addTotal((Long) oa[0], (Long) oa[1]);
}
return ch;
}