Re: Fluent API addition request

"Jurgen Doll" <[email protected]> Wed, 10 Jul 2024 15:29:18 +0200
Newsgroups gmane.comp.java.cayenne.devel
Organization iVory EMR
Message-ID <op.2qo3q4dky9kazd@admin-pc>
Hi Nikita

That's an interesting suggestion with the Predicate parameter. I gave it  
some thought and came up with the following concern.

Consider that ObjectSelect is a builder and that the fluent method  
invocations can happen in "kind of" any order. So then if they're  
rearranged it may result in the ObjectSelect being in a different state  
than intended and the predicate subsequently not evaluating as expected.

I'm inclined to not let the developer sabotage themselves like this, on  
the other hand maybe there's a use case for it.
Did you have a use case in mind ?  What do you think about the order  
influencing the outcome ?

Thanks, regards
Jurgen


On Tue, 09 Jul 2024 10:06:51 +0200, Nikita Timofeev  
<[email protected]> wrote:

> Hi all,
>
> I like the functional style of apply(). For me it seems best as it's
> flexible and has a small footprint.
> And as for the condition part we could just add overloaded version with
> Predicate<> argument, like this:
>
> public ObjectSelect<T> apply(Predicate<ObjectSelect<T>> cond,
> Consumer<ObjectSelect<T>> op) {
>      if(cond.test(this)) {
>          op.accept( this );
>      }
>      return this;
> }
>
> John's example could be done like this:
>
> .apply(q -> yearRange != null, q ->   
> q.and(APPOINTMENT_DATE.gt(yearRange)))
>