[PLEASE TEST] new Guice module snapshot

classic Classic list List threaded Threaded
15 messages Options
Reply | Threaded
Open this post in threaded view
|

[PLEASE TEST] new Guice module snapshot

Simone Tripodi-2
Hi all guys,
even if working well, I was not really satisfied at all about the
Builders pattern applied to Modules, so I took advantage from some
spare time and quickly redesigned the mybatis modules to be
implemented closer to how Guice educated users to wire components.

So, I completely dropped the builders, and modules now are configured
with "internal EDSL" alike, APIs are still familiar with existing
ones; just to give an overview old code like

{{{
Injector injector = Guice.createInjector(JdbcHelper.HSQLDB_Embedded,
       new MyBatisModule.Builder()

.setDataSourceProviderType(PooledDataSourceProvider.class)
                        .addMapperClasses(ContactMapper.class)
                        .addTypeHandler(CustomType.class,
CustomLongTypeHandler.class)
                        .addTypeHandler(Address.class, AddressTypeHandler.class)
                        .addInterceptorsClasses(CountUpdateInterceptor.class)
                        .create());
}}}

becomes

{{{
Injector injector = Guice.createInjector(JdbcHelper.HSQLDB_Embedded,
       new MyBatisModule() {

            @Override
            protected void configure() {
                setDataSourceProviderType(PooledDataSourceProvider.class);
                addMapperClasses(ContactMapper.class);
                handleType(CustomType.class).with(CustomLongTypeHandler.class);
                handleType(Address.class).with(AddressTypeHandler.class);
                addInterceptorsClasses(CountUpdateInterceptor.class);
            }

        });
}}}

that looks like much much closer to how Modules work!!! The XML sample below:

{{{
Injector injector = Guice.createInjector(JdbcHelper.HSQLDB_Embedded,
       new XMLMyBatisModule.Builder().setEnvironmentId("test").create());
}}}

becomes

{{{
njector injector = Guice.createInjector(JdbcHelper.HSQLDB_Embedded,
       new XMLMyBatisModule() {

            @Override
            protected void configure() {
                setEnvironmentId("test");
            }

        });
}}}

IMHO is *much* better... but what do YOU think about it? Would you
want to have this APIs released in next release?

Maven users that want to test it, add the repo below in the pom.xml:

{{{
    <repositories>
        ...
        <repository>
            <id>sonatype-nexus-snapshots</id>
            <name>Sonatype Nexus Snapshots</name>
            <url>https://oss.sonatype.org/content/repositories/snapshots</url>
            <releases>
                <enabled>false</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
        ...
    </repositories>
}}}

and add the dependency:

{{{
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-guice</artifactId>
            <version>1.1.1-SNAPSHOT</version>
        </dependency>
}}}

just let me know!!!

Have a nice day,
Simo

http://people.apache.org/~simonetripodi/
http://www.99soft.org/
Reply | Threaded
Open this post in threaded view
|

Re: [PLEASE TEST] new Guice module snapshot

Jeff Butler
Hi Simo,

I just tested this with the XML builder in my current project.  It
works perfectly and I do like the new API as it is much more "guicey".

It is a breaking change to the API, but I think it's early enough in
the life cycle that it will be OK.

+1 from me.

Thanks for your work on this - it's really cool.

Jeff Butler


On Wed, Mar 16, 2011 at 1:04 PM, Simone Tripodi
<[hidden email]> wrote:

> Hi all guys,
> even if working well, I was not really satisfied at all about the
> Builders pattern applied to Modules, so I took advantage from some
> spare time and quickly redesigned the mybatis modules to be
> implemented closer to how Guice educated users to wire components.
>
> So, I completely dropped the builders, and modules now are configured
> with "internal EDSL" alike, APIs are still familiar with existing
> ones; just to give an overview old code like
>
> {{{
> Injector injector = Guice.createInjector(JdbcHelper.HSQLDB_Embedded,
>       new MyBatisModule.Builder()
>
> .setDataSourceProviderType(PooledDataSourceProvider.class)
>                        .addMapperClasses(ContactMapper.class)
>                        .addTypeHandler(CustomType.class,
> CustomLongTypeHandler.class)
>                        .addTypeHandler(Address.class, AddressTypeHandler.class)
>                        .addInterceptorsClasses(CountUpdateInterceptor.class)
>                        .create());
> }}}
>
> becomes
>
> {{{
> Injector injector = Guice.createInjector(JdbcHelper.HSQLDB_Embedded,
>       new MyBatisModule() {
>
>            @Override
>            protected void configure() {
>                setDataSourceProviderType(PooledDataSourceProvider.class);
>                addMapperClasses(ContactMapper.class);
>                handleType(CustomType.class).with(CustomLongTypeHandler.class);
>                handleType(Address.class).with(AddressTypeHandler.class);
>                addInterceptorsClasses(CountUpdateInterceptor.class);
>            }
>
>        });
> }}}
>
> that looks like much much closer to how Modules work!!! The XML sample below:
>
> {{{
> Injector injector = Guice.createInjector(JdbcHelper.HSQLDB_Embedded,
>       new XMLMyBatisModule.Builder().setEnvironmentId("test").create());
> }}}
>
> becomes
>
> {{{
> njector injector = Guice.createInjector(JdbcHelper.HSQLDB_Embedded,
>       new XMLMyBatisModule() {
>
>            @Override
>            protected void configure() {
>                setEnvironmentId("test");
>            }
>
>        });
> }}}
>
> IMHO is *much* better... but what do YOU think about it? Would you
> want to have this APIs released in next release?
>
> Maven users that want to test it, add the repo below in the pom.xml:
>
> {{{
>    <repositories>
>        ...
>        <repository>
>            <id>sonatype-nexus-snapshots</id>
>            <name>Sonatype Nexus Snapshots</name>
>            <url>https://oss.sonatype.org/content/repositories/snapshots</url>
>            <releases>
>                <enabled>false</enabled>
>            </releases>
>            <snapshots>
>                <enabled>true</enabled>
>            </snapshots>
>        </repository>
>        ...
>    </repositories>
> }}}
>
> and add the dependency:
>
> {{{
>        <dependency>
>            <groupId>org.mybatis</groupId>
>            <artifactId>mybatis-guice</artifactId>
>            <version>1.1.1-SNAPSHOT</version>
>        </dependency>
> }}}
>
> just let me know!!!
>
> Have a nice day,
> Simo
>
> http://people.apache.org/~simonetripodi/
> http://www.99soft.org/
>
Reply | Threaded
Open this post in threaded view
|

Re: [PLEASE TEST] new Guice module snapshot

Simone Tripodi-2
Thanks a lot for testing it Jeff!!!
And thanks for the kind words, of course, very appreciated :)
Since there is breaking change to the API, maybe it's time to version
it as 2.0.0 instead of 1.0.2, which is your thought about it?
Thanks in advance, all the best!
Simo

http://people.apache.org/~simonetripodi/
http://www.99soft.org/



On Thu, Mar 17, 2011 at 12:25 AM, Jeff Butler <[hidden email]> wrote:

> Hi Simo,
>
> I just tested this with the XML builder in my current project.  It
> works perfectly and I do like the new API as it is much more "guicey".
>
> It is a breaking change to the API, but I think it's early enough in
> the life cycle that it will be OK.
>
> +1 from me.
>
> Thanks for your work on this - it's really cool.
>
> Jeff Butler
>
>
> On Wed, Mar 16, 2011 at 1:04 PM, Simone Tripodi
> <[hidden email]> wrote:
>> Hi all guys,
>> even if working well, I was not really satisfied at all about the
>> Builders pattern applied to Modules, so I took advantage from some
>> spare time and quickly redesigned the mybatis modules to be
>> implemented closer to how Guice educated users to wire components.
>>
>> So, I completely dropped the builders, and modules now are configured
>> with "internal EDSL" alike, APIs are still familiar with existing
>> ones; just to give an overview old code like
>>
>> {{{
>> Injector injector = Guice.createInjector(JdbcHelper.HSQLDB_Embedded,
>>       new MyBatisModule.Builder()
>>
>> .setDataSourceProviderType(PooledDataSourceProvider.class)
>>                        .addMapperClasses(ContactMapper.class)
>>                        .addTypeHandler(CustomType.class,
>> CustomLongTypeHandler.class)
>>                        .addTypeHandler(Address.class, AddressTypeHandler.class)
>>                        .addInterceptorsClasses(CountUpdateInterceptor.class)
>>                        .create());
>> }}}
>>
>> becomes
>>
>> {{{
>> Injector injector = Guice.createInjector(JdbcHelper.HSQLDB_Embedded,
>>       new MyBatisModule() {
>>
>>            @Override
>>            protected void configure() {
>>                setDataSourceProviderType(PooledDataSourceProvider.class);
>>                addMapperClasses(ContactMapper.class);
>>                handleType(CustomType.class).with(CustomLongTypeHandler.class);
>>                handleType(Address.class).with(AddressTypeHandler.class);
>>                addInterceptorsClasses(CountUpdateInterceptor.class);
>>            }
>>
>>        });
>> }}}
>>
>> that looks like much much closer to how Modules work!!! The XML sample below:
>>
>> {{{
>> Injector injector = Guice.createInjector(JdbcHelper.HSQLDB_Embedded,
>>       new XMLMyBatisModule.Builder().setEnvironmentId("test").create());
>> }}}
>>
>> becomes
>>
>> {{{
>> njector injector = Guice.createInjector(JdbcHelper.HSQLDB_Embedded,
>>       new XMLMyBatisModule() {
>>
>>            @Override
>>            protected void configure() {
>>                setEnvironmentId("test");
>>            }
>>
>>        });
>> }}}
>>
>> IMHO is *much* better... but what do YOU think about it? Would you
>> want to have this APIs released in next release?
>>
>> Maven users that want to test it, add the repo below in the pom.xml:
>>
>> {{{
>>    <repositories>
>>        ...
>>        <repository>
>>            <id>sonatype-nexus-snapshots</id>
>>            <name>Sonatype Nexus Snapshots</name>
>>            <url>https://oss.sonatype.org/content/repositories/snapshots</url>
>>            <releases>
>>                <enabled>false</enabled>
>>            </releases>
>>            <snapshots>
>>                <enabled>true</enabled>
>>            </snapshots>
>>        </repository>
>>        ...
>>    </repositories>
>> }}}
>>
>> and add the dependency:
>>
>> {{{
>>        <dependency>
>>            <groupId>org.mybatis</groupId>
>>            <artifactId>mybatis-guice</artifactId>
>>            <version>1.1.1-SNAPSHOT</version>
>>        </dependency>
>> }}}
>>
>> just let me know!!!
>>
>> Have a nice day,
>> Simo
>>
>> http://people.apache.org/~simonetripodi/
>> http://www.99soft.org/
>>
>
Reply | Threaded
Open this post in threaded view
|

Re: new Guice module snapshot

marzia
In reply to this post by Simone Tripodi-2
Hi Simone,

It's worthy revision, but my humble observation...
'AbstractMyBatisModule' implements 'Module' but it replicates some
code of 'com.google.inject.AbstractModule' wouldn't be wiser to extend
from it ?
Downside of current 'AbstractMyBatisModule' is that it hides a binder
and have no handy methods of 'com.google.inject.AbstractModule'.

Cheers,
Marzia
Reply | Threaded
Open this post in threaded view
|

Re: new Guice module snapshot

Simone Tripodi-2
Hi Marzia,
that's the kind of question I was waiting for ;)

The reason why I took that decision is because users that need to bind
objects in the old way have to use proper Guice
Module/AbstractModules; OTOH, (XML)MyBatisModule exposes a MyBatis
EDSL only.

The AbstractMyBatisModule replicates the
com.google.inject.AbstractModule only in 2 small things:
 * wrap the binder and call the configure method;
 * make the binder available in subclasses, hiding it from external uses.

APIs provided by (XML)MyBatisModule are higher level compared to
Binder APIs, the intention is providing a MyBatis language to wire
components, rather than the Guice's one. Being a *MyBatis* module,
users configure there mybatis stuff, other stuff have to be bound
elsewhere.

Thanks for your feedbacks and keep on providing
feedbacks/suggestions/questions!!!
Simo

http://people.apache.org/~simonetripodi/
http://www.99soft.org/



On Fri, Mar 18, 2011 at 11:44 AM, marzia <[hidden email]> wrote:

> Hi Simone,
>
> It's worthy revision, but my humble observation...
> 'AbstractMyBatisModule' implements 'Module' but it replicates some
> code of 'com.google.inject.AbstractModule' wouldn't be wiser to extend
> from it ?
> Downside of current 'AbstractMyBatisModule' is that it hides a binder
> and have no handy methods of 'com.google.inject.AbstractModule'.
>
> Cheers,
> Marzia
>
Reply | Threaded
Open this post in threaded view
|

Re: new Guice module snapshot

Simone Tripodi-2
BTW since the Guice team adopted and approach similar to what you're
proposing for the ServletModule[1] I'll do yet another review&snapshot
deploy later ;)
Thanks!!!
Simo

[1] http://tinyurl.com/6c6wr4l

http://people.apache.org/~simonetripodi/
http://www.99soft.org/



On Fri, Mar 18, 2011 at 12:00 PM, Simone Tripodi
<[hidden email]> wrote:

> Hi Marzia,
> that's the kind of question I was waiting for ;)
>
> The reason why I took that decision is because users that need to bind
> objects in the old way have to use proper Guice
> Module/AbstractModules; OTOH, (XML)MyBatisModule exposes a MyBatis
> EDSL only.
>
> The AbstractMyBatisModule replicates the
> com.google.inject.AbstractModule only in 2 small things:
>  * wrap the binder and call the configure method;
>  * make the binder available in subclasses, hiding it from external uses.
>
> APIs provided by (XML)MyBatisModule are higher level compared to
> Binder APIs, the intention is providing a MyBatis language to wire
> components, rather than the Guice's one. Being a *MyBatis* module,
> users configure there mybatis stuff, other stuff have to be bound
> elsewhere.
>
> Thanks for your feedbacks and keep on providing
> feedbacks/suggestions/questions!!!
> Simo
>
> http://people.apache.org/~simonetripodi/
> http://www.99soft.org/
>
>
>
> On Fri, Mar 18, 2011 at 11:44 AM, marzia <[hidden email]> wrote:
>> Hi Simone,
>>
>> It's worthy revision, but my humble observation...
>> 'AbstractMyBatisModule' implements 'Module' but it replicates some
>> code of 'com.google.inject.AbstractModule' wouldn't be wiser to extend
>> from it ?
>> Downside of current 'AbstractMyBatisModule' is that it hides a binder
>> and have no handy methods of 'com.google.inject.AbstractModule'.
>>
>> Cheers,
>> Marzia
>>
>
Reply | Threaded
Open this post in threaded view
|

Re: new Guice module snapshot

marzia
In reply to this post by Simone Tripodi-2
Hi Somine,

All valid points, but...
I use to encapsulate mybatis inside 'UserDAOImpl' which implements
'UserDAO', so I need something like:
bind(UserDAO.class).to(UserDAOImpl.class);
to make a configuration complete.
So now I have to have two modules: one for mybatis stuff and one for
my service/dao components, it was handy to have those close together,
something like:

addMapperClass(UserMapper.class);
bind(UserDAO.class).to(UserDAOImpl.class);

WDYT ?
Marzia
Reply | Threaded
Open this post in threaded view
|

Re: new Guice module snapshot

Simone Tripodi-2
Hi Marzia,
agreed, good point ;) As I wrote in my previous message, I'll
change&deploy the new snapshot as soon as I can, stay tuned!!!
Thanks!!!
Simo

http://people.apache.org/~simonetripodi/
http://www.99soft.org/



On Fri, Mar 18, 2011 at 12:25 PM, marzia <[hidden email]> wrote:

> Hi Somine,
>
> All valid points, but...
> I use to encapsulate mybatis inside 'UserDAOImpl' which implements
> 'UserDAO', so I need something like:
> bind(UserDAO.class).to(UserDAOImpl.class);
> to make a configuration complete.
> So now I have to have two modules: one for mybatis stuff and one for
> my service/dao components, it was handy to have those close together,
> something like:
>
> addMapperClass(UserMapper.class);
> bind(UserDAO.class).to(UserDAOImpl.class);
>
> WDYT ?
> Marzia
>
Reply | Threaded
Open this post in threaded view
|

Re: new Guice module snapshot

marzia
Hi Simone,

Sorry but I haven't red your message before posting mine...

Cheers,
Marzia
Reply | Threaded
Open this post in threaded view
|

Re: new Guice module snapshot

Simone Tripodi-2
Don't worry at all, it was just a reminder ;)
Have a nice day,
Simo

http://people.apache.org/~simonetripodi/
http://www.99soft.org/



On Fri, Mar 18, 2011 at 12:41 PM, marzia <[hidden email]> wrote:
> Hi Simone,
>
> Sorry but I haven't red your message before posting mine...
>
> Cheers,
> Marzia
>
Reply | Threaded
Open this post in threaded view
|

Re: new Guice module snapshot

Simone Tripodi-2
I just updated a new SNAPSHOT with Marzia's suggestions, does someone
have the time to check it?
Many thanks in advance!!!
Simo

http://people.apache.org/~simonetripodi/
http://www.99soft.org/



On Fri, Mar 18, 2011 at 12:51 PM, Simone Tripodi
<[hidden email]> wrote:

> Don't worry at all, it was just a reminder ;)
> Have a nice day,
> Simo
>
> http://people.apache.org/~simonetripodi/
> http://www.99soft.org/
>
>
>
> On Fri, Mar 18, 2011 at 12:41 PM, marzia <[hidden email]> wrote:
>> Hi Simone,
>>
>> Sorry but I haven't red your message before posting mine...
>>
>> Cheers,
>> Marzia
>>
>
Reply | Threaded
Open this post in threaded view
|

Re: new Guice module snapshot

marzia
Hi Simone,

Just checked... and it's even more perfect ;-)

Cheers,
Marzia
Reply | Threaded
Open this post in threaded view
|

Re: new Guice module snapshot

Simone Tripodi
Thanks a lot Marzia,
just the time to update the user manual and the module will be
released as 2.0.0 :) At 90% it will happen tonight :D
Thanks a lot for your contributions, have a nice day!
Simo

PS Are you Italian?

On Mar 18, 3:41 pm, marzia <[hidden email]> wrote:
> Hi Simone,
>
> Just checked... and it's even more perfect ;-)
>
> Cheers,
> Marzia
Reply | Threaded
Open this post in threaded view
|

Re: new Guice module snapshot

marzia
Hi Simone,

Many thanks to you for taking your time & energy and giving back to
mybatis community ;-)

Cheers,
Marzia
Reply | Threaded
Open this post in threaded view
|

Re: new Guice module snapshot

Simone Tripodi-2
Hi all guys,
please do a final review :) I uploaded a new SNAPSHOT and attached to
this email the user manual, please have a look at it.
If the new would work for you, I'll release it. Please let me know!!!
Have a nice day,
Simo

http://people.apache.org/~simonetripodi/
http://www.99soft.org/



On Fri, Mar 18, 2011 at 3:58 PM, marzia <[hidden email]> wrote:
> Hi Simone,
>
> Many thanks to you for taking your time & energy and giving back to
> mybatis community ;-)
>
> Cheers,
> Marzia

mybatis-guice-2.0.0-SNAPSHOT-reference.pdf (116K) Download Attachment