I have developed the following solution: created a new maven project with
class:

[...]
public class SgnGenerator extends DefaultGenerator {

    @Override
    protected String getType(Database db, SchemaDefinition schema, String
t, int p, int s, String u, String defaultType) {
        //NUMBER(4,0)
        if ("NUMBER".equalsIgnoreCase(t) && p == 4 && s == 0) {
            return "java.lang.Integer";
        }
        //NUMBER(19,0)
        if ("NUMBER".equalsIgnoreCase(t) && p == 19 && s == 0) {
            return "java.lang.Long";
        }
        return super.getType(db, schema, t, p, s, u, defaultType);
    }

    @Override
    protected String getTypeReference(Database db, SchemaDefinition schema,
String t, int p, int s, String u) {
        //NUMBER(4,0)
        if ("NUMBER".equalsIgnoreCase(t) && p == 4 && s == 0) {
            return "org.jooq.impl.SQLDataType.INTEGER";
        }
        //NUMBER(19,0)
        if ("NUMBER".equalsIgnoreCase(t) && p == 19 && s == 0) {
            return "org.jooq.impl.SQLDataType.BIGINT";
        }
        return super.getTypeReference(db, schema, t, p, s, u);
    }
}

added that project to plugin dependencies and replaced DefaultGenerator
with the one above in configuration section. The separate project was
required, because the code gen is happening before compilation.

Let me know if there is a better approach :)

Regards,
Witold Szczerba


On 27 January 2013 01:09, Witold Szczerba <[email protected]> wrote:

> Hi,
> Is it possible to instruct JOOQ to use specific database to Java mapping
> by type? In documentation it is explained to specify forced mappings by
> table and column name, not type. For example, I have a NUMBER(4,0) column,
> JOOQ generates java.lang.Short. I would like all NUMBER(4,0) to be mapped
> as java.lang.Integer.
>
> Thanks,
> Witold Szczerba
>
> P.S.
> One extra question: what is the pronunciation of JOOQ?
>
> P.P.S.
> JOOQ is GREAT! I use it together with Liquibase. It is a nice duet :)
>
> --
>
>
>

-- 


Reply via email to