From: <jma...@rh...> - 2009-07-16 05:24:28
|
<!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] [4422] end-to-end flow for new criteria query generation works from the CLI; </title> </head> <body> <div id="msg"> <dl> <dt>Revision</dt> <dd>4422</dd> <dt>Author</dt> <dd>jmarques</dd> <dt>Date</dt> <dd>2009-07-16 00:24:21 -0500 (Thu, 16 Jul 2009)</dd> </dl> <h3>Log Message</h3> <pre>end-to-end flow for new criteria query generation works from the CLI; </pre> <h3>Modified Paths</h3> <ul> <li><a href="#rhqtrunkmodulescoredomainsrcmainjavaorgrhqcoredomaincriteriaCriteriajava">rhq/trunk/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/Criteria.java</a></li> <li><a href="#rhqtrunkmodulescoredomainsrcmainjavaorgrhqcoredomainutilCriteriaQueryGeneratorjava">rhq/trunk/modules/core/domain/src/main/java/org/rhq/core/domain/util/CriteriaQueryGenerator.java</a></li> <li><a href="#rhqtrunkmodulesenterpriseserverjarsrcmainjavaorgrhqenterpriseserveralertAlertManagerLocaljava">rhq/trunk/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertManagerLocal.java</a></li> <li><a href="#rhqtrunkmodulesenterpriseserverjarsrcmainjavaorgrhqenterpriseserveralertAlertManagerRemotejava">rhq/trunk/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertManagerRemote.java</a></li> </ul> </div> <div id="patch"> <h3>Diff</h3> <a id="rhqtrunkmodulescoredomainsrcmainjavaorgrhqcoredomaincriteriaCriteriajava"></a> <div class="modfile"><h4>Modified: rhq/trunk/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/Criteria.java (4421 => 4422)</h4> <pre class="diff"> <span class="info">--- rhq/trunk/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/Criteria.java 2009-07-16 05:09:19 UTC (rev 4421) +++ rhq/trunk/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/Criteria.java 2009-07-16 05:24:21 UTC (rev 4422) </span><span class="lines">@@ -37,47 +37,42 @@ </span><span class="cx"> */ public abstract class Criteria implements Serializable { </span><span class="add">+ private enum Type { + FILTER, FETCH, SORT; + } + </span><span class="cx"> private static final long serialVersionUID = 1L; </span><span class="rem">- private List<Field> filterFields; - private List<Field> fetchFields; - private List<Field> sortFields; - private List<Field> overrideFields; - </span><span class="cx"> protected Map<String, String> filterOverrides; protected Map<String, String> sortOverrides; private List<String> orderingFieldNames; public Criteria() { </span><span class="rem">- Field[] fields = this.getClass().getDeclaredFields(); - filterFields = new ArrayList<Field>(); - fetchFields = new ArrayList<Field>(); - sortFields = new ArrayList<Field>(); - overrideFields = new ArrayList<Field>(); </span><span class="cx"> </span><span class="rem">- for (Field field : fields) { - field.setAccessible(true); - if (field.getName().startsWith("filter")) { - filterFields.add(field); - } else if (field.getName().startsWith("fetch")) { - fetchFields.add(field); - } else if (field.getName().startsWith("sort")) { - sortFields.add(field); - } else { - overrideFields.add(field); - } - } - </span><span class="cx"> filterOverrides = new HashMap<String, String>(); sortOverrides = new HashMap<String, String>(); orderingFieldNames = new ArrayList<String>(); } </span><span class="add">+ private List<Field> getFields(Type fieldType) { + String prefix = fieldType.name().toLowerCase(); + List<Field> results = new ArrayList<Field>(); + + for (Field field : this.getClass().getDeclaredFields()) { + field.setAccessible(true); + if (field.getName().startsWith(prefix)) { + results.add(field); + } + } + + return results; + } + </span><span class="cx"> public Map<String, Object> getFilterFields() { Map<String, Object> results = new HashMap<String, Object>(); </span><span class="rem">- for (Field filterField : filterFields) { </span><span class="add">+ for (Field filterField : getFields(Type.FILTER)) { </span><span class="cx"> Object filterFieldValue = null; try { filterFieldValue = filterField.get(this); </span><span class="lines">@@ -101,7 +96,7 @@ </span><span class="cx"> public List<String> getFetchFields() { List<String> results = new ArrayList<String>(); </span><span class="rem">- for (Field fetchField : fetchFields) { </span><span class="add">+ for (Field fetchField : getFields(Type.FETCH)) { </span><span class="cx"> Object fetchFieldValue = null; try { fetchField.setAccessible(true); </span><span class="lines">@@ -126,7 +121,7 @@ </span><span class="cx"> public PageControl getPageControl() { PageControl pc = PageControl.getUnlimitedInstance(); for (String fieldName : orderingFieldNames) { </span><span class="rem">- for (Field sortField : sortFields) { </span><span class="add">+ for (Field sortField : getFields(Type.SORT)) { </span><span class="cx"> if (sortField.getName().equals(fieldName) == false) { continue; } </span></pre></div> <a id="rhqtrunkmodulescoredomainsrcmainjavaorgrhqcoredomainutilCriteriaQueryGeneratorjava"></a> <div class="modfile"><h4>Modified: rhq/trunk/modules/core/domain/src/main/java/org/rhq/core/domain/util/CriteriaQueryGenerator.java (4421 => 4422)</h4> <pre class="diff"> <span class="info">--- rhq/trunk/modules/core/domain/src/main/java/org/rhq/core/domain/util/CriteriaQueryGenerator.java 2009-07-16 05:09:19 UTC (rev 4421) +++ rhq/trunk/modules/core/domain/src/main/java/org/rhq/core/domain/util/CriteriaQueryGenerator.java 2009-07-16 05:24:21 UTC (rev 4422) </span><span class="lines">@@ -73,7 +73,7 @@ </span><span class="cx"> this.pageControl = pageControl; } </span><span class="rem">- String criteriaClassName = criteria.getClass().getName(); </span><span class="add">+ String criteriaClassName = criteria.getClass().getSimpleName(); </span><span class="cx"> className = criteriaClassName.substring(0, criteriaClassName.length() - 8); StringBuilder aliasBuilder = new StringBuilder(); </span><span class="lines">@@ -184,8 +184,14 @@ </span><span class="cx"> results.append(alias).append(NL); } results.append("FROM ").append(className).append(' ').append(alias).append(NL); </span><span class="rem">- for (String fetchJoin : criteria.getFetchFields()) { - results.append("LEFT JOIN FETCH ").append(alias).append('.').append(fetchJoin).append(NL); </span><span class="add">+ if (countQuery == false) { + /* + * don't fetch in the count query to avoid: "query specified join fetching, + * but the owner of the fetched association was not present in the select list" + */ + for (String fetchJoin : criteria.getFetchFields()) { + results.append("LEFT JOIN FETCH ").append(alias).append('.').append(fetchJoin).append(NL); + } </span><span class="cx"> } if (authorizationJoinFragment != null) { results.append(authorizationJoinFragment); </span></pre></div> <a id="rhqtrunkmodulesenterpriseserverjarsrcmainjavaorgrhqenterpriseserveralertAlertManagerLocaljava"></a> <div class="modfile"><h4>Modified: rhq/trunk/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertManagerLocal.java (4421 => 4422)</h4> <pre class="diff"> <span class="info">--- rhq/trunk/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertManagerLocal.java 2009-07-16 05:09:19 UTC (rev 4421) +++ rhq/trunk/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertManagerLocal.java 2009-07-16 05:24:21 UTC (rev 4422) </span><span class="lines">@@ -87,5 +87,5 @@ </span><span class="cx"> PageList<Alert> findAlerts(Subject subject, Alert criteria, AlertPriority priority, int[] resourceIds, long beginTime, long endTime, PageControl pc) throws FetchException; </span><span class="rem">- PageList<Alert> findAlerts(Subject subject, AlertCriteria criteria, PageControl pc) throws FetchException; </span><span class="add">+ PageList<Alert> findAlertsByCriteria(Subject subject, AlertCriteria criteria, PageControl pc) throws FetchException; </span><span class="cx"> } \ No newline at end of file </span></pre></div> <a id="rhqtrunkmodulesenterpriseserverjarsrcmainjavaorgrhqenterpriseserveralertAlertManagerRemotejava"></a> <div class="modfile"><h4>Modified: rhq/trunk/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertManagerRemote.java (4421 => 4422)</h4> <pre class="diff"> <span class="info">--- rhq/trunk/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertManagerRemote.java 2009-07-16 05:09:19 UTC (rev 4421) +++ rhq/trunk/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertManagerRemote.java 2009-07-16 05:24:21 UTC (rev 4422) </span><span class="lines">@@ -75,7 +75,7 @@ </span><span class="cx"> throws FetchException; @WebMethod </span><span class="rem">- PageList<Alert> findAlerts( // </span><span class="add">+ PageList<Alert> findAlertsByCriteria( // </span><span class="cx"> @WebParam(name = "subject") Subject subject, // @WebParam(name = "criteria") AlertCriteria criteria, // @WebParam(name = "pageControl") PageControl pageControl) // </span> </pre> </div> </div> </body> </html> |