jOOQ generates Java code from your database and lets you build type safe SQL queries through its fluent API.
Configuring the module for your application is quite easy. There is a demo application that shows you how to do it. Check out subproject ninja-jooq-demo/pom.xml for further information.
More about jOOQ: http://www.jooq.org
-
ninja-jooq will read the database info from your application.conf. Optionally, you can configure the following settings.
jooq.renderSchema
-(true|false)
, default: truejooq.renderNameStyle
-("QUOTED"|"AS_IS"|"LOWER"|"UPPER")
, default "QUOTED"jooq.renderKeywordStyle
-("LOWER"|"UPPER")
, default "LOWER"jooq.renderFormatted
-(true|false)
, default falsejooq.statementType
-("STATIC_STATEMENT"|"PREPARED_STATEMENT")
, default "PREPARED_STATEMENT"jooq.executeLogging
-(true|false)
, default truejooq.executeWithOptimisticLocking
-(true|false)
, default truejooq.attachRecords
-(true|false)
, default truejooq.sqlDialect
- one of the values of SQLDialect, default "DEFAULT"
-
Add the ninja-jooq dependency to your pom.xml:
org.ninjaframework ninja-jooq-module 0.0.1 -
Add the jOOQ generator plugin to your pom.xml:
<plugin>
<!-- Specify the maven code generator plugin -->
<groupId>org.jooq</groupId>
<artifactId>jooq-codegen-maven</artifactId>
<version>3.7.2</version>
<!-- The plugin should hook into the generate goal -->
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<!-- Manage the plugin's dependency. In this example, we'll use a H2 database -->
<dependencies>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.190</version>
</dependency>
<dependency>
<groupId>org.ninjaframework</groupId>
<artifactId>ninja-jooq-module</artifactId>
<version>0.0.1</version>
</dependency>
</dependencies>
<!-- Specify the plugin configuration.
The configuration format is the same as for the standalone code generator -->
<configuration>
<!-- JDBC connection parameters -->
<jdbc>
<url>${db.url}</url>
<user>${db.username}</user>
</jdbc>
<!-- Generator parameters -->
<generator>
<database>
<includes>.*</includes>
<inputSchema>FLYWAY_TEST</inputSchema>
</database>
<target>
<packageName>models</packageName>
<directory>target/generated-sources/jooq</directory>
</target>
</generator>
</configuration>
</plugin>
-
Install the module in your conf.Module:
protected void configure() { // This installs the NinjaModule and handles the lifecycle install(new NinjaJooqModule()); }
And that's it already :)