how to use @Mappers & @TypeAliases

25 views
Skip to first unread message

Eelco Hillenius

unread,
Feb 11, 2010, 3:41:29 PM2/11/10
to ibag...@googlegroups.com
I hope you don't mind if I take you up to your offer of asking freely... :-)

I was wondering how @Mappers and @TypeAliases (package
com.google.code.ibaguice.core.configuration) are supposed to be used?

Eelco

Marco Speranza

unread,
Feb 11, 2010, 4:57:01 PM2/11/10
to ibaguice
Hi Eelco,

dont worry, feel free to ask whatever you want :-)

So.. basically @Mapper and @TypeAliases are used by core class module
com.google.code.ibaguice.core.SqlSessionFactoryModule to bind your
ibatis mapper and typealiases, and create an iBatis configuration
through
com.google.code.ibaguice.core.configuration.ConfigurationProvider.

take a look this: com.google.code.ibaguice.samples.AbstractTestCase
and com.google.code.ibaguice.samples.SimpleTestCase
...
// bindings
SqlSessionFactoryModule ibatisModule = new
SqlSessionFactoryModule(this.getDataSourceProviderClass());

ibatisModule.addSimpleAliases(Contact.class);
ibatisModule.setMapperClasses(getMapperClass());
Injector injector = Guice.createInjector(ibatisModule,
...

with this snippet you can configure programmatically the main module
with your mapper and to register your typeAlias.

If you are familiar with ibatis xml configuration file, the snippet
above is equals to:

<configuration>
<typeAliases>
<typeAlias alias="Contact"
type="com.google.code.ibaguice.samples.Contact"/>
</typeAliases>
....
<mappers>
<mapper
resource="com.google.code.ibaguice.samples.ContactMapper.xml"/>
</mappers>
...
</configuration>

I hope I've been helpful

ciao

Eelco Hillenius

unread,
Feb 11, 2010, 5:00:01 PM2/11/10
to ibag...@googlegroups.com
> So.. basically @Mapper and @TypeAliases are used by  core class module
> com.google.code.ibaguice.core.SqlSessionFactoryModule to bind your
> ibatis mapper and  typealiases,  and create an iBatis configuration
> through
> com.google.code.ibaguice.core.configuration.ConfigurationProvider.

Ah, ok... so if I understand correctly it is a multi-map like trick
you use internally; @Mappers and @TypeAliases are not intended to be
used by regular clients.

Cheers,

Eelco

Marco Speranza

unread,
Feb 11, 2010, 5:09:26 PM2/11/10
to ibaguice
> @Mappers and @TypeAliases are not intended to be
> used by regular clients.

Yes, correct

ciao.

Simone Tripodi

unread,
Feb 12, 2010, 2:29:26 AM2/12/10
to ibag...@googlegroups.com
Hi Eelco,
as Marco already explained, the annotations are used to inject mapper
interfaces and type aliases; since the Mapper neither the TypeAlias
type doesn't exist as type in iBatis, and we needed to make them
auto-injectable through guice, the only way to achieve it was using
the multi-mapping and binding annotations you found in the code.
The com.google.code.ibaguice.core.SqlSessionFactoryModule we developed
is intended to simplify developers' tasks, but advanced and more
exigent user are free to inject the
org.apache.ibatis.session.SqlSessionFactory reusing iBaGuice classes
in the way they prefer ;)
Best regards,
Simo

http://people.apache.org/~simonetripodi/

Simone Tripodi

unread,
Feb 18, 2010, 4:40:30 AM2/18/10
to ibag...@googlegroups.com
Hi Eelco!
do you have any feedback/suggestion for us to improve the library? :P
Thanks in advance!!!
Simo

http://people.apache.org/~simonetripodi/

Eelco Hillenius

unread,
Feb 18, 2010, 2:21:47 PM2/18/10
to ibag...@googlegroups.com
Hi Simone,

On Thu, Feb 18, 2010 at 1:40 AM, Simone Tripodi
<simone....@gmail.com> wrote:
> Hi Eelco!
> do you have any feedback/suggestion for us to improve the library? :P
> Thanks in advance!!!

Well, I've been a bit side tracked unfortunately, and I might just
write a few classes myself to fit in the frameworks I wrote for my
company, as that'd be simpler. Again, the main stumble block is that I
need to support multiple data sources, and while you could build that
in to ibaguice, it might make the library more complicated, so it
might not be the best idea. I think ibaguice is nice as it is tbh.

I did also take a look at writing something that would fit into
warp-persist, but concluded that, while I like warp-persist, ibaguice
is better for ibatis, since it supports some things in a more
straightforward fashion (like what you can configure as part of
@Transactional).

Anyway, hopefully I'll have a bit time next week to work on iBatis
integration. If I have something to share from that experience, I
won't hesitate :-)

Thanks!

Eelco

Reply all
Reply to author
Forward
0 new messages