FWIW, when I need something like this for the WHERE part of a query I do it
with the ternary operator and a static import of ExpressionFactory (which
your IDE can add for you), like:

.and(yearRange != null ? APPOINTMENT_DATE.gt(yearRange) : expTrue())

I don't think there is a good alternative to handle prefetches, but this
handles the WHERE clause very well in my opinion.

On Mon, Jul 8, 2024 at 5:30 AM Jurgen Doll <jur...@ivoryemr.co.za> wrote:

> Hi All
>
> What about borrowing "apply" from Function/UnaryOperator ?
> Then we'll have the following API added to Expression:
>
> /**
>   * Apply the provided UnaryOperator function to the current Expression.
>   */
> public Expression apply( UnaryOperator<Expression> op )
> {
>      return op.apply( this );
> }
>
> And the same for ObjectSelect but passing a Consumer instead:
>
> /**
>   * Apply the provided Consumer to the current ObjectSelect.
>   */
> public ObjectSelect<T> apply( Consumer<ObjectSelect<T>> op )
> {
>      op.accept( this );
>      return this;
> }
>
> In addition I'd still very much like to have "apply" API that takes a
> boolean parameter as well. For simple cases this will allow user code to
> be more concise without the ternary pattern clutter.
>
> Thoughts, tweaks, likes or objections ?
>
> Regards
> Jurgen
>

Reply via email to