modules/core/domain/src/main/java/org/rhq/core/domain/resource/ResourceType.java | 2 - modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceTypeManagerBean.java | 19 +++------- 2 files changed, 6 insertions(+), 15 deletions(-)
New commits: commit 4d895c6794fc8b746e4f8c2f7593b7deaa083d76 Author: Lukas Krejci lkrejci@redhat.com Date: Fri Jan 14 14:25:40 2011 +0100
Fix the discrepancy between the return type of the query ResourceType.FIND_ALL_TEMPLATE_COUNT_COMPOSITES and the type expected in the code.
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/resource/ResourceType.java b/modules/core/domain/src/main/java/org/rhq/core/domain/resource/ResourceType.java index 947bf62..9e0ce28 100644 --- a/modules/core/domain/src/main/java/org/rhq/core/domain/resource/ResourceType.java +++ b/modules/core/domain/src/main/java/org/rhq/core/domain/resource/ResourceType.java @@ -96,8 +96,6 @@ import org.rhq.core.domain.util.Summary; @NamedQuery(name = ResourceType.FIND_CHILDREN_BY_PARENT, query = "SELECT DISTINCT rt FROM ResourceType AS rt " + "JOIN FETCH rt.parentResourceTypes AS pa " + // also fetch parents, as we need them later "WHERE rt.deleted = false and pa IN (:resourceType)"), - // template count composites need the parent types fetched; however, because of a quirk in hibernate, - // we can't use the template component constructor in the select, we'll build the composites in our code @NamedQuery(name = ResourceType.FIND_ALL_TEMPLATE_COUNT_COMPOSITES, query = "" // + "SELECT new org.rhq.core.domain.resource.composite.ResourceTypeTemplateCountComposite" // + "(" // diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceTypeManagerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceTypeManagerBean.java index b4086b9..e225f7e 100644 --- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceTypeManagerBean.java +++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceTypeManagerBean.java @@ -391,23 +391,19 @@ public class ResourceTypeManagerBean implements ResourceTypeManagerLocal, Resour ResourceFacetsCache.getSingleton().reload(facets); }
- @SuppressWarnings("unchecked") public Map<Integer, ResourceTypeTemplateCountComposite> getTemplateCountCompositeMap() { Query templateCountQuery = entityManager.createNamedQuery(ResourceType.FIND_ALL_TEMPLATE_COUNT_COMPOSITES); - // the weirdness here is because we needed to JOIN FETCH the parent types, but hibernate bombs when you do that - // and try to use a composite constructor in the query itself. We need to build the composites here. - // Our results will be a list of arrays that we'll build into the composite below - List<?> results = templateCountQuery.getResultList(); + + @SuppressWarnings("unchecked") + List<ResourceTypeTemplateCountComposite> results = (List<ResourceTypeTemplateCountComposite>) templateCountQuery.getResultList();
// we don't need to send all the data in resource types over the wire, so we'll be scrubbing the types // to avoid the scrubbed types getting persisted back to the db, let's clear the persistence context entityManager.clear();
Map<Integer, ResourceTypeTemplateCountComposite> compositeMap = new HashMap<Integer, ResourceTypeTemplateCountComposite>(); - for (Object result : results) { - Object[] array = (Object[]) result; - - ResourceType type = (ResourceType) array[0]; + for (ResourceTypeTemplateCountComposite result : results) { + ResourceType type = result.getType();
// scrub it to avoid sending data over the wire we don't need // some of these are eagerly loaded, but my paranoia says assume everything is eagerly loaded to purge it all @@ -427,10 +423,7 @@ public class ResourceTypeManagerBean implements ResourceTypeManagerLocal, Resour type.setResources(null); type.setSubCategory(null);
- ResourceTypeTemplateCountComposite composite = new ResourceTypeTemplateCountComposite(type, - ((Number) array[1]).longValue(), ((Number) array[2]).longValue(), ((Number) array[3]).longValue(), - ((Number) array[4]).longValue()); - compositeMap.put(composite.getType().getId(), composite); + compositeMap.put(type.getId(), result); }
return compositeMap;
rhq-commits@lists.fedorahosted.org