Skip to content

Commit

Permalink
Java/jOOQ: Add jOOQ code generation add-on for Gradle
Browse files Browse the repository at this point in the history
  • Loading branch information
amotl committed Jan 20, 2023
1 parent eb951b9 commit 091a65b
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 5 deletions.
9 changes: 4 additions & 5 deletions by-language/java-jooq/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ builder without code generation`_.
Caveats
=======

- `jOOQ's code generator`_ takes your database schema and reverse-engineers it
into a set of Java classes. This feature currently does not work with CrateDB
yet. The code provided within the ``src/generated`` directory has not been
derived by reflecting the database schema from CrateDB.

- Most of the jOOQ examples use uppercase letters for the database, table, and
field names. CrateDB currently only handles lowercase letters.

Expand All @@ -73,6 +68,10 @@ Usage

./gradlew test

4. Generate the jOOQ sources from the main jOOQ configuration, see ``jooq.gradle``::

./gradlew generateJooq


.. _CrateDB: https://github.com/crate/crate
.. _Different use cases for jOOQ: https://www.jooq.org/doc/latest/manual/getting-started/use-cases/
Expand Down
3 changes: 3 additions & 0 deletions by-language/java-jooq/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ test {
dependsOn 'cleanTest'
}

// Activate jOOQ code generation add-on.
apply from: 'jooq.gradle'

idea.module.inheritOutputDirs = true
processResources.destinationDir = compileJava.destinationDir
compileJava.dependsOn processResources
89 changes: 89 additions & 0 deletions by-language/java-jooq/jooq.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/**
* About
* =====
*
* Configure `gradle-jooq-plugin`, a Gradle plugin that integrates the jOOQ
* code generation tool. This layout manages the jOOQ configuration within
* a separate script file.
*
* Synopsis
* ========
*
* ./gradlew generateJooq
*
* Resources
* =========
*
* - https://github.com/etiennestuder/gradle-jooq-plugin#gradle-groovy-dsl-4
* - https://github.com/etiennestuder/gradle-jooq-plugin/tree/main/example/extract_script_file
* - https://github.com/etiennestuder/gradle-jooq-plugin#examples
*/

buildscript {
repositories {
gradlePluginPortal()
}
dependencies {
classpath 'nu.studer:gradle-jooq-plugin:8.1'
}
}

repositories {
mavenCentral()
}

apply plugin: nu.studer.gradle.jooq.JooqPlugin

dependencies {
jooqGenerator 'org.postgresql:postgresql:42.5.1'
}

jooq {

// Defaults (can be omitted).
// version = '3.17.6'
// edition = nu.studer.gradle.jooq.JooqEdition.OSS

configurations {
// Name of the jOOQ configuration.
main {

// Do not *automatically* generate code.
generateSchemaSourceOnCompilation = false

generationTool {
logging = org.jooq.meta.jaxb.Logging.WARN
jdbc {
driver = 'org.postgresql.Driver'
url = 'jdbc:postgresql://localhost:5432/testdrive'
user = 'crate'
password = ''
properties {
property {
key = 'PAGE_SIZE'
value = 2048
}
}
}
generator {
name = 'org.jooq.codegen.DefaultGenerator'
database {
name = 'org.jooq.meta.postgres.PostgresDatabase'
inputSchema = 'testdrive'
}
generate {
deprecated = false
records = false
immutablePojos = false
fluentSetters = false
}
target {
packageName = 'io.crate.demo.jooq.model'
directory = 'src/generated/java'
}
strategy.name = "org.jooq.codegen.DefaultGeneratorStrategy"
}
}
}
}
}

0 comments on commit 091a65b

Please sign in to comment.