What is jOOQ?
jOOQ, which stands for "jOOQ Object Oriented Querying," is an ORM (object-relational mapping) for Java. With jOOQ you don't write statements with "SQL-like language"; like Hibernate's HQL. Instead, you write well designed and intuitive DSL code which, for someone speaking SQL, is obvious and self-explanatory. Read more »
Some time ago I announced that the integration of Vertabelo and jOOQ was coming soon. While we're waiting for an official (stable) jOOQ release to support this integration, I'd like to present you with some of the details about how to use this new feature.
How It Used to Be
In my first experiments with jOOQ I used reverse-engineering to generate ORM classes. I had to create a database and then configure it in a codegen XML file like this:
org.postgresql.Driver jdbc:postgresql://localhost:5432/modelers mkolodziejski my_secret_password org.jooq.util.DefaultGenerator org.jooq.util.postgres.PostgresDatabase[...]
This is a standard procedure in jOOQ setup, described in step 3 of the "Getting started" tutorial.
How It Can Be Done Now
As I described in the previous post, you can now choose from two more sources of information to obtain the database structure: a Vertabelo XML file stored locally or data that jOOQ downloads directly from Vertabelo.
Local Vertabelo XML File
In this first scenario, you model your DB structure in Vertabelo, export it as a Vertabelo XML file and use it with jOOQ. The only change you have to make for this import to work is to modify the codegen configuration file. It looks like this:
org.jooq.util.DefaultGenerator org.jooq.util.vertabelo.VertabeloXMLDatabase [...] dialect POSTGRES xml-file database_modelers.xml
section is now obsolete – we don't need to connect to the existing database. Since you don't use a DBMS-specific implementation of the generator, you must explicitly provide the proper dialect. You can find the list of dialects supported by jOOQ here. In my case it's "POSTGRES."
Download Directly From the Cloud
If you run the code generator only after making some changes to the DB structure (as opposed to using the "regenerate with every build" strategy) and you don't want to store the XML locally (or in the repository), you can let jOOQ take care of downloading the XML from Vertabelo. You only have to worry about making changes in Vertabelo and running the code generator – it's as simple as that! The only setup effort you have to do is, once again, change a standard jOOQ codegen XML file:
org.jooq.util.DefaultGenerator org.jooq.util.vertabelo.VertabeloAPIDatabase [...] dialect POSTGRES api-token your_secret_api_token model-id your_model_identifier
As you can see, you must provide the Vertabelo API token, model identifier and, as in the previous case, the dialect.