Created
January 27, 2013 17:26
-
-
Save witoldsz/4649307 to your computer and use it in GitHub Desktop.
JOOQ Converter for Oracle to support boolean types in generated sources.
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
<!-- [...] --> | |
<plugin> | |
<groupId>org.jooq</groupId> | |
<artifactId>jooq-codegen-maven</artifactId> | |
<version>2.6.0</version> | |
<executions> | |
<execution> | |
<!-- INFO: set phase to process _RE_sources to make it happen AFTER Liquibase! --> | |
<phase>process-resources</phase> | |
<goals> | |
<goal>generate</goal> | |
</goals> | |
</execution> | |
</executions> | |
<dependencies> | |
<dependency> | |
<groupId>com.h2database</groupId> | |
<artifactId>h2</artifactId> | |
<version>1.3.168</version> | |
</dependency> | |
<dependency> | |
<groupId>com.oracle</groupId> | |
<artifactId>ojdbc6</artifactId> | |
<version>11.2.0.2.0</version> | |
</dependency> | |
<dependency> | |
<groupId>pl.espeo.sgn</groupId> | |
<artifactId>sgn-db-customizations</artifactId> | |
<version>1.0-SNAPSHOT</version> | |
</dependency> | |
</dependencies> | |
<configuration> | |
<jdbc> | |
<driver>${sgn.db.driver}</driver> | |
<url>${sgn.db.url}</url> | |
<user>${sgn.db.user}</user> | |
<password>${sgn.db.pass}</password> | |
</jdbc> | |
<generator> | |
<name>pl.espeo.sgn.jooq.SgnGenerator</name> | |
<database> | |
<name>${sgn.jooq.generator.dialect}</name> | |
<includes>.*</includes> | |
<excludes></excludes> | |
<inputSchema>${sgn.db.schema}</inputSchema> | |
<customTypes> | |
<customType> | |
<name>java.lang.Boolean</name> | |
<converter>pl.espeo.sgn.jooq.OracleBooleanConverter</converter> | |
</customType> | |
</customTypes> | |
<forcedTypes> | |
<forcedType> | |
<name>java.lang.Boolean</name> | |
<expressions>.*\.((ESTATE\.DEVELOPED)|(FOLDER\.BID))</expressions> | |
</forcedType> | |
</forcedTypes> | |
</database> | |
<target> | |
<packageName>pl.espeo.sgn.coredb.jooq</packageName> | |
<directory>${project.basedir}/target/generated-sources/jooq</directory> | |
</target> | |
</generator> | |
</configuration> | |
</plugin> | |
<!-- [...] --> |
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 pl.espeo.sgn.jooq; | |
import org.jooq.Converter; | |
/** | |
* | |
* @author Witold Szczerba | |
*/ | |
public class OracleBooleanConverter implements Converter<Byte, Boolean> { | |
@Override | |
public Boolean from(Byte databaseObject) { | |
return databaseObject == null ? null : databaseObject == (byte)1; | |
} | |
@Override | |
public Byte to(Boolean userObject) { | |
return userObject == null ? null : userObject ? (byte)1 : (byte)0; | |
} | |
@Override | |
public Class<Byte> fromType() { | |
return Byte.class; | |
} | |
@Override | |
public Class<Boolean> toType() { | |
return Boolean.class; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For JOOQ 3.11 we could use
Reference
<forcedTypes> <forcedType> <name>BOOLEAN</name> <expression>.*\.ENABLED</expression> </forcedType> </forcedTypes>