Bug 1080171 - CriteriaQuery generation fails when only a disabled NonBindingFilter is present
Summary: CriteriaQuery generation fails when only a disabled NonBindingFilter is present
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: RHQ Project
Classification: Other
Component: Core Server
Version: 4.10
Hardware: Unspecified
OS: Unspecified
unspecified
urgent
Target Milestone: ---
: RHQ 4.11
Assignee: Heiko W. Rupp
QA Contact: Mike Foley
URL:
Whiteboard:
Depends On:
Blocks: 1003211
TreeView+ depends on / blocked
 
Reported: 2014-03-24 20:24 UTC by Heiko W. Rupp
Modified: 2014-07-21 10:13 UTC (History)
1 user (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2014-07-21 10:13:54 UTC
Embargoed:


Attachments (Terms of Use)
Possible patch (2.13 KB, patch)
2014-03-26 15:44 UTC, Heiko W. Rupp
no flags Details | Diff

Description Heiko W. Rupp 2014-03-24 20:24:57 UTC
While looking at https://github.com/rhq-project/rhq/pull/2

I got failed executions of the rest-tests because of

Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: ORDER near line 4, column 1 [SELECT alert
FROM org.rhq.core.domain.alert.Alert alert
WHERE
ORDER BY alert.ctime DESC, alert.id ASC
]

Here the WHERE clause is empty.
Looking at the code reveals that we do some incomplete checking here

This is the code in question
org/rhq/enterprise/server/util/CriteriaQueryGenerator.java:550



        Map<String, Object> filterFields = getFilterFields(criteria);
        if (filterFields.size() > 0 || authorizationPermsFragment != null
            || authorizationCustomConditionFragment != null || searchExpressionWhereClause != null) {
            results.append("WHERE ");  <<<<-----------  (1)
        }

        String conjunctiveFragment = criteria.isFiltersOptional() ? "OR " : "AND ";
        boolean wantCaseInsensitiveMatch = !criteria.isCaseSensitive();

        // criteria
        StringBuilder conjunctiveResults = new StringBuilder();
        boolean firstCrit = true;
        for (Map.Entry<String, Object> filterField : filterFields.entrySet()) {
            Object filterFieldValue = filterField.getValue();

            // if this filter field is non-binding (that is, the query has no parameter whose value is to be bound for the field)
            // and that filter field is turned off, do nothing and continue to the next filter.
            // this in effect does not filter on this field at all.
            if (Criteria.NonBindingOverrideFilter.OFF.equals(filterFieldValue)) {
                continue;  <<<<<<<<<<<<<---- (2) 
            }


At 1) we check if the filterList is not empty and put a 'WHERE' in  then at 2) if the filter is 'OFF', we do not put it in the WHERE clause. 
If that was the only filter statement in the list, we are left with a WHERE keyword without a clause.

Comment 1 Heiko W. Rupp 2014-03-26 15:44:07 UTC
Created attachment 879069 [details]
Possible patch

Comment 2 Heiko W. Rupp 2014-03-28 11:42:21 UTC
Merged by Lukas from https://github.com/rhq-project/rhq/pull/17

Comment 3 Heiko W. Rupp 2014-07-21 10:13:54 UTC
Bulk closing of RHQ 4.11 issues, now that RHQ 4.12 is out.

If you find an issue with those, please open a new BZ, linking to the old one.


Note You need to log in before you can comment on or make changes to this bug.