Skip to content

Instantly share code, notes, and snippets.

@danhyun
Created December 3, 2015 17:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danhyun/683caf30146910d81d64 to your computer and use it in GitHub Desktop.
Save danhyun/683caf30146910d81d64 to your computer and use it in GitHub Desktop.
jOOQ code gen from properties
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.postgresql:postgresql:9.4-1206-jdbc42'
classpath 'org.jooq:jooq-codegen:3.7.1'
classpath 'org.jyaml:jyaml:1.3'
}
}
import org.jooq.util.jaxb.*
import org.jooq.util.*
import org.ho.yaml.Yaml
task jooqCodegen {
doLast {
def config = Yaml.load(file('src/ratpack/db.yaml')).db
def dsProps = config.dataSourceProperties
Configuration configuration = new Configuration()
.withJdbc(new Jdbc()
.withDriver("org.postgresql.Driver")
.withUrl("jdbc:postgresql://$dsProps.serverName:$dsProps.portNumber/$dsProps.databaseName")
.withUser(config.username)
.withPassword(config.password))
.withGenerator(new Generator()
.withDatabase(new Database()
.withName("org.jooq.util.postgres.PostgresDatabase")
.withIncludes(".*")
.withExcludes("")
.withInputSchema("public"))
.withTarget(new Target()
.withPackageName("jooq")
.withDirectory("src/main/java")))
GenerationTool.generate(configuration)
}
}
db:
dataSourceClassName: org.postgresql.ds.PGSimpleDataSource
username: postgres
password: password
dataSourceProperties:
databaseName: modern
portNumber: 5432
serverName: 192.168.99.101
@youchen
Copy link

youchen commented Jan 8, 2016

Hey, Dan.

If we

import org.jooq.util.jaxb.*
import org.jooq.util.*

We'll get warning

Cannot initiate 'Generator'
Cannot initiate 'Database'

To get rid of that, simply

import org.jooq.util.GenerationTool
import org.jooq.util.jaxb.*

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment