Primitive Types in Pojos

25 views
Skip to first unread message

andreasvor...@gmail.com

unread,
Jan 4, 2020, 2:28:14 AM1/4/20
to jOOQ User Group
Hi together and a happy new year.

First, i am really impressed by Jooq and we used it in the project for 1 year now. (powerfull and easy)
Now the project is more mature and it comes to optimication.
As it is a number crunching project we must not have wrapped datatypes, because it leads to a lot auf auto(un)boxing and slows down performance.
Is there a way, that jooq generates the pojos with primitive types for nonnull values? (float instead of Float)

Thanks in advance.

BR Andi

Knut Wannheden

unread,
Jan 6, 2020, 5:02:02 AM1/6/20
to jOOQ User Group
Hi Andi,


On Saturday, January 4, 2020 at 8:28:14 AM UTC+1, andi wrote:
Hi together and a happy new year.

Happy new year to you, too. 

First, i am really impressed by Jooq and we used it in the project for 1 year now. (powerfull and easy)

Thanks for the kind words.
 
Now the project is more mature and it comes to optimication.
As it is a number crunching project we must not have wrapped datatypes, because it leads to a lot auf auto(un)boxing and slows down performance.
Is there a way, that jooq generates the pojos with primitive types for nonnull values? (float instead of Float)

I assume you are using POJOs in order to be able to use methods like ResultQuery#fetchInto(Class) and Record#into(Class), which behind the scenes rely on jOOQ's RecordMapper.

jOOQ's default DefaultRecordMapper implementation cannot fully support primitive types in a generic way, as there would be no way to distinguish null values from the primitive type's default value (e.g. 0L for long). There was a recent related discussion which may also help to understand the problem: https://github.com/jOOQ/jOOQ/issues/9704#issuecomment-570514225.

Please also note that a generic RecordMapper implementation would be expected to use reflection to call setter methods, and when Method#invoke(Object, Object...) gets called you would already there have some autoboxing. So a custom RecordMapper implementation would also not fully alleviate this issue.

To optimize for performance I think you will in a first step want to optimize the SQL query and in a second step also review your JDBC parameters, which for many databases can have a big impact performance. But I assume you have already done that.

To further maximize performance for a given query you may want to go down to the JDBC level and do the POJO mapping for the query manually, which you can achieve by using ResultQuery#fetchResultSet() which returns a plain JDBC ResultSet. With performance testing you will then be able to establish how much this improves things.

Hope this helps,
Knut

andreasvor...@gmail.com

unread,
Jan 7, 2020, 7:56:26 AM1/7/20
to jOOQ User Group
Hi Knut,

thank you very much for the detailed answer.
your assumption is correct.
You gave some usefull tips that we will process now. In the end ResultQuery#fetchResultSet() is what i was looking for.

bye, Andi.

Lukas Eder

unread,
Jan 10, 2020, 6:59:25 AM1/10/20
to jOOQ User Group
Folks,

While ResultQuery::fetchResultSet is a workaround for the time being (don't forget to close the ResultSet with try-with-resources!), it obviously bypasses a lot of useful jOOQ features by exposing the JDBC ResultSet directly.

In the future, we'll address this issue, which isn't strictly an issue about being able to read primitive types from the ResultSet, but to be able to bypass the intermediate org.jooq.Record type in the mapping, which is basically a wrapper for an Object[], another reason why wrapper types are necessary in jOOQ apart from reflection. Once this intermediate type is bypassable, then reflection won't be the limiting factor anymore either. An interesting feature that will not contribute to making this a trivial change is that currently, all fetch() operations pass by the RecordListener SPI, which would also have to be bypassed.

Relevant feature requests are:

https://github.com/jOOQ/jOOQ/issues/6544 Optimise fetchXYZ() operations by allowing to bypass the RecordListener
https://github.com/jOOQ/jOOQ/issues/6737 Add Settings.fetchIntermediateRecords

I hope this helps,
Lukas

--
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 jooq-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jooq-user/00aa8fa4-bfa2-481d-9c0b-1a579b1712d3%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages