Exploring code generation and running into issues with name mapping

35 views
Skip to first unread message

Carsten Langsdorf

unread,
Jul 14, 2016, 7:11:12 PM7/14/16
to jOOQ User Group
Hi everyone,

I'm currently digging into jOOQ's code generation feature, and I'm running into issues with generated names. 
Over the years, I have developed my own naming pattern, and thus I would like to preserve names as they are, if possible. I will use some table and view names to explain the situation and the approaches I already have taken.

Among others, I got the following tables and corresponding views in an H2 database:

Account
Server
ServerAccount

V_Account
V_Server
V_ServerAccount

And I'm trying to generate code for those while completely preserving the names.

Here are the names I get from a plain generation run without any name manipulation:

Account
Server
Serveraccount

VAccount
VServer
VServeraccount


That's not really what I wanted. A peek into the documentation led me to approach #1:

<generator>
   
<!-- ... -->
   
<strategy>
       
<name>org.jooq.util.KeepNamesGeneratorStrategy</name>
   
</strategy>
</generator>


(Omitting the top level <configuration> tag and the <jdbc> section)

Resulting names:

ACCOUNT
SERVER
SERVERACCOUNT

V_ACCOUNT
V_SERVER
V_SERVERACCOUNT


Again, not quite. Digging further took me to approach #2:

<generator>
   
<!-- ... -->
   
<strategy>
       
<matchers>
           
<tables>
               
<table>
                   
<!-- no expression on purpose -->
                   
<tableClass>
                       
<transform>AS_IS</transform>
                   
</tableClass>
               
</table>
           
</tables>
       
</matchers>
   
</strategy>
</generator>


Result: Same as above.

Approach #3:

<generator>
   
<!-- ... -->
   
<strategy>
       
<matchers>
           
<tables>
               
<table>
                   
<expression>(\w)+</expression>
                   
<tableClass>
                       
<expression>$0</expression>
                   
</tableClass>
               
</table>
           
</tables>
       
</matchers>
   
</strategy>
</generator>


Again, the same result.

Finally, I tried to use AsInDatabaseStrategy, as defined in the documentation:

<generator>
   
<!-- ... -->
   
<strategy>
       
<name>org.oddloot.db.AsInDatabaseStrategy</name>
   
</strategy>
</generator>


And this took me back to

Account
Server
Serveraccount

VAccount
VServer
VServeraccount


Of course, all these results are pretty much usable - only not quite what I wanted.

Am I doing something fundamentally wrong here, or just missing something?

Any suggestions/hints really appreciated.

Cheers,
Carsten

Lukas Eder

unread,
Jul 15, 2016, 12:43:35 PM7/15/16
to jooq...@googlegroups.com
Hi Carsten,

Are those tables in your database really case sensitive? In other words, do you do:

CREATE TABLE VAccount ( ... );

or

CREATE TABLE "VAccount" ( ... );

Because in the first case, the H2 database will already lose your upper/lower case information and report them to jOOQ's code generator in all upper case. That would explain the KeepNamesGeneratorStrategy behaviour.

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.
For more options, visit https://groups.google.com/d/optout.

Message has been deleted

Carsten Langsdorf

unread,
Jul 15, 2016, 7:49:02 PM7/15/16
to jooq...@googlegroups.com
Hi Lukas,

yup, that was the issue. Thanks again.

I had completely forgotten about the automatic conversion, but now I found out it can be disabled by appending ;DATABASE_TO_UPPER=FALSE to the database URL. I will try that and see if it works well enough.

Cheers,
Carsten

--
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/cncowd9o_fc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jooq-user+...@googlegroups.com.

Lukas Eder

unread,
Jul 16, 2016, 3:04:02 AM7/16/16
to jooq...@googlegroups.com
Huh, interesting, I wasn't aware of that flag. But if you want to stay on the safe side, it's probably best to make all identifiers in your database case-sensitive by using double quotes. I think case-sensitivity is an all or nothing thing, otherwise there will always be forgotten cases / edge cases, etc.

