Hello Josh,

Thank you for the reply. Going to a different naming convention for our 
database would be overkill as it was setup Java style names for database 
objects.

I traced the code to check how jooq maps the field names on runtime and it 
seams the problem might be that when I am generating Java objects from the 
database model I am using my own name converted (see attached). May be I 
need to embed my converter on runtime somehow as well. That's all I need.

I am moving from my own ORM implementation to jooq that has happen to have 
similar ideology. Before I was using hibernate and tried to use iBatis.

Igor.


On Monday, September 8, 2014 5:31:00 AM UTC-8, Josh Padnick wrote:
>
> Hi Lukas and Igor,
>
> The filtered post was from me, accidentally posting from a different 
> Google login.  My second time hit by Google spam filters!
>
> Anyway, to add to what Lukas said, we ran into this exact issue with 
> Postgres and jOOQ, and I actually see this is a Postgres limitation, not a 
> jOOQ issue. Basically, Postgres will automatically lower case any 
> identifier name (like a field name or table name) unless it's surrounded by 
> quotes.  See 
> http://stackoverflow.com/questions/20878932/are-postgresql-column-names-case-sensitive.
>  
>  
>
> Having to surround every field name with quotes for the life of your 
> application is needlessly cumbersome.  The solution we took is to just 
> switch to use underscored identifiers. So, your "htmlSummary" would become 
> "html_summary".
>
> Josh
>
> On Monday, September 8, 2014 1:59:12 AM UTC-7, Lukas Eder wrote:
>>
>> Hello,
>>
>> Unfortunately, Google Groups has spam-filtered and eaten a reply by 
>> someone, and I cannot retrieve it. Please, if you sent an e-mail to this 
>> thread, can you re-send it?
>>
>> Thanks,
>> Lukas
>>
>

-- 
You received this message because you are subscribed to the Google Groups "jOOQ 
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.
package org.metalib;

import java.util.Arrays;
import static java.util.Collections.unmodifiableSet;
import java.util.HashSet;
import java.util.Set;
import org.jooq.tools.StringUtils;
import org.jooq.util.ArrayDefinition;
import org.jooq.util.DefaultGeneratorStrategy;
import org.jooq.util.Definition;
import org.jooq.util.EnumDefinition;
import org.jooq.util.GeneratorStrategy;
import org.jooq.util.PackageDefinition;
import org.jooq.util.RoutineDefinition;
import org.jooq.util.TableDefinition;
import org.jooq.util.UDTDefinition;

public class NprbGeneratorStrategy extends DefaultGeneratorStrategy {
    
    public NprbGeneratorStrategy() {
        super();
    }
    
    @Override public String getJavaClassName( Definition definition, GeneratorStrategy.Mode mode) {
        String result = toPropertyNameUC( definition.getName());
        //String result = super.getJavaClassName(definition, mode);
        switch ( mode) {
        case DAO:
            break;
        case ENUM:
            break;
        case INTERFACE:
            break;
        case POJO:
            break;
        case DEFAULT:
            break;
        default:

        }
        return result;
    }

    @Override public String getJavaIdentifier(Definition definition) {
        String result = toPropertyName( definition.getName());
        return result;
        //return super.getJavaIdentifier(definition);
    }

    @Override public String getJavaPackageName(Definition definition, GeneratorStrategy.Mode mode) {
        //return super.getJavaPackageName( definition, mode);
        StringBuilder sb = new StringBuilder();

        sb.append(getTargetPackage());

        // [#282] In multi-schema setups, the schema name goes into the package
        if (definition.getDatabase().getSchemata().size() > 1) {
            sb.append(".");
            sb.append( toPropertyName( definition.getSchema().getOutputName()));
        }

        switch ( mode) {
        case RECORD:
            sb.append(".tuples");
            break;
        case DAO:
            sb.append(".daos");
            break;
        case ENUM:
        case INTERFACE:
            sb.append(".ifaces");
            break;
        case POJO:
            sb.append(".pojos");
            break;
        case DEFAULT:
        default:
            // Some definitions have their dedicated subpackages, e.g. "tables", "routines"
            if (!StringUtils.isBlank(getSubPackage(definition))) {
                sb.append(".");
                sb.append(getSubPackage(definition));
            }

        }
        return sb.toString();
    }

