[ 
https://issues.apache.org/jira/browse/IBATIS-590?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12689937#action_12689937
 ] 

Jeff Butler commented on IBATIS-590:
------------------------------------

I think this is a potentially interesting idea, but there are a lot of 
assumptions made in the code example you provided.  For this to work properly, 
there would need to be a lot more definition.  For example:

1. Will we allow multiple levels of nesting (xxx.yyy.zzz)?
2. Should Ibator generate all the intermediate classes too? (e.g., in your 
example do you expect Ibator to generate the Phone class?)
3. What if there is more than one attribute on the nested class?  For example, 
in this case:
  <columnOverride column="FK_PHONE_ID" property="phone.id" 
javaType="model.Phone" /> 
  <columnOverride column="FK_PHONE_NUMBER" property="phone.number" 
javaType="model.Phone" />

  With the patch above, Ibator would generate two getPhone, setPhone methods 
leading to compile errors.

4. What if there are inconsistencies?  For example, what should be generated in 
this case:
  <columnOverride column="FK_PHONE_ID" property="phone.id" 
javaType="model.Phone" /> 
  <columnOverride column="FK_PHONE_NUMBER" property="phones.number" 
javaType="model.Phone" />
5. What if the Phone class is used by more than one table?  Ibator would need 
to keep track of classes that had already been generated so it wouldn't 
generate multiple copies of the Phone class.

Ibator was designed to have a one-to-one match between tables and generated 
classes.  This is pushing Ibator more into the realm of generating a real 
object model.  I'm not completely opposed to this idea, but it requires quite a 
bit more work than the patch above suggests if you want to make it work in a 
general sense.


> Generate Model for property by Ibator 1.2.1
> -------------------------------------------
>
>                 Key: IBATIS-590
>                 URL: https://issues.apache.org/jira/browse/IBATIS-590
>             Project: iBatis for Java
>          Issue Type: Bug
>          Components: Tools
>            Reporter: Alisson Gomes Cerqueira
>
> When generate class java for bean model, by example:
> <table schema="XXX" domainObjectName="Person">
>   <columnOverride column="FK_PHONE"    property="phone.id"   
> javaType="model.Phone"  />
> </table>
> Code generated:
> public class Person {
>   private Phone phone.id;
>   public Phone getPhone.id() {
>         return phone.id;
>     }
>  public void setPhone.id(Phone phone.id) {
>         return phone.id;
>     }
> }
> Solution, create method:
>     public static String getBeanNamePropertyValid(String javaProperty)
>     {
>       String property = javaProperty;
>               if (property != null && !"".equals(property))
>               {
>             int i = property.indexOf('.');
>             if (i >= 0)
>             {
>               property = property.substring(0, i);
>             }
>               }       
>               return property;
>     }
> Modified methods:
> public abstract class BaseModelClassGenerator extends AbstractJavaGenerator {
>    public Field getJavaBeansField(IntrospectedColumn introspectedColumn) 
>    {
>      ...
>      String property = 
> StringUtility.getBeanNamePropertyValid(introspectedColumn.getJavaProperty());
>      ...
>   } 
>   public Method getJavaBeansSetter(IntrospectedColumn introspectedColumn) 
>   { 
>    ....
>    String property = 
> StringUtility.getBeanNamePropertyValid(introspectedColumn.getJavaProperty());
>    ....
>   }
>   public Method getJavaBeansGetter(IntrospectedColumn introspectedColumn) 
>   {
>    ...
>    String property = 
> StringUtility.getBeanNamePropertyValid(introspectedColumn.getJavaProperty());
>    ...
>  }
>   

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to