ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeff Butler <jeffgbut...@gmail.com>
Subject Re: Questions on Customized Ibator Implementations
Date Thu, 05 Mar 2009 16:01:55 GMT
1. I'm not sure what you mean by "handle this".  If you disable all
the example methods and have no primary key, then Ibator will only
generate an insert statement.  IMHO, this makes Ibator almost useless!

I'm guessing you mean that the tables have primary keys enforced by
programming, just not constrained in the DB.  In this case, I usually
recommend using the example methods to create "virtual primary key"
based methods.  For example, if SomeTable has an ID field that is like
a primary key, you could write this method:

int deleteById(SomeTableRecord record) {
  SomeTableExample example = new SomeTableExample();
  example.createCriteria().andIdEqualTo(record.getId());
  return deleteByExample(example);
}

But again, if you disable all the example methods this isn't possible.

2. There's no better way - an implementation of CommentGenerator is
the way to go.

3. The XML id for each element is hard-coded - there is no simple way
to change it.

3a. Ibator doesn't support doing aliases out of the box.  But you
could easily write a plugin that changes the full class name to an
alias for all the XML elements.  You could even supply the alias as a
table property in the ibatorConfig if you wanted to.  You could also
have the plugin generate the <typeAlias> elements to add to the SQL
Map XML - although these elements are not mergeable.

3b. A plugin can add methods or elements to any generated object.  I
would suggest the plugin method rather than modifying classes in the
sqlmap.elements packages - this decouples your code from internal
Ibatis code.

Hope that helps -
Jeff Butler


On Thu, Mar 5, 2009 at 2:35 AM, aravind. s <aravind.s@cgi.com> wrote:
>
>
> Hello,
>
>
>
> I need to customize some of the ibator implementations.
>
> Am using Ibator 1.2.1.
>
>
>
> Kindly guide me with the following scenarios which I found cannot be handled
> by ‘plugins’:
>
>
>
> 1.)     We don’t have a primary key constraint in the data base. Is there a
> way to explicitly handle this?
>
> 2.)     I want to provide customized comments instead of
> DefaultCommentGenerator. One of the ways is to write my own implementation
> for CommentGenerator interface. Is there any better way.
>
> 3.)     In xxxSqlMap.xml files, I need to customize the ‘id’ for all the
> elements- resultMap, select, insert, update.
>
> a.)     Instead of giving the full path for class/parameterClass, am
> planning to define an alias name for every class to be used.
>
> b.)     Am not using the model example classes, so I have suppressed their
> generation in one of my plugins, so in case of update, select statements I
> need to have my own where clauses.
>
> For these customizations am currently updating the classes under
> org.apache.ibatis.ibator.generator.ibatis2.sqlmap.elements package.
>
> Can they be implemented using plugins?
>
>
>
> Appreciate your views on these customizations.
>
>
>
> Thanks In Advance,
>
> Aravind. S
>
>

Mime
View raw message