New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for RowN.mapping(Function<? super Object[], ? extends U>) #12515
Comments
Thanks for your suggestion. I don't think it's possible to abstract over arity in Java, other than what Scala / Haskell did with
Also, from my experience, it's generally not a good idea to overload methods taking lambda arguments, because method references (and in this case, constructor references) suddenly stop working, which would be a pain if the arity is high. A new method name could be invented, but this kinda hints at the idea or approach not being clean.
If you look at jOOQ's internals, that's precisely what jOOQ does all the time. Look e.g. at If you could show a specific example of what you're trying to do, there might be a better API possible than the one you asked for. For example, there's a possibility of embedded keys being the answer to your question about composite keys: But I'm just guessing. A real world example of what actual problem you're trying to solve would be helpful. |
I understand the issues with arity and suspected that this feature might be wishful thinking. I figured raising it might be worth while even so. I'm not too unhappy with the switch-based approach, it just feels a bit off. :) I looked at using embedded keys, but ran into issues since we make extensive use of natural keys and need to access the columns individually as well. I found no way of doing that. Didn't think of raising this as an issue to be honest. Here's a snippet of what I'm currently doing:
|
Well, we can hope! I, for one, am hoping for higher kinded generics, or even what TypeScript has. Though, that too, is probably wishful thinking, in Java
It does. But so does stopping type safety at degree 22... 😅. Within jOOQ, we have an API and implementation code generator. Specifically, we use Xtend's templates to generate the code. It gets too boring to write, otherwise. Once that's in place, it's not as bad anymore to support degrees 1 - 22 for each such case.
Ah yes, embeddable keys replace their columns by default, though it's possible to turn that off (though, not for keys yet): There are some issues to fix this, already
I see, thanks for the example. Well, as a workaround, you could use
However, I get your point now. I'm not sure if I was planning to review this as part of #7100 (comment), and then delayed it until the implementation of #4727, which raises a few questions in terms of type hierarchy consistency. Will review again for 3.16 |
Thank you for taking the time to understand my need. We’ll get by with my current implementation for now, and then move to |
I just needed this myself, recently, and was probably as surprised as you were, when it wasn't there. The most obvious choice of method signature would be: <U> SelectField<U> mapping(Function<? super Object[], ? extends U> function);
<U> SelectField<U> mapping(Class<U> uType, Function<? super Object[], ? extends U> function); An alternative would be to apply |
Implemented in jOOQ 3.17.0. Thanks again for your feature request. |
Use case:
We have situations where we work on groups of fields where the group is of unknown size. The current use case is composite keys, but I can see this as useful for other groups as well.
By wrapping the fields in a
row
we can attach a mapping function to the resulting selectfield at query build time, something that is very powerful when building dynamic reusable queries.Unfortunately the RowN interface does not provide the
mapping
method, thus we have to switch over the group size and create a lot of boilerplate/duplicate code.Possible solution you'd like to see:
Being able to attach a mapping on a RowN. This mapping could provide us with a Record that can be used together with the original group of fields to get the values and instantiate the user class we want.
The parameters provided to the mapping-method could include the group of fields as well as the record, but this isn’t strictly necessary.
Possible workarounds:
Switch over the group size and create the specific methods needed.
The text was updated successfully, but these errors were encountered: