Use in generated code java.util.Date

262 views
Skip to first unread message

Darren S

unread,
Nov 21, 2013, 4:44:09 AM11/21/13
to jooq...@googlegroups.com
I think it would be nice if there was an option in the code generator to define the setter/getters as java.util.Date and not java.sql.Date/Timestamp.  I know their is a difference in the objects and I would expect that when fetching a record, the implementation of the java.util.Date value would be one of the java.sql.X ones.  I think it would just be nice to do setMyField(new Date()).

I started looking at the code generator and seeing if this was an easy change.  It works fine for the pojos, but then fails for the DAOs and Records.  I found I ran into an issue with the DataType object.  So would this even be possible, or would this seem like it would go against the core design/principles of jOOQ?  I assume that supporting this in the pojos might be easy, but I was curious if this would be possible with the records too.

Darren

Lukas Eder

unread,
Nov 21, 2013, 5:27:54 AM11/21/13
to jooq...@googlegroups.com
Hi Darren,

2013/11/21 Darren S <darren.s...@gmail.com>

I think it would be nice if there was an option in the code generator to define the setter/getters as java.util.Date and not java.sql.Date/Timestamp.  I know their is a difference in the objects and I would expect that when fetching a record, the implementation of the java.util.Date value would be one of the java.sql.X ones.  I think it would just be nice to do setMyField(new Date()).

Have you seen the manual's section about Converters:

... and how to enforce them to the code generator:
http://www.jooq.org/doc/3.2/manual/code-generation/custom-data-types/

With jOOQ 3.2, you can just rewrite all SQL DATE, TIME, TIMESTAMP types to use your own custom Converter<T, java.util.Date>. Before, you could only explicitly pattern-match column names, not data types
 
I started looking at the code generator and seeing if this was an easy change.  It works fine for the pojos, but then fails for the DAOs and Records.  I found I ran into an issue with the DataType object.  So would this even be possible, or would this seem like it would go against the core design/principles of jOOQ?  I assume that supporting this in the pojos might be easy, but I was curious if this would be possible with the records too.

Yes, it would be against jOOQ's design principles to introduce native support for such "custom" data types, even if they're part of the JDK (java.util.Date? java.util.Calendar? JodaTime? etc...). But I think the above features should cover all of your needs.

Cheers
Lukas
 

Darren Shepherd

unread,
Nov 21, 2013, 11:42:09 AM11/21/13
to jooq...@googlegroups.com
I tried that out and it seemed to do exactly what I wanted.  I noticed from reading the code that there is a <types/> element where I can just match "datetime" and not specific fields names.  This option doesn't seem to be documented.  Is there some reason its not documented?  Should I not use this feature?

Darren


--
You received this message because you are subscribed to a topic in the Google Groups "jOOQ User Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jooq-user/VExjfjh942g/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jooq-user+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Lukas Eder

unread,
Nov 21, 2013, 1:05:47 PM11/21/13
to jooq...@googlegroups.com
Hmm, <types/> should be documented. It was implemented with:

I'll fix this tomorrow.


2013/11/21 Darren Shepherd <darren.s...@gmail.com>

--
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.

Lukas Eder

unread,
Nov 22, 2013, 9:40:50 AM11/22/13
to jooq...@googlegroups.com
Aha, I get it. I had previously only documented it here:

Fixed the below to match the above:

Cheers
Lukas


2013/11/21 Lukas Eder <lukas...@gmail.com>
Reply all
Reply to author
Forward
0 new messages