With all the different ways to do the same thing in JOOQ it's often difficult to find the best approach. I'm trying to write up our basic jOOQ idioms. In doing so I was wondering if their is any difference between these two variants?List<MyObject> results = select.fetch(this::toMyObject);And:List<MyObject> results = select.fetch().stream().map(this::toMyObject).collect(Collectors.toList());
The latter is more verbose but is a standard idiom that allows me to build my own collection types, Maps, or groupings.
Which actually leads me to wonder why there is a bunch of fetchSet methods but no:Set<MyObject> results = select.fetchSet(this::toMyObject);
Why have so many fetchSet methods but none that takes a record mapper? From my perspective there are just too many options in jOOQ. Ever seen that movie The Wonder Boys? It's basically about a brilliant author who lost the ability to edit himself resulting in a novel that was too long for anyone to follow. :) Might it be time to start deprecating methods.
For example, fetch().stream() can do almost everything. Or you could even make a more general purpose collecting fetch and get rid of the rest of all of them.fetch(RecordMapper<...>, Collector<...>);
So two requests:1. What are the primary query patterns (canonical approaches)
2. Please start deprecating methods. :)
For example to collect identities from a joined query I can collect them like fetch("id"), fetch(0), fetch(DSL.name("id")), fetch(Record1::value1), etc.
Alternatively, they could do fetch().map(...). It's overwhelming for them and makes it hard for them to make decisions about what to do.
So I want to choose one or two idioms that they should stick to.
Maybe it is always Cursor,
but what I see instead is fetch in some places, fetchInto, in others, fetch.map others, and event fetch.stream and then just .stream (without a finally call to close).
Its hard for example to visually understand the difference between stream and fetch.stream.
I see fetchOptional in places where the query can return more than one record
SELECT (SELECT 1 UNION SELECT 2)
hugecollection.stream().map(e -> expensiveMapping(e))
.collect(Collectors.toList())
.subList(0, 2);
hugecollection.stream().limit(2).map(e -> expensiveMapping(e))
.collect(Collectors.toList());
whereas fethLazy().fetchOptional does something different than fetchOptional alone.
So it's a lot of choice which (just to me maybe) makes the API harder to understand an use. For some people fewer choices make things easier to understand. But of course fewer choices means some things are harder to do. So I understand it is a balance.
Hi Robert,Thank you very much for elaborating. I think I see what you mean. Let me summarise this topic from a different angle, so we'll get closer to what makes it particularly hard for your peers to grasp the jOOQ API at first:Like many APIs, jOOQ tries to establish a vocabulary, and a common set of types from your examples, we can see: