From: <hr...@rh...> - 2009-03-04 16:44:41
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><style type="text/css"><!-- #msg DL { border : 1px #006 solid; background-color : #369; padding : 6px; color : #fff; } #msg DT { float : left; width : 6em; font-weight : bold; } #msg DL, #msg DT, #msg UL, #msg LI { font-family : arial,helvetica,sans-serif; font-size : 10pt; } h3 { font-family : arial,helvetica,sans-serif; font-size : 10pt; font-weight : bold; } #msg PRE { overflow : auto; white-space : normal; background-color : #ffc; border : 1px #fc0 solid; padding : 6px; } #msg UL, PRE, .diff { overflow : auto; } #patch h4 { font-family : arial,helvetica,sans-serif; font-size : 10pt; } #patch h4 { padding: 8px; background : #369; color : #fff; margin : 0; } #patch .propset h4, #patch .binary h4 {margin: 0;} #patch pre {padding:0;line-height:1.2em;margin:0;} #patch .diff {background:#eeeeee;padding: 0 0 10px 0;} #patch .propset .diff, #patch .binary .diff {padding: 10px 0;} #patch span {display:block;padding:0 10px;} #patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;} #patch .add {background:#ddffdd;} #patch .rem {background:#ffdddd;} #patch .lines, .info {color:#888888;background:#ffffff;} .diff { width : 100%; } #msg DL { border : 1px #006 solid; background-color : #369; padding : 6px; color : #fff; } #msg DT { float : left; width : 6em; font-weight : bold; } #msg DL, #msg DT, #msg UL, #msg LI { font-family : arial,helvetica,sans-serif; font-size : 10pt; } h3 { font-family : arial,helvetica,sans-serif; font-size : 10pt; font-weight : bold; } #msg PRE { overflow : auto; white-space : normal; background-color : #ffc; border : 1px #fc0 solid; padding : 6px; } #msg UL, PRE, .diff { overflow : auto; } #patch h4 { font-family : arial,helvetica,sans-serif; font-size : 10pt; } #patch h4 { padding: 8px; background : #369; color : #fff; margin : 0; } #patch .propset h4, #patch .binary h4 {margin: 0;} #patch pre {padding:0;line-height:1.2em;margin:0;} #patch .diff {background:#eeeeee;padding: 0 0 10px 0;} #patch .propset .diff, #patch .binary .diff {padding: 10px 0;} #patch span {display:block;padding:0 10px;} #patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;} #patch .add {background:#ddffdd;} #patch .rem {background:#ffdddd;} #patch .lines, .info {color:#888888;background:#ffffff;} .diff { width : 100%; } --></style> <title>[rhq-project.org rhq] [3290] RHQ-1717 Fix the instantiation issue.</title> </head> <body> <div id="msg"> <dl> <dt>Revision</dt> <dd>3290</dd> <dt>Author</dt> <dd>hrupp</dd> <dt>Date</dt> <dd>2009-03-04 10:44:37 -0600 (Wed, 04 Mar 2009)</dd> </dl> <h3>Log Message</h3> <pre>RHQ-1717 Fix the instantiation issue. The underlying query was returning wrong data which in turn returned in nulls for places where nulls are not possible.</pre> <h3>Modified Paths</h3> <ul> <li><a href="#rhqtrunkmodulescoredomainsrcmainjavaorgrhqcoredomainmeasurementMeasurementOOBjava">rhq/trunk/modules/core/domain/src/main/java/org/rhq/core/domain/measurement/MeasurementOOB.java</a></li> <li><a href="#rhqtrunkmodulescoredomainsrcmainjavaorgrhqcoredomainutilPersistenceUtilityjava">rhq/trunk/modules/core/domain/src/main/java/org/rhq/core/domain/util/PersistenceUtility.java</a></li> <li><a href="#rhqtrunkmodulesenterpriseserverjarsrcmainjavaorgrhqenterpriseservermeasurementMeasurementOOBManagerBeanjava">rhq/trunk/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/MeasurementOOBManagerBean.java</a></li> </ul> </div> <div id="patch"> <h3>Diff</h3> <a id="rhqtrunkmodulescoredomainsrcmainjavaorgrhqcoredomainmeasurementMeasurementOOBjava"></a> <div class="modfile"><h4>Modified: rhq/trunk/modules/core/domain/src/main/java/org/rhq/core/domain/measurement/MeasurementOOB.java (3289 => 3290)</h4> <pre class="diff"> <span class="info">--- rhq/trunk/modules/core/domain/src/main/java/org/rhq/core/domain/measurement/MeasurementOOB.java 2009-03-04 12:15:53 UTC (rev 3289) +++ rhq/trunk/modules/core/domain/src/main/java/org/rhq/core/domain/measurement/MeasurementOOB.java 2009-03-04 16:44:37 UTC (rev 3290) </span><span class="lines">@@ -46,10 +46,7 @@ </span><span class="cx"> " AND bal.schedule = sched " + " AND (UPPER(def.displayName ) LIKE :metricName OR :metricName is null ) " + " AND (UPPER(res.name) LIKE :resourceName OR :resourceName is null ) " + </span><span class="rem">- " AND (UPPER(parent.name) LIKE :parentName OR :parentName is null ) " + - " AND (-1 = :subjectId) OR (res.id IN ( SELECT rr.id FROM Resource rr " + - " JOIN rr.implicitGroups g JOIN g.roles r JOIN r.subjects s " + - " WHERE s.id = :subjectId )) " </span><span class="add">+ " AND (UPPER(parent.name) LIKE :parentName OR :parentName is null ) " </span><span class="cx"> ), @NamedQuery(name=MeasurementOOB.GET_SCHEDULES_WITH_OOB_AGGREGATE_COUNT, query = "SELECT sched.id " + </span><span class="lines">@@ -62,10 +59,7 @@ </span><span class="cx"> " AND sched.resource = res " + " AND (UPPER(def.displayName ) LIKE :metricName OR :metricName is null ) " + " AND (UPPER(res.name) LIKE :resourceName OR :resourceName is null ) " + </span><span class="rem">- " AND (UPPER(parent.name) LIKE :parentName OR :parentName is null ) " + - " AND (-1 = :subjectId) OR (res.id IN ( SELECT rr.id FROM Resource rr " + - " JOIN rr.implicitGroups g JOIN g.roles r JOIN r.subjects s " + - " WHERE s.id = :subjectId )) " </span><span class="add">+ " AND (UPPER(parent.name) LIKE :parentName OR :parentName is null ) " </span><span class="cx"> ), @NamedQuery(name=MeasurementOOB.DELETE_OUTDATED, query = "DELETE FROM MeasurementOOB o " + </span><span class="lines">@@ -180,7 +174,12 @@ </span><span class="cx"> public static final String TRUNCATE_TMP_TABLE = "TRUNCATE TABLE rhq_measurement_oob_tmp"; </span><span class="add">+ public static final String SECURITY_ADDITION = + " AND (res.id IN ( SELECT rr.id FROM Resource rr " + + " JOIN rr.implicitGroups g JOIN g.roles r JOIN r.subjects s " + + " WHERE s.id = :subjectId )) "; </span><span class="cx"> </span><span class="add">+ </span><span class="cx"> private static final long serialVersionUID = 1L; @Id </span></pre></div> <a id="rhqtrunkmodulescoredomainsrcmainjavaorgrhqcoredomainutilPersistenceUtilityjava"></a> <div class="modfile"><h4>Modified: rhq/trunk/modules/core/domain/src/main/java/org/rhq/core/domain/util/PersistenceUtility.java (3289 => 3290)</h4> <pre class="diff"> <span class="info">--- rhq/trunk/modules/core/domain/src/main/java/org/rhq/core/domain/util/PersistenceUtility.java 2009-03-04 12:15:53 UTC (rev 3289) +++ rhq/trunk/modules/core/domain/src/main/java/org/rhq/core/domain/util/PersistenceUtility.java 2009-03-04 16:44:37 UTC (rev 3290) </span><span class="lines">@@ -103,6 +103,33 @@ </span><span class="cx"> return entityManager.createQuery(query.toString()); } </span><span class="add">+ public static Query createNonNamedQueryWithOrderBy(EntityManager entityManager, String queryText, PageControl pageControl) { + Query query; + + if (pageControl.getPrimarySortColumn() != null) { + query = createNonNamedQueryWithOrderBy(entityManager, queryText, pageControl.getOrderingFieldsAsArray()); + } else { + StackTraceElement caller = new Throwable().fillInStackTrace().getStackTrace()[1]; + LOG.warn("Queries should really supply default sort columns. Caller did not: " + caller); + + // Use the standard named query if no sorting is specified + query = entityManager.createQuery(queryText); + } + + setDataPage(query, pageControl); + + return query; + } + + + public static Query createNonNamedQueryWithOrderBy(EntityManager entityManager, String queryText, + OrderingField... orderByFields) { + + StringBuilder query = new StringBuilder(queryText); + buildOrderBy(query, orderByFields); + return entityManager.createQuery(query.toString()); + } + </span><span class="cx"> private static StringBuilder buildOrderBy(StringBuilder query, OrderingField... orderByFields) { boolean first = true; for (OrderingField orderingField : orderByFields) { </span><span class="lines">@@ -270,6 +297,12 @@ </span><span class="cx"> } } </span><span class="add">+ public static String getQueryDefinitionFromNamedQuery(EntityManager entityManager, String queryName) { + + NamedQueryDefinition ndc = getNamedQueryDefinition(entityManager,queryName); + return ndc.getQueryString(); + } + </span><span class="cx"> private static NamedQueryDefinition getNamedQueryDefinition(EntityManager entityManager, String queryName) { SessionFactoryImplementor sessionFactory = getHibernateSessionFactoryImplementor(entityManager); NamedQueryDefinition namedQueryDefinition = sessionFactory.getNamedQuery(queryName); </span></pre></div> <a id="rhqtrunkmodulesenterpriseserverjarsrcmainjavaorgrhqenterpriseservermeasurementMeasurementOOBManagerBeanjava"></a> <div class="modfile"><h4>Modified: rhq/trunk/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/MeasurementOOBManagerBean.java (3289 => 3290)</h4> <pre class="diff"> <span class="info">--- rhq/trunk/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/MeasurementOOBManagerBean.java 2009-03-04 12:15:53 UTC (rev 3289) +++ rhq/trunk/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/MeasurementOOBManagerBean.java 2009-03-04 16:44:37 UTC (rev 3290) </span><span class="lines">@@ -257,10 +257,26 @@ </span><span class="cx"> pc.initDefaultOrderingField("o.oobFactor", PageOrdering.DESC); </span><span class="rem">- Query queryCount = entityManager.createNamedQuery(MeasurementOOB.GET_SCHEDULES_WITH_OOB_AGGREGATE_COUNT); - Query query = PersistenceUtility.createQueryWithOrderBy(entityManager, - MeasurementOOB.GET_SCHEDULES_WITH_OOB_AGGREGATE, pc); </span><span class="add">+ Query queryCount; + Query query; </span><span class="cx"> </span><span class="add">+ boolean isAdmin = authMangager.isOverlord(subject) || authMangager.isSystemSuperuser(subject); + + if (isAdmin) { + queryCount = entityManager.createNamedQuery(MeasurementOOB.GET_SCHEDULES_WITH_OOB_AGGREGATE_COUNT); + query = PersistenceUtility.createQueryWithOrderBy(entityManager, + MeasurementOOB.GET_SCHEDULES_WITH_OOB_AGGREGATE, pc); + } + else { + String tmp = PersistenceUtility.getQueryDefinitionFromNamedQuery(entityManager,MeasurementOOB.GET_SCHEDULES_WITH_OOB_AGGREGATE); + tmp += MeasurementOOB.SECURITY_ADDITION ; + query = PersistenceUtility.createNonNamedQueryWithOrderBy(entityManager,tmp,pc); + + tmp = PersistenceUtility.getQueryDefinitionFromNamedQuery(entityManager,MeasurementOOB.GET_SCHEDULES_WITH_OOB_AGGREGATE_COUNT); + tmp += MeasurementOOB.SECURITY_ADDITION ; + queryCount = PersistenceUtility.createNonNamedQueryWithOrderBy(entityManager,tmp,pc); + } + </span><span class="cx"> // trim crap, toUpper it and put % around it for a LIKE query metricNameFilter = PersistenceUtility.formatSearchParameter(metricNameFilter); resourceNameFilter = PersistenceUtility.formatSearchParameter(resourceNameFilter); </span><span class="lines">@@ -274,11 +290,7 @@ </span><span class="cx"> query.setParameter("parentName", parentNameFilter); queryCount.setParameter("parentName", parentNameFilter); </span><span class="rem">- if (authMangager.isOverlord(subject) || authMangager.isSystemSuperuser(subject)) { - query.setParameter("subjectId", -1); - queryCount.setParameter("subjectId", -1); - } - else { </span><span class="add">+ if (!isAdmin) { </span><span class="cx"> query.setParameter("subjectId", subject.getId()); queryCount.setParameter("subjectId", subject.getId()); } </span> </pre> </div> </div> </body> </html> |