I'm reposting part of this from an email thread. I have a complex dynamic
query where I ultimately map from a ResultSet instead of using Record.
Lukas was curious why I was using ResultSet instead of Record to create my
beans. Here's my reply:
Thanks Lukas, on Record vs. RecordSet this is probably because I am not
familiar with all of JOOQ, especially on the Converter classes. I did TRY
Record but here were my issues:
1. Using your Record class creates several temporary objects per-field on
every row. In particular two ConvertAll converters. These seemed
unnecessary for me since I could just optimally call #getLong or
#getString, etc. on the ResultSet without extra overhead.
2. The ConvertAll implementation is not super efficient for Numbers. For
example, I use INT in my database, but my Object model uses Long so that if
I change the implementation I will not impact clients. To convert from
Integer to Long you first get the row value as an Integer from the
ResultSet. Then you perform a #toString on it, then you convert it to a
BigInteger, then finally get the Long value. I'd suggest adding a case to
ConvertAll something like this:
if (Number.class.isAssignableFrom(fromClass) {
return (U)((Number)from).longValue();
}
You might want to think about this for all the number to number
conversions.
I thought about creating a synthetic Record for this query that I could
create dynamically (to match the dynamic nature of the query), then I could
control the field names, types, and bindings. There is probably a better
way to do it but I'm still exploring.
3. One other reason, but not too important if they were equally efficient,
is that it was easier to write my lambda to rs.getLong(pos) instead of
record.getValue(pos, Long.class).
Is there a simple inline way to specify converters as fields are added to a
result set in such a way that they are used when results are read? Or do I
have to do it globally in Configuration? Basically, I would like NOT to
have to specify a Type to record#getValue, since if the type is right in
the field, it should be in Record correctly. The double ConvertAll
instantiation from record#getValue(int,Class<?>) to #convert0 seems a bit
much.
Thanks for being so responsive and open to my opinions!
--
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.