There, I've registered a feature request to enhance the ResultQuery Javadoc:
https://github.com/jOOQ/jOOQ/issues/6196

ResultQuery.iterator() is already overridden to add some Javadoc

2017-05-09 15:22 GMT+02:00 Lukas Eder <[email protected]>:

> Hi FP,
>
> That's an interesting discovery! Indeed, ResultQuery extends Iterable. The
> reason for this is this quite neat API usage here:
> https://blog.jooq.org/2016/09/27/a-hidden-jooq-gem-foreach-
> loop-over-resultquery/
>
> I.e. the "classic" Java-5 foreach loop now works like a PL/SQL implicit
> cursor
>
> // Automatic execution here
> for (Record rec : query) {
>   ...
> }
>
>
> I hadn't even thought of the fact that the forEach() method is
> automatically inherited as well. All the better! :)
>
> The implementation is in AbstractResultQuery:
>
> @Override
> public final Iterator<R> iterator() {
>     return fetch().iterator();
> }
>
>
> And then, Iterable.forEach():
>
> default void forEach(Consumer<? super T> action) {
>     Objects.requireNonNull(action);
>     for (T t : this) { // Implicit Iterable.iterator() call here
>         action.accept(t);
>     }
> }
>
>
> It's trivial, just convenience.
> Hope this helps,
> Lukas
>
> 2017-05-09 14:50 GMT+02:00 FP <[email protected]>:
>
>> Hello everyone,
>>
>> I had some JOOQ code that I was writing to generate a dynamic query.
>>
>> I had made a selectQuery as such:
>>
>> SelectQuery<Record10<...>> query = ...;
>>
>> Afterwards, I had forgotten to perform a query.fetch(), and instead wrote:
>>
>> query.forEach(entry -> { ... });
>>
>> To my surprise, this not only compiled but also worked! I checked every
>> interface that SelectQuery extends and saw that this is supported due to
>> the SelectQuery <- Select <- ResultQuery <- Iterable extension, but was
>> unable to find an implementation that would explain this behaviour.
>>
>> Could someone explain what is happening here?
>>
>> Best,
>> FP
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "jOOQ User Group" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups "jOOQ 
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to