Skip to main content

QuerySearch Expanders 2.14.0

· 2 min read
Frédéric Hannes
Frédéric Hannes
R&D Engineer

Changes and improvements

Legacy constraint methods

The when(boolean, QueryConstraint) and whenOrElse(boolean, QueryConstraint) methods have been removed after being marked as deprecated for three years. These methods were fundamentally flawed as the constraints are passed as a parameter adn as such evaluated immediately, instead of only when the condition is true as per the design of these constraints.

The exists(qualifiedElementName, variableName, constraint, queryOptions) constraint method has now been marked as deprecated. This method was superseded by a new exists() method in version 1.7.0, which takes a QueryBuilder instance as an argument. Using the QueryBuilder instance if more version transparent and more readable.

Meta-model

The QuerySearchOptionType element has been removed in favor of using the new ValueType system introduced in the elements metamodel. This change aligns the querySearch metamodel more with the elements model which it extend and will allow for more flexibility as the metamodel is refined further. This change was also planned for quite a long time ago and the reason the model was still considered unstable. With this change now implemented, the querySearch metamodel can now be considered to be stable and will no longer be subjected to large breaking changes in the future.

Migration guide

when() constraints

Migrating the when(boolean, QueryConstraint) to when(boolean, Supplier<QueryConstraint>) and whenOrElse(boolean, QueryConstraint, QueryConstraint) to when(boolean, Supplier<QueryConstraint>, Supplier<QueryConstraint>) is very straightforward. Simply add () -> at the start of the constraint to turn it into a lambda expression.

Before
when(filter.getName() != null,
equal("o.name", filter.getName()))
After
when(filter.getName() != null, () ->
equal("o.name", filter.getName()))

The same applies to whenOrElse():

Before
when(filter.getName() != null,
whenOrElse(filter.shouldUseA(),
equal("o.fieldA", filter.getName()),
equal("o.fieldB", filter.getName())))
After
when(filter.getName() != null, () ->
whenOrElse(filter.shouldUseA(),
() -> equal("o.fieldA", filter.getName()),
() -> equal("o.fieldB", filter.getName())))