2

I'm trying to use jooq to load configurations automatically from gradle but had a hard time following the guide.

I finally have it loading data, but so far I can only get all databases to work (by having the database() chunk be blank).

My code below has my attempt to load only one database.

buildscript {

   repositories {
     mavenCentral()
     maven {
       name 'JFrog OSS snapshot repo'
       url  'https://oss.jfrog.org/oss-snapshot-local/'
     }
     jcenter()
   }

   dependencies {
       classpath 'org.jooq:jooq-codegen:3.9.1'
       classpath group: 'mysql', name: 'mysql-connector-java', version: '6.0.6'
   }
}

apply plugin: 'application'
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'antlr'

repositories {
    mavenLocal()
    mavenCentral()
    jcenter()
}

dependencies {
    //compile group: 'com.github.javaparser', name: 'javaparser-core', version: '3.0.0-alpha.2'
    compile group: 'com.github.javaparser', name: 'java-symbol-solver-core', version: '0.5.2'
    compile 'org.jooq:jooq:3.9.1'
    runtime group: 'mysql', name: 'mysql-connector-java', version: '6.0.6'
    testCompile "junit:junit:latest.release"
}

idea {
    module {
        excludeDirs += file('src/main/resources')
    }
}

// Use your favourite XML builder to construct the code generation configuration file
// ----------------------------------------------------------------------------------
def writer = new StringWriter()
def xml = new groovy.xml.MarkupBuilder(writer)
        .configuration('xmlns': 'http://www.jooq.org/xsd/jooq-codegen-3.9.0.xsd') {
    jdbc() {
        driver('com.mysql.cj.jdbc.Driver')
        url('jdbc:mysql://127.0.0.1/graphUpgrade?serverTimezone=UTC')
        user('parseUser')
        password('password')
    }
    generator() {
        database() {
            name('org.jooq.util.mysql.MySQLDatabase')
            inputSchema('graphUpgrade')
            includes('.*')
        }

        // Watch out for this caveat when using MarkupBuilder with "reserved names"
        // - https://github.com/jOOQ/jOOQ/issues/4797
        // - http://stackoverflow.com/a/11389034/521799
        // - https://groups.google.com/forum/#!topic/jooq-user/wi4S9rRxk4A
        generate([:]) {
            pojos true
            daos true
        }
        target() {
            packageName('us.klingman.codeParser.db')
            directory('src/main/java')
        }
    }
}
print writer.toString()
// Run the code generator
// ----------------------
org.jooq.util.GenerationTool.generate(
        javax.xml.bind.JAXB.unmarshal(new StringReader(writer.toString()), org.jooq.util.jaxb.Configuration.class)
)

Running this code produces the following error:

Error while fetching tables
java.lang.NullPointerException
    at org.jooq.util.AbstractElementContainerDefinition.<init>(AbstractElementContainerDefinition.java:79)
    at org.jooq.util.AbstractElementContainerDefinition.<init>(AbstractElementContainerDefinition.java:75)
    at org.jooq.util.AbstractTableDefinition.<init>(AbstractTableDefinition.java:68)
    at org.jooq.util.mysql.MySQLTableDefinition.<init>(MySQLTableDefinition.java:70)
    at org.jooq.util.mysql.MySQLDatabase.getTables0(MySQLDatabase.java:256)
    at org.jooq.util.AbstractDatabase.getTables(AbstractDatabase.java:1137)
    at org.jooq.util.AbstractDatabase.getTable(AbstractDatabase.java:1163)
    at org.jooq.util.AbstractDatabase.getTable(AbstractDatabase.java:1158)
    at org.jooq.util.mysql.MySQLDatabase.getEnums0(MySQLDatabase.java:295)
    at org.jooq.util.AbstractDatabase.getEnums(AbstractDatabase.java:1182)
    at org.jooq.util.JavaGenerator.generateSchemaIfEmpty(JavaGenerator.java:334)
    at org.jooq.util.JavaGenerator.generateCatalogIfEmpty(JavaGenerator.java:323)
    at org.jooq.util.JavaGenerator.generate(JavaGenerator.java:297)
    at org.jooq.util.GenerationTool.run(GenerationTool.java:610)
    at org.jooq.util.GenerationTool.generate(GenerationTool.java:199)
    at org.jooq.util.GenerationTool$generate.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
    at build_87hklhc6v691dvh83y5ogqnvl.run(/Users/lorenklingman/Sites/code-search-parser/build.gradle:79)
    at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:74)

Finally, for completeness, here are the files generated for all databases.

Screenshot of Generated Files

Loren
  • 9,783
  • 4
  • 39
  • 49

1 Answers1

1

I believe you've run into this problem here: #5213

Be sure to always use the exact upper/lower case writing of your database name also in the jOOQ configuration. Also, there are some caveats with case sensitivity in MySQL and MariaDB, depending on the operating system. These caveats can affect other tools than jOOQ. The relevant info is also in #5213.

Lukas Eder
  • 211,314
  • 129
  • 689
  • 1,509
  • I think I've done that, unless you see somewhere I cased it wrong graphUpgrade is the exact casing. If I use graphupgrade in ``inputSchema`` I get a different error that no schemas match what I've requested. – Loren Mar 25 '17 at 13:57
  • @Loren: I'm sorry, my comment was wrong/incomplete. I've fixed it. Have you tried naming your database in lower case only? – Lukas Eder Mar 25 '17 at 19:08
  • 1
    For future users, it would be nice to add casing directly into the answer. Maybe "Also, there are some caveats with case sensitivity in MySQL and MariaDB, depending on the operating system. These can be avoided by naming the database in all lower case." Also for those who need it, how to rename a database in MySQL/MariaDB http://stackoverflow.com/a/1072988/3854385 – Loren Mar 27 '17 at 15:35