query.setParameter("subject", subject);
}
query.setParameter("ids", ids);
AutoGroupComposite oneComp;
try {
oneComp = (AutoGroupComposite) query.getSingleResult();
} catch (NoResultException nre) {
return null; // better throw a PermissionException ?
}
if (isInventoryManager) {
query = entityManager.createNamedQuery(Resource.QUERY_FIND_AVAILABILITY_BY_RESOURCE_IDS_ADMIN);
} else {
query = entityManager.createNamedQuery(Resource.QUERY_FIND_AVAILABILITY_BY_RESOURCE_IDS);
query.setParameter("subject", subject);
}
query.setParameter("ids", ids);
// We are not doing a query with constructor here, as this would fire a select per
// resource and row. So we need to construct the ResourceWithAvailability objects ourselves.
List<Object[]> objs = query.getResultList();
for (Object[] ob : objs) {
Resource r = (Resource) ob[0];
AvailabilityType at = (AvailabilityType) ob[1];
ResourceWithAvailability rwa = new ResourceWithAvailability(r, at);
AutoGroupComposite comp = new AutoGroupComposite(oneComp);
List res = new ArrayList(1); // hack to get around type safety
res.add(rwa);
comp.setResources(res);
results.add(comp);
}
return results;
}