Possible glitch with code generation for H2

12 views
Skip to first unread message

Carsten Langsdorf

unread,
Jul 14, 2016, 7:45:27 AM7/14/16
to jOOQ User Group
Hi everybody,

I just joined, and although I don't know if I can contribute more than the occasional silly question, I will try ;)

(yeah I know, there is no try, only do or not do ;)

So here's my current question:

I'm working on a program that uses H2, and I use Intellij IDEA. The database design is pretty stable for now, and I want to use jOOQ's code generation to generate classes right into my IDEA project. I have managed so far, although I'm fairly new to jOOQ. There is one funny thing though. My H2 database uses multiple schemas, and oddly enough the PUBLIC schema comes up as 

public_

after code generation. i.e. as package/directory in IDEA as well as part of the package declaration in the generated classes.

Although it doesn't seem to be a major issue, it's bothering. I already tried to get around it by using a <schema> section in the XML file that I use for generation:

<schema>
 
<inputSchema>PUBLIC</inputSchema>
 
<outputSchema>public</outputSchema>
 
<outputSchemaToDefault>false</outputSchemaToDefault>
</schema>

Oddly enough, the schema isn't even recognised/processed if I don't specify it in caps as input schema.

However, even the code above causes the PUBLIC schema to appear as 

public_

after generation.

Things that make you go 'hmmmm'.

Any ideas, anyone?

Carsten Langsdorf

unread,
Jul 14, 2016, 7:47:18 AM7/14/16
to jOOQ User Group
P.S.: I'm using jOOQ 3.8.3.

Lukas Eder

unread,
Jul 14, 2016, 8:51:17 AM7/14/16
to jooq...@googlegroups.com
Hi Carsten,

That's not a glitch :) Think about it: What would happen if jOOQ generated "public" as a package name? The same thing would happen, by the way, if you had a schema called "if" or "for" or "switch" or "break" or "class"...

jOOQ escapes all sorts of naming collisions, keywords, and other things that are not allowed in the Java language by appending an underscore. If you want fine-grained control over these things (e.g. to name the package PUBLIC (with upper case letters)), you can use a generator strategy:


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.

Carsten Langsdorf

unread,
Jul 14, 2016, 9:32:57 AM7/14/16
to jOOQ User Group
Hallo Lukas ;)

Of course. *facepalm*. 

Makes sense. Sorry for the silly question, my Java has gotten a bit rusty.

Thanks for the quick reply and for the pointers to generator strategies - I'm already digging into those, and I'm confident this will get me somewhere. I think the solution you chose is quite good in that case, but I got more naming issues to resolve.

And btw: Lots of kudos, grats and thanks for jOOQ so far. I'm an old SQL veteran, not exactly a fan of the NoSQL movement (*cough*), and although I can remember all the issues from days even long before Java, I always liked SQL. jOOQ is just what I needed to make it work better with Java than plain JDBC.

Carsten

Lukas Eder

unread,
Jul 14, 2016, 9:36:57 AM7/14/16
to jooq...@googlegroups.com
No worries, it does look weird when you first see it :)

Thanks for your nice words, I wish you a lot of success!
If you encounter any additional issues, just ask. I'll be very happy to reply here

Cheers
Lukas
Reply all
Reply to author
Forward
0 new messages