Cheers,
Lukas

2016-07-16 1:37 GMT+02:00 Carsten Langsdorf <carsten....@gmail.com>:
Hi Lukas,

yup, that was the issue. Thanks again.

I had completely forgotton about the automatic conversion, but now I found out it can be disabled by appending ;DATABASE_TO_UPPER=FALSE to the database URL.

Cheers,
Carsten

2016-07-15 18:43 GMT+02:00 Lukas Eder <lukas...@gmail.com>:

--
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/cncowd9o_fc/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/d/optout.

Carsten Langsdorf

unread,
Jul 16, 2016, 11:09:38 PM7/16/16
to jooq...@googlegroups.com
I tried the flag, and it does not seem to work. It had been attributed as experimental anyway.

Concerning my db identifiers and the resulting class names - yep, I could use double quotes. That would imply I'd have to pass all my automatically generated scripts through another batch edit layer, and weighing the potential error source I would also introduce against the benefit makes me think I might be better off just sticking to plain unmodified uppercase and focusing on more crucial tasks.

One of which is another thing you might be able to give me a hint about. I'm using JavaFX via FXML for the client, and it's a plain desktop application. The database is strictly local, and I'm using H2 in embedded mode. The next thing I'm pondering about is whether I should stick with jOOQ alone to drive the JavaFX controls efficiently and elegantly, or I should also use DataFX or similar. Also, I'm not familiar with DataFX yet and thus don't know how well it would work in conjunction with jOOQ.

Any insights/hints on that one?

Cheers,
Carsten

2016-07-16 9:04 GMT+02:00 Lukas Eder <lukas...@gmail.com>:
Huh, interesting, I wasn't aware of that flag. But if you want to stay on the safe side, it's probably best to make all identifiers in your database case-sensitive by using double quotes. I think case-sensitivity is an all or nothing thing, otherwise there will always be forgotten cases / edge cases, etc.

Cheers,
Lukas

2016-07-16 1:37 GMT+02:00 Carsten Langsdorf <carsten....@gmail.com>:
Hi Lukas,

yup, that was the issue. Thanks again.

I had completely forgotten about the automatic conversion, but now I found out it can be disabled by appending ;DATABASE_TO_UPPER=FALSE to the database URL.

Lukas Eder

unread,
Jul 17, 2016, 2:19:28 PM7/17/16
to jooq...@googlegroups.com
2016-07-17 5:09 GMT+02:00 Carsten Langsdorf <carsten....@gmail.com>:
I tried the flag, and it does not seem to work. It had been attributed as experimental anyway.

Concerning my db identifiers and the resulting class names - yep, I could use double quotes. That would imply I'd have to pass all my automatically generated scripts through another batch edit layer, and weighing the potential error source I would also introduce against the benefit makes me think I might be better off just sticking to plain unmodified uppercase and focusing on more crucial tasks.

That sounds like an excellent plan :)
 
One of which is another thing you might be able to give me a hint about. I'm using JavaFX via FXML for the client, and it's a plain desktop application. The database is strictly local, and I'm using H2 in embedded mode. The next thing I'm pondering about is whether I should stick with jOOQ alone to drive the JavaFX controls efficiently and elegantly, or I should also use DataFX or similar. Also, I'm not familiar with DataFX yet and thus don't know how well it would work in conjunction with jOOQ.

Any insights/hints on that one?

Hmm, I personally don't have much experience with JavaFX / DataFX, but from what I can tell, DataFX doesn't seem to add a lot of functionality between JavaFX and an RDBMS. When I had written our JavaFX example, I hadn't found the direct integration (e.g. by using Java 8 functional programming constructs for the mapping) very difficult:

It would be certainly very interesting in learning more about best integration practices.

Carsten Langsdorf

unread,
Jul 17, 2016, 7:14:42 PM7/17/16
to jooq...@googlegroups.com
Thanks for the link, Lukas, I will check it out in depth and share what I might dig up about integration practices.

Cheers,
Carsten

--
Reply all
Reply to author
Forward
0 new messages