You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Francois LE ROLLAND <f....@ortems.com> on 2007/01/23 15:33:42 UTC

Abator tool extension

Hi,

 

            I'm wondering if it could be possible to add the column names as constant in the generated Java Model. I've tried something like that 

In the class JavaModelGeneratorJava2Impl and it works fine for me :

 

        // FLD

        Field constant;

        Method method;

 

        while (columnDefinitions.hasNext()) {

            ColumnDefinition cd = (ColumnDefinition) columnDefinitions.next();

            FullyQualifiedJavaType fqjt = cd.getResolvedJavaType()

                    .getFullyQualifiedJavaType();

 

            topLevelClass.addImportedType(fqjt);

 

            String property = cd.getJavaProperty();

 

            field = new Field();

            field.addComment(table, cd.getColumnName());

            field.setVisibility(JavaVisibility.PRIVATE);

            field.setType(fqjt);

            field.setName(property);

            topLevelClass.addField(field);

            

            // FLD - begin

            constant = new Field();

            constant.addComment(table, cd.getColumnName());

            constant.setVisibility(JavaVisibility.PUBLIC);

            constant.setModifierFinal(true);

            constant.setModifierStatic(true);

            constant.setType(FullyQualifiedJavaType.getStringInstance());

            constant.setName(cd.getColumnName());

            constant.setInitializationString("\""+property+"\"");

            topLevelClass.addField(constant);            

            // FLD - end

            ...

 

This is very usefull when you handle the domain classes from within binding solutions like "JGoodies bindings" to reference bean properties.

 

Thanks

 

François Le Rolland

 

 


Re: Abator tool extension

Posted by Jeff Butler <je...@gmail.com>.
Hi Francois,

This seems like something that is pretty specific to your needs.  I think
the best way to handle this would be to write a "hook" into Abator to do
this.

The version of Abator in SVN includes new methods on all generators that
allow you to add to the generated classes.  For example, the
JavaModelGeneratorJava2Impl class has methods like
afterBaseRecordGenerationHook(...) that would let you accomplish this.  Will
this work for you?

Jeff Butler



On 1/23/07, Francois LE ROLLAND <f....@ortems.com> wrote:
>
>  Hi,
>
>
>
>             I'm wondering if it could be possible to add the column names
> as constant in the generated Java Model. I've tried something like that
>
> In the class *JavaModelGeneratorJava2Impl *and it works fine for me :
>
>
>
>         // FLD
>
>         Field constant;
>
>         Method method;
>
>
>
>         *while* (columnDefinitions.hasNext()) {
>
>             ColumnDefinition cd = (ColumnDefinition)
> columnDefinitions.next();
>
>             FullyQualifiedJavaType fqjt = cd.getResolvedJavaType()
>
>                     .getFullyQualifiedJavaType();
>
>
>
>             topLevelClass.addImportedType(fqjt);
>
>
>
>             String property = cd.getJavaProperty();
>
>
>
>             field = *new* Field();
>
>             field.addComment(table, cd.getColumnName());
>
>             field.setVisibility(JavaVisibility.*PRIVATE*);
>
>             field.setType(fqjt);
>
>             field.setName(property);
>
>             topLevelClass.addField(field);
>
>
>
>             // FLD - begin
>
>             constant = *new* Field();
>
>             constant.addComment(table, cd.getColumnName());
>
>             constant.setVisibility(JavaVisibility.*PUBLIC*);
>
>             constant.setModifierFinal(*true*);
>
>             constant.setModifierStatic(*true*);
>
>             constant.setType(FullyQualifiedJavaType.*getStringInstance*
> ());
>
>             constant.setName(cd.getColumnName());
>
>             constant.setInitializationString("\""+property+"\"");
>
>             topLevelClass.addField(constant);
>
>             // FLD – end
>
>             …
>
>
>
> This is very usefull when you handle the domain classes from within
> binding solutions like "JGoodies bindings" to reference bean properties.
>
>
>
> Thanks
>
>
>
> François Le Rolland
>
>
>
>
>