    private final String getSubPackage(Definition definition) {
        if (definition instanceof TableDefinition) {
            return "tables";
        }

        // [#799] UDT's are also packages
        else if (definition instanceof UDTDefinition) {
            return "udt";
        }
        else if (definition instanceof PackageDefinition) {
            return "packages";
        }
        else if (definition instanceof RoutineDefinition) {
            RoutineDefinition routine = (RoutineDefinition) definition;

            if (routine.getPackage() instanceof UDTDefinition) {
                return "udt." + getJavaIdentifier(routine.getPackage()).toLowerCase();
            }
            else if (routine.getPackage() != null) {
                return "packages." + getJavaIdentifier(routine.getPackage()).toLowerCase();
            }
            else {
                return "routines";
            }
        }
        else if (definition instanceof EnumDefinition) {
            return "enums";
        }
        else if (definition instanceof ArrayDefinition) {
            return "udt";
        }

        // Default always to the main package
        return "";
    }

    @Override public String getJavaGetterName(Definition definition, GeneratorStrategy.Mode mode) {
        return "get" + toPropertyNameUC( definition.getName());
    }

    @Override public String getJavaMemberName(Definition definition, GeneratorStrategy.Mode mode) {
        return toPropertyName( definition.getName());
        //return super.getJavaMemberName(definition, mode);
    }

    @Override public String getJavaMethodName(Definition definition, GeneratorStrategy.Mode mode) {
        return toPropertyName( definition.getName());
        //return super.getJavaMethodName(definition, mode);
    }

    @Override public String getJavaSetterName(Definition definition, GeneratorStrategy.Mode mode) {
        return "set" + toPropertyNameUC( definition.getName());
    }
    
    static public String toPropertyNameUC( String name) {
        String result = toPropertyName( name);
        return result.substring(0, 1).toUpperCase() + result.substring(1);
        
    }
    
    static public String toPropertyName( String name) {
        // Basically let's eat all separators and capitalize a letter after.
        boolean separatorMarker = false;
        StringBuilder result = new StringBuilder();
        int count = 0;
        for ( char ch: name.toCharArray()) {
            if ( Character.isDigit(ch)) {
                if ( 0 == count)
                   result.append('_');
                result.append(ch);
            } else if ( Character.isLetter(ch)) {
                if ( 0 == count)
                    ch = Character.toLowerCase(ch);
                else if ( separatorMarker) {
                    ch = Character.toUpperCase(ch);
                    separatorMarker = false;
                }
                result.append(ch);
            } else 
                separatorMarker = true;
            count++;
        }
        if ( JAVA_KEYWORDS.contains( result)) {
            result.insert(0, "_");
        }
        return result.toString();
    }
    
    private static final Set<String> JAVA_KEYWORDS = unmodifiableSet(new HashSet<String>( Arrays.asList( new String[]
    { "abstract"
    , "assert"
    , "boolean"
    , "break"
    , "byte"
    , "case"
    , "catch"
    , "char"
    , "class"
    , "const"
    , "continue"
    , "default"
    , "double"
    , "do"
    , "else"
    , "enum"
    , "extends"
    , "false"
    , "final"
    , "finally"
    , "float"
    , "for"
    , "goto"
    , "if"
    , "implements"
    , "import"
    , "instanceof"
    , "interface"
    , "int"
    , "long"
    , "native"
    , "new"
    , "package"
    , "private"
    , "protected"
    , "public"
    , "return"
    , "short"
    , "static"
    , "strictfp"
    , "super"
    , "switch"
    , "synchronized"
    , "this"
    , "throw"
    , "throws"
    , "transient"
    , "true"
    , "try"
    , "void"
    , "volatile"
    , "while"
    })));
    
}

Reply via email to