Hi,

The current names produced by the generator are conformant with Java
standards but are not very readable in a fluent API.
e.g. for a table "T_DbSRBatchSetBO" with a column "T_DbSRBatch_ID" we
get by default:
TDbsrbatchsetbo.java (static instance T_DBSRBATCHSETBO) with a field
"T_DBSRBATCH_ID".
with a few tweaks, I get this:
T_DbSRBatchSetBO.java (static instance T_DbSRBatchSetBO) with a field
"T_DbSRBatch_ID".

This is much better from a users point of view, especially because
some names are very hard to read if all caps due to the importance of
certain specific capitalisations.

Here is what I have done to get the desired capitalisation, using my
SQLServer flavor (as I said, we generated both Oracle and SQLServer
versions and allow the user to chose his RDBMS):

I added to the properties file:
generator.strategy=chrriis.ph.jooq.CodeGeneratorStrategy

And in the "CodeGeneratorStrategy" class:
public String getJavaIdentifierUC(Definition definition) {
    String javaIdentifier = super.getJavaIdentifier(definition); //
Note: not UC
    // We declared names starting with LC. For now, fix that in
generator, later in our DB creation scripts.
    return Character.toUpperCase(javaIdentifier.charAt(0)) +
javaIdentifier.substring(1);
}
public String getJavaClassName(Definition definition, String suffix) {
    StringBuilder result = new StringBuilder();
    result.append(definition.getName());
    if (!StringUtils.isEmpty(suffix)) {
        result.append(suffix);
    }
    return result.toString();
}

I have a problem though and I would not want to write my own generator
(easier to follow upgrades) if there is a solution: with the above
changes, routines do not compile. The problem is that
getJavaIdentifier(x) is called to create the field, but the usage of
the parameters hardcodes "parameter.getName().toUpperCase()" in the
generator.

Here is a sample:

public static final org.jooq.Parameter<java.lang.Long> ObjID =
createParameter("objID", org.jooq.impl.SQLDataType.BIGINT);
public spGetObjectID() {
    super(org.jooq.SQLDialect.SQLSERVER, "spGetObjectID",
test.generated.dbo.Dbo);
    addInOutParameter(OBJID); // Does not compile
}

1. Would it be possible to fix the routines generation to use the same
code to produce names?
2. Much lower priority if 1. is fixed: would it be possible to have a
global name strategy switch to favor all caps or untouched names?

Cheers,
-Christopher

Reply via email to