Just as a teaser, here is the configuration of the new code generator. I'm 
not a big fan of XML-based configurations, I prefer DSLs but the API is 
public, so writing an XML front-end for the config is just an issue of 
someone wanting to scratch this itch.

Here is the config:

        BluNamingStrategy namingStrategy = new BluNamingStrategy();
        namingStrategy
        .renameColumn( "BLU.ADM_LANGUAGE.ISO_CODE", "locale" )
        .renameColumn( "BLU.GBL_LOCALISED_TEXT.ISO_CODE", "locale" )
        .renameBooleanColumn( "BLU.ADM_LANGUAGE.IS_DEFAULT", "default" )
        ;

        generator.config()
        .dataSource( dataSource )
        .dialect( SQLDialect.H2 )
        .packageName( "com.avanon.blu.jooq.gen" )
        .rootFolder( new File( "tmp/gen2" ) )
        .schema( "PUBLIC", "BLU" )
        .includeAll()
        .namingStrategy( namingStrategy )
        .factory( new BluGeneratorFactory( generator.config() ) )
        .typeMapping( DateTime.class, DateTimeConverter.class )
            .columnPatterns(
                new ColumnPattern( "(VALID_FROM|VALID_TO)" ),
                new ColumnPattern( "ADM_USER", 
"(PASSWORD_EXPIRES|LAST_LOGIN|FIRST_FAILED_LOGIN|LAST_MODIFIED_DATE|DEACTIVATED_DATE)"
 
),
                new ColumnPattern( "GBL_LOCK", "LAST_UPDATE" )
            )
        .typeMapping( Boolean.class, BooleanConverter.class )
            .columnPatterns(
                new ColumnPattern( "ADM_LANGUAGE", "IS_DEFAULT" ),
                new ColumnPattern( "ADM_USER", "ACCOUNT_LOCKED" ),
                new ColumnPattern( "ADM_USER", "MANDATORY_NOTIFS_DISABLED" 
),
                new ColumnPattern( "ADM_ORG_UNIT_REV", "IS_PROFIT_CENTER" )
            )
        .typeMapping( Locale.class, LocaleConverter.class )
            .columnPatterns(
                new ColumnPattern( "GBL_LOCALISED_TEXT", "ISO_CODE" ),
                new ColumnPattern( "ADM_LANGUAGE", "ISO_CODE" )
            )
        ;

* The naming strategy has support for renaming columns in Java code. So the 
column ISO_CODE will be mapped to setLocale()/getLocale() while IS_DEFAULT 
will be setDefault()/isDefault()
* The PUBLIC schema is renamed to BLU
* I include all tables of the schema
* Three custom types are defined which map columns to joda-time's DateTime, 
Boolean and java.util.Locale. Each type gets a list of column patterns 
where to apply it.
* I'm using my own Generator factory because I need custom code in my 
POJOs, Records and interfaces.

Config is the most complex step; the rest of the code is two lines (create 
the JavaGenerator and start it).

Regards,

A. Digulla

Reply via email to