Regarding Code Generation In Jooq.

38 views
Skip to first unread message

Anto Aravinth

unread,
Apr 5, 2017, 12:18:09 PM4/5/17
to jOOQ User Group
Hi, 

I'm getting started with Jooq and I did code generation for my database (Postgres). I have 4 tables in my database and I expected only 4 classes after code generation. However I got many classes for which I need clarification:

1. DefaultCatalog, Keys, Public, Sequences, Tables classes are been generated -- Guess these are tables of postgres itself, which I might not required. Kindly let me know. 
2. I could able to see a new package called record, which has 4 classes of my table name with suffix "Record". -- Again are these classes are useful or even required in my codebase? Whats its usecase?

And also in the code level, I did:

DSLContext create = DSL.using(connection, SQLDialect.POSTGRES);

There were SQLDialect for specific POSTGRES version like 9.4 etc, but what version does SQLDIalect.POSTGRES refers?

` Anto.


Alex

unread,
Apr 5, 2017, 5:08:53 PM4/5/17
to jOOQ User Group
To bridge the time until someone gives a more comprehensive answer, you can read about the Active Record Pattern. This should shed some light on the purpose of the "Record" classes. :-)

Samir Faci

unread,
Apr 5, 2017, 10:47:10 PM4/5/17
to jooq...@googlegroups.com
Records are classes used to do SQL operation.  They're basically helpers where you can construct an object then invoke.

record.store();
record.update();
record.insert() ;  
record.refresh(); 


depending on your use case.

Public is a default schema that every postgres DB has.  You can specify which schema to auto-generate code for.  By default any new table goes in public.

If you don't want to use records you can just easily use the Tables and other classes to write the SQL manually.

dslContext.insertInto(table, field1, field2).values('hello', 'world').execute();

You could also create a white list of what gets generated to only include the tables you're interested in. 

If you want to be minimalistic, then you should make tell jooq what to introspect otherwise it'll by default look at everything in the public catalog and public schema if I'm not mistaken.

public and pg_catalog are usually the default schemas. 


specifically the <include> </include> tag.





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



--
Thank you
Samir Faci

Anto Aravinth

unread,
Apr 6, 2017, 1:29:39 AM4/6/17
to jooq...@googlegroups.com
Thanks all for the replies, now it make sense. 

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

Lukas Eder

unread,
Apr 6, 2017, 5:21:51 AM4/6/17
to jooq...@googlegroups.com
Just completing Samir's excellent answer here:

There's the possibility to turn off most of the generation of the classes you've seen. Samir's link also describes how to turn on/off the various artefacts. If in doubt, just leave them there - they won't really bother you (and prove useful occasionally), e.g. if you don't have any Keys, you cannot profit from:

- UpdatableRecords, as Key information is required for those
- Meta data navigation, in case you ever need this

Here's again the link:

Some more comments inline

2017-04-05 18:18 GMT+02:00 Anto Aravinth <anto.ara...@gmail.com>:
1. DefaultCatalog,

DefaultCatalog is there in all databases that do not support any explicit catalog (currently all but SQL Server). But you don't need to worry about this
  
Sequences, Tables

These are helpful utilities, e.g. you can static import Tables.* to have all table references available to your DAO logic. That's quite useful.
 
There were SQLDialect for specific POSTGRES version like 9.4 etc, but what version does SQLDIalect.POSTGRES refers?

If a SQLDialect family (e.g. POSTGRES) has different versioned dialects (e.g. POSTGRES_9_4), then the family will always be equivalent to the *latest* version available from jOOQ. This is mostly irrelevant as there are few differences in the jOOQ implementation that depend on the dialect version (with the exception of Oracle and SQL Server's OFFSET .. LIMIT support), mostly these versions are useful to document API

If you want to stay on the safe side, you can simply use the latest available version that is less or equal to your server version.

Hope this helps,
Lukas

Anto Aravinth

unread,
Apr 6, 2017, 9:17:25 AM4/6/17
to jooq...@googlegroups.com
Thanks a lot Luke and others. 

Really started to like the library. 

--
Reply all
Reply to author
Forward
0 new messages