Re: CamelCase form for JavaClassName

177 views
Skip to first unread message

Lukas Eder

unread,
May 14, 2013, 11:54:58 AM5/14/13
to jooq...@googlegroups.com
Hi Sirguy,

This is the expected behaviour of the DefaultGeneratorStrategy. You can override this behaviour by rolling your own strategy as documented here:

This will allow you to keep camel-casing the way it is defined in the database. An example can be found here:

Cheers
Lukas


2013/5/14 Sirguy Chikirev <ad...@chinawindow.ru>
I expected that if my database tables names already in the CamelCase form that I like, generator will preserve this form for the generated class name.
But it is convert names in: first letter in UpperCase and the rest of the name in LowerCase form. This happens even if table name do not have any underscore char.
I think that will be more correctly generate class name as close as possible to the tables name.

The fix is easy. 

in the class org.jooq.tools.StringUtils at static method toCamelCase
check if name does not contains any underscore  and if it is correct java class name use it as is. Else correct and beautify it

smth. like this 

    public static String toCamelCase(String string) {

        StringBuilder result = new StringBuilder();

   

        if(string.indexOf()==-1)

            if(Character.isDigit( string.charAt(0)))

                string="_" +string;

            else

 

                for (String word : string.split("_")) {

 

                    // Uppercase first letter of a word

                    if (word.length() > 0) {

 

                        // [#82] - If a word starts with a digit, prevail the

                        // underscore to prevent naming clashes

                        if (Character.isDigit(word.charAt(0))) {

                            result.append("_");

                        }

 

                        result.append(word.substring(0, 1).toUpperCase());

                        result.append(word.substring(1).toLowerCase());

                    }

 

 

With best regards ! Sirguy.


--
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 jooq-user+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Sirguy Chikirev

unread,
May 14, 2013, 12:16:32 PM5/14/13
to jooq...@googlegroups.com
Let me correct my code.

    /**

     * Convert a string to camel case

     */

    public static String toCamelCase(String string)

    {

        StringBuilder result = new StringBuilder();

 

        if (string.indexOf('_') == -1)

            return  Character.isDigit(string.charAt(0)) ? "_" + string : string;

        else

            for (String word : string.split("_"))

            {

 

                // Uppercase first letter of a word

                if (word.length() > 0)

                {

 

                    // [#82] - If a word starts with a digit, prevail the

                    // underscore to prevent naming clashes

                    if (Character.isDigit(word.charAt(0)))

                    {

                        result.append("_");

                    }

 

                    result.append(word.substring(0, 1).toUpperCase());

                    result.append(word.substring(1).toLowerCase());

                }

 

Thanks
Reply all
Reply to author
Forward
0 new messages