Details
-
New Feature
-
Status: Closed
-
Normal
-
Resolution: Fixed
-
None
-
None
-
None
-
Platform Sprint 140
Description
It would be nice if we can build HstQuery through a fluent builder API.
Rough idea in example code for comparison:
AS-IS
/* * The current way */ private HstQuery createHstQueryInfluently() throws Exception { HstRequestContext requestContext = RequestContextProvider.get(); HippoBean scopeBean = requestContext.getSiteContentBaseBean(); HstQuery query = requestContext.getQueryManager().createQuery(scopeBean); Filter filter = query.createFilter(); Filter nestedFilter1 = query.createFilter(); nestedFilter1.addEqualTo("myhippoproject:customid", "123"); Filter nestedFilter2 = query.createFilter(); Filter nestedFilter21 = query.createFilter(); nestedFilter21.addLike("myhippoproject:title", "Hello%"); Filter nestedFilter22 = query.createFilter(); nestedFilter22.addContains("myhippoproject:description", "foo"); nestedFilter2.addOrFilter(nestedFilter21); nestedFilter2.addOrFilter(nestedFilter22); filter.addAndFilter(nestedFilter1); filter.addAndFilter(nestedFilter2); query.setFilter(filter); return query; }
TO-BE
/* * New fluent way */ private HstQuery createHstQueryFluently() throws Exception { HstRequestContext requestContext = RequestContextProvider.get(); HippoBean scopeBean = requestContext.getSiteContentBaseBean(); // constructor-arg and scope can be optional with sensible defaults. // obviously .filter() is also optional. // .filter() is to set filter whereas filter() to create a new filter as static import. return new HstQueryBuilder(requestContext.getQueryManager()) .scope(scopeBean) .filter( and(filter("myhippoproject:customid").equalsTo("123"), or( filter("myhippoproject:title").like("Hello%"), filter("myhippoproject:description").contains("foo") ) ) ); }
Attachments
Issue Links
- causes
-
HSTTWO-3835 Better compile time guidance of the fluent query api
- Closed
- includes
-
HSTTWO-3832 Avoid possible NPE in scope related methods in HstQueryBuilder
- Closed
-
HSTTWO-3833 Make sure ofTypes and ofPrimaryTypes in fluent api is resilient against null values
- Closed
-
CMS-12879 Support fluent query api in org.hippoecm.hst.util.ContentBeanUtils as well
- Open
-
HSTTWO-3823 Use fluent query api in testsuite
- Closed
-
HSTTWO-3827 Make sure hst fluent query api is resilient for order by null arrays or arrays with empty field names
- Closed
-
HSTTWO-3828 Improve exception handling of the new fluent query api
- Closed