Created
August 31, 2016 16:13
-
-
Save agentgt/221f76b5d3ed49272ef467c0e2143069 to your computer and use it in GitHub Desktop.
A Jooq generator that puts POJO in a public package and records in a private package
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.snaphop.jooq; | |
import org.jooq.util.DefaultGeneratorStrategy; | |
import org.jooq.util.Definition; | |
public class CustomJooqGeneratorStrategy extends DefaultGeneratorStrategy { | |
@Override | |
public String getJavaClassName(Definition definition, Mode mode) { | |
/* | |
* Adds suffix of "Table" for table things. | |
* Otherwise there is annoying conflict with the POJOs. | |
*/ | |
if (mode == Mode.DEFAULT || mode == null) { | |
return super.getJavaClassName(definition, mode) + "Table"; | |
} | |
return super.getJavaClassName(definition, mode); | |
} | |
@Override | |
public String getJavaPackageName(Definition definition, Mode mode) { | |
/* | |
* This is to hide jooq things by adding an "internal" package | |
*/ | |
if (mode == Mode.POJO || mode == Mode.INTERFACE) { | |
StringBuilder sb = new StringBuilder(); | |
return sb.append(getTargetPackage()).append(".data").toString(); | |
} | |
else { | |
String packageName = super.getJavaPackageName(definition, mode); | |
String target = getTargetPackage(); | |
if (packageName.startsWith(target)) { | |
String suffix = packageName.substring(target.length()); | |
return target + ".internal" + suffix; | |
} | |
return packageName; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment