"Managed" SqlSession injection with mybatis-guice?

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

"Managed" SqlSession injection with mybatis-guice?

Eduardo Macarron
I there Simo,

This is a question from a complete Guice ignorant & newcomer, so
please be patient ;)

From a user point of view I think that I would expect from IoC
container to get injected "managed" mappers and "managed" SqlSessions.
That is just what my code needs. All the rest (like the
SqlSessionFactory) may be injected if needed but not in the normal
scenario when the @Transactional/TransactionInterceptor will manage
the whole SqlSession life cycle.

The point is that the manual just talks about injecting a
SqlSessionFactory and a SqlSessionManager. But I would expect it to
talk about injecting a SqlSession that I would not have to open/commit/
rollback/close and also mappers that I use in the same way.

So far this is a doc-related question.

And should not the MyBatis module bind the SqlSessionManager to
SqlSession to SqlSession so it can be injected?

Reply | Threaded
Open this post in threaded view
|

RE: "Managed" SqlSession injection with mybatis-guice?

Poitras Christian
Hi Eduardo,

I guess you're right and it makes sense.

Christian

-----Message d'origine-----
De : [hidden email] [mailto:[hidden email]] De la part de Eduardo
Envoyé : November-24-10 10:46 AM
À : mybatis-user
Objet : "Managed" SqlSession injection with mybatis-guice?

I there Simo,

This is a question from a complete Guice ignorant & newcomer, so
please be patient ;)

From a user point of view I think that I would expect from IoC
container to get injected "managed" mappers and "managed" SqlSessions.
That is just what my code needs. All the rest (like the
SqlSessionFactory) may be injected if needed but not in the normal
scenario when the @Transactional/TransactionInterceptor will manage
the whole SqlSession life cycle.

The point is that the manual just talks about injecting a
SqlSessionFactory and a SqlSessionManager. But I would expect it to
talk about injecting a SqlSession that I would not have to open/commit/
rollback/close and also mappers that I use in the same way.

So far this is a doc-related question.

And should not the MyBatis module bind the SqlSessionManager to
SqlSession to SqlSession so it can be injected?

Reply | Threaded
Open this post in threaded view
|

Re: "Managed" SqlSession injection with mybatis-guice?

Simone Tripodi
In reply to this post by Eduardo Macarron
Hola Edu,
don't worry, I'm pleased you're interested on Guice, and glad you're
reading the documentation, so feedbacks are appreciated :P

I've to suppose that maybe the documentation is not so clear as I
thought, but ALL components injected by Guice are *ONLY* managed
components, based on a thread-safety SqlSessionManager instance,
except the SqlSessionFactory, available for crazy guys that need to
execute their hacks ;)
When requesting mappers injection, components that will be injected
are SqlSessionManager managed mappers, and users don't have to take
care about open/close/rollback/commit at all.
I'm sure I told you about it since we chatted a little on this topic,
but reading the doc is not obvious as I though :)

What is missing, is the SqlSession -> SqlSessionManager binding, that
I'm going to add now, and thanks for the hint :P

Hope this helps,
Simo

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



On Wed, Nov 24, 2010 at 4:45 PM, Eduardo <[hidden email]> wrote:

> I there Simo,
>
> This is a question from a complete Guice ignorant & newcomer, so
> please be patient ;)
>
> From a user point of view I think that I would expect from IoC
> container to get injected "managed" mappers and "managed" SqlSessions.
> That is just what my code needs. All the rest (like the
> SqlSessionFactory) may be injected if needed but not in the normal
> scenario when the @Transactional/TransactionInterceptor will manage
> the whole SqlSession life cycle.
>
> The point is that the manual just talks about injecting a
> SqlSessionFactory and a SqlSessionManager. But I would expect it to
> talk about injecting a SqlSession that I would not have to open/commit/
> rollback/close and also mappers that I use in the same way.
>
> So far this is a doc-related question.
>
> And should not the MyBatis module bind the SqlSessionManager to
> SqlSession to SqlSession so it can be injected?
>
>
Reply | Threaded
Open this post in threaded view
|

Re: "Managed" SqlSession injection with mybatis-guice?

Eduardo Macarron

Yep Simo, I already know that mappers _are_ managed (I first thought
it was a bug in mybatis-guice but you explained me where the magic
is :) ). I was just pointing that maybe the "getting injection"
chapter in the manual maybe should be written from a different
perspective.

And, happy to be of help! :)


Reply | Threaded
Open this post in threaded view
|

Re: "Managed" SqlSession injection with mybatis-guice?

Simone Tripodi
Hola Edu,
I had a fantastic idea: why don't you contribute on the Guice module
user manual? Being not deep inside the code, you should be able to
raise questions, like this, that would improve the documentation?
Are you interested? I hope you'll reply "yes" :)
Have a nice evening,
Simo

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



On Wed, Nov 24, 2010 at 6:08 PM, Eduardo <[hidden email]> wrote:

>
> Yep Simo, I already know that mappers _are_ managed (I first thought
> it was a bug in mybatis-guice but you explained me where the magic
> is :) ). I was just pointing that maybe the "getting injection"
> chapter in the manual maybe should be written from a different
> perspective.
>
> And, happy to be of help! :)
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: "Managed" SqlSession injection with mybatis-guice?

Eduardo Macarron
of course yes :)

I will send suggestions & patches to this list.

On 24 nov, 19:29, Simone Tripodi <[hidden email]> wrote:

> Hola Edu,
> I had a fantastic idea: why don't you contribute on the Guice module
> user manual? Being not deep inside the code, you should be able to
> raise questions, like this, that would improve the documentation?
> Are you interested? I hope you'll reply "yes" :)
> Have a nice evening,
> Simo
>
> http://people.apache.org/~simonetripodi/http://www.99soft.org/
>
>
>
>
>
>
>
> On Wed, Nov 24, 2010 at 6:08 PM, Eduardo <[hidden email]> wrote:
>
> > Yep Simo, I already know that mappers _are_ managed (I first thought
> > it was a bug in mybatis-guice but you explained me where the magic
> > is :) ). I was just pointing that maybe the "getting injection"
> > chapter in the manual maybe should be written from a different
> > perspective.
>
> > And, happy to be of help! :)
Reply | Threaded
Open this post in threaded view
|

Re: "Managed" SqlSession injection with mybatis-guice?

Eduardo Macarron

I would suggest to start doing the same we did for the Spring manual.
There are two missing chapters that I think are very useful: a getting
started and the sample code.

I would like to see how to make this run in few steps without going
into internals. This is just the installation instructions and a few
steps to setup a datasource, the module, a mapper and inject it
(forgetting about typehandlers, interceptos, aliases and so)

For the sample we can add the UserMapper ultra-simple sample we have
in Spring. I think it will be really didactic to be able to see the
same sample in both technologies (it will be almost a copy&paste
because it will work almost untouched)

So the main index could be this one:
1- introduction (no changes)
2- getting started (installation & simple steps to make it run)
3- mybatis setup (both by code & xml)
4- datasource setup
5- requesting injections (just how to inject SqlSessions and Mappers,
explain that SqlSession is managed, etc..)
6- transactions
7- using mybatis api (warning about using the SqlSessionFactory)
8- sample code

I will work in this line to make a proposal in a pair of days (1)

(1) I never meet the deadlines ;)


Reply | Threaded
Open this post in threaded view
|

Re: "Managed" SqlSession injection with mybatis-guice?

Simone Tripodi
Cool, thanks a lot :) I'm convinced that when writing the manual I
assumed too much implicit concepts, better being more clear :D
Have a nice day,
Simo

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



On Wed, Nov 24, 2010 at 11:11 PM, Eduardo <[hidden email]> wrote:

>
> I would suggest to start doing the same we did for the Spring manual.
> There are two missing chapters that I think are very useful: a getting
> started and the sample code.
>
> I would like to see how to make this run in few steps without going
> into internals. This is just the installation instructions and a few
> steps to setup a datasource, the module, a mapper and inject it
> (forgetting about typehandlers, interceptos, aliases and so)
>
> For the sample we can add the UserMapper ultra-simple sample we have
> in Spring. I think it will be really didactic to be able to see the
> same sample in both technologies (it will be almost a copy&paste
> because it will work almost untouched)
>
> So the main index could be this one:
> 1- introduction (no changes)
> 2- getting started (installation & simple steps to make it run)
> 3- mybatis setup (both by code & xml)
> 4- datasource setup
> 5- requesting injections (just how to inject SqlSessions and Mappers,
> explain that SqlSession is managed, etc..)
> 6- transactions
> 7- using mybatis api (warning about using the SqlSessionFactory)
> 8- sample code
>
> I will work in this line to make a proposal in a pair of days (1)
>
> (1) I never meet the deadlines ;)
>
>
>