You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Andreas Prudzilko <ap...@welho.com> on 2006/12/16 10:22:54 UTC

Connection session bound

Hi,

i was wondering about the connection pooling in ibatis. Is it possible 
to bind a connection to a httpsession?
Or are there any pros and cons to do it?

- Andreas



Re: Connection session bound

Posted by Larry Meadors <lm...@apache.org>.
On 12/16/06, Chris Lamey <cl...@localmatters.com> wrote:
>  PS: I sound like a Spring salesman today!  Buy now and I'll throw in a set
> of steak knives for free!

SOLD! ...now, where are my knives?!

Larry

Re: Connection session bound

Posted by Clinton Begin <cl...@gmail.com>.
Without going as far as spring, you could make a servlet filter that simply
starts, commits and ends the transaction.

It would probably be less than 25 lines of code.  Piece o' cake.

Cheers,
Clinton

On 12/16/06, Chris Lamey <cl...@localmatters.com> wrote:
>
>  I was under the impression that the transaction per HTTP request was more
> for easy error handling than performance.  If some SQL halfway through the
> request bombs out you automatically roll everything back.
>
> Anyway, iBATIS has nothing like this built in, but you could set something
> similar up with declarative transactional support in Spring.  If you're
> using the Spring web framework with the DispatcherServlet and stuff I think
> it'd be pretty easy to specify the transactions wherever you wanted.
> Personally, I like to stuff my transaction handling as far 'down' as
> possible, but I guess there's no reason you couldn't bring it 'up' as far as
> you want.
>
> Also, I believe if you do it right, changing transactional behavior won't
> require refactoring because the transactional support should be transparent
> to your code.  I like to write my business logic as clearly as possible,
> then figure out what's transactional, and then specify the transactions
> outside the code using Spring.  That's just my opinion, I know some folks
> really like writing explicit transaction handling in their code, but I find
> it makes things overly complicated and I can do everything I need at the
> method level.
>
> PS: I sound like a Spring salesman today!  Buy now and I'll throw in a set
> of steak knives for free!
>
> Cheers,
> Chris
>
>
> -----Original Message-----
> From: Andreas Prudzilko [mailto:aprudzil@welho.com <ap...@welho.com>]
> Sent: Sat 12/16/2006 1:39 PM
> To: user-java@ibatis.apache.org
> Subject: Re: Connection session bound
>
> Yeah I agree, it was more about choosing the best practice. From my
> experience it saves a lot of refactoring if you do it right in the first
> place :-D
> I guess I leave it for now as is, and see what happens in production.
>
> Thanks,
>
> - Andreas
> > If you are using a pool, it would give almost no benefit, IMO.
> >
> > Try it simple, if you have problems, optimize them later - premature
> > optimization is the root of many evils. ;-)
> >
> > Larry
> >
> >
> > On 12/16/06, Andreas Prudzilko <ap...@welho.com> wrote:
> >>
> >>  Hi Brandon,
> >>
> >>  well i was just reading some hibernate tutorials and there were some
> >> thought about binding a db connection at least to a http request to
> gain
> >> more performance.
> >>  Now im writing an ajax webapplication, so i have a lot of tiny http
> >> requests. So binding the db connection there wouldn't make much
> >> sense. So I
> >> thought, if its beneficial I would prefer binding it to a http
> sessions.
> >>  Well might be of course total bogus :-D. To be honest I'm not even
> >> sure how
> >> the performance would improve especially since there is a connection
> >> pooling
> >> to begin with.
> >>
> >>  Any remarks on my thoughts?
> >>
> >>  - Andreas
> >>
> >>
> >> I can't imagine a situation where I would tie a connection to an
> >> HttpSession. What is causing you to consider this? If you can provide
> >> some
> >> insight as to why you would want to do this we can provide more pointed
> >> advice.
> >>
> >>  Brandon
> >>
> >>
> >> On 12/16/06, Andreas Prudzilko <ap...@welho.com> wrote:
> >> > Hi,
> >> >
> >> > i was wondering about the connection pooling in ibatis. Is it
> possible
> >> > to bind a connection to a httpsession?
> >> > Or are there any pros and cons to do it?
> >> >
> >> > - Andreas
> >> >
> >> >
> >> >
> >>
> >>
> >>
> >
>
>
>

RE: Connection session bound

Posted by Chris Lamey <cl...@localmatters.com>.
I was under the impression that the transaction per HTTP request was more for easy error handling than performance.  If some SQL halfway through the request bombs out you automatically roll everything back.

Anyway, iBATIS has nothing like this built in, but you could set something similar up with declarative transactional support in Spring.  If you're using the Spring web framework with the DispatcherServlet and stuff I think it'd be pretty easy to specify the transactions wherever you wanted.  Personally, I like to stuff my transaction handling as far 'down' as possible, but I guess there's no reason you couldn't bring it 'up' as far as you want.

Also, I believe if you do it right, changing transactional behavior won't require refactoring because the transactional support should be transparent to your code.  I like to write my business logic as clearly as possible, then figure out what's transactional, and then specify the transactions outside the code using Spring.  That's just my opinion, I know some folks really like writing explicit transaction handling in their code, but I find it makes things overly complicated and I can do everything I need at the method level.

PS: I sound like a Spring salesman today!  Buy now and I'll throw in a set of steak knives for free!

Cheers,
Chris

-----Original Message-----
From: Andreas Prudzilko [mailto:aprudzil@welho.com]
Sent: Sat 12/16/2006 1:39 PM
To: user-java@ibatis.apache.org
Subject: Re: Connection session bound
 
Yeah I agree, it was more about choosing the best practice. From my 
experience it saves a lot of refactoring if you do it right in the first 
place :-D
I guess I leave it for now as is, and see what happens in production.

Thanks,

- Andreas
> If you are using a pool, it would give almost no benefit, IMO.
>
> Try it simple, if you have problems, optimize them later - premature
> optimization is the root of many evils. ;-)
>
> Larry
>
>
> On 12/16/06, Andreas Prudzilko <ap...@welho.com> wrote:
>>
>>  Hi Brandon,
>>
>>  well i was just reading some hibernate tutorials and there were some
>> thought about binding a db connection at least to a http request to gain
>> more performance.
>>  Now im writing an ajax webapplication, so i have a lot of tiny http
>> requests. So binding the db connection there wouldn't make much 
>> sense. So I
>> thought, if its beneficial I would prefer binding it to a http sessions.
>>  Well might be of course total bogus :-D. To be honest I'm not even 
>> sure how
>> the performance would improve especially since there is a connection 
>> pooling
>> to begin with.
>>
>>  Any remarks on my thoughts?
>>
>>  - Andreas
>>
>>
>> I can't imagine a situation where I would tie a connection to an
>> HttpSession. What is causing you to consider this? If you can provide 
>> some
>> insight as to why you would want to do this we can provide more pointed
>> advice.
>>
>>  Brandon
>>
>>
>> On 12/16/06, Andreas Prudzilko <ap...@welho.com> wrote:
>> > Hi,
>> >
>> > i was wondering about the connection pooling in ibatis. Is it possible
>> > to bind a connection to a httpsession?
>> > Or are there any pros and cons to do it?
>> >
>> > - Andreas
>> >
>> >
>> >
>>
>>
>>
>



Re: Connection session bound

Posted by Andreas Prudzilko <ap...@welho.com>.
Yeah I agree, it was more about choosing the best practice. From my 
experience it saves a lot of refactoring if you do it right in the first 
place :-D
I guess I leave it for now as is, and see what happens in production.

Thanks,

- Andreas
> If you are using a pool, it would give almost no benefit, IMO.
>
> Try it simple, if you have problems, optimize them later - premature
> optimization is the root of many evils. ;-)
>
> Larry
>
>
> On 12/16/06, Andreas Prudzilko <ap...@welho.com> wrote:
>>
>>  Hi Brandon,
>>
>>  well i was just reading some hibernate tutorials and there were some
>> thought about binding a db connection at least to a http request to gain
>> more performance.
>>  Now im writing an ajax webapplication, so i have a lot of tiny http
>> requests. So binding the db connection there wouldn't make much 
>> sense. So I
>> thought, if its beneficial I would prefer binding it to a http sessions.
>>  Well might be of course total bogus :-D. To be honest I'm not even 
>> sure how
>> the performance would improve especially since there is a connection 
>> pooling
>> to begin with.
>>
>>  Any remarks on my thoughts?
>>
>>  - Andreas
>>
>>
>> I can't imagine a situation where I would tie a connection to an
>> HttpSession. What is causing you to consider this? If you can provide 
>> some
>> insight as to why you would want to do this we can provide more pointed
>> advice.
>>
>>  Brandon
>>
>>
>> On 12/16/06, Andreas Prudzilko <ap...@welho.com> wrote:
>> > Hi,
>> >
>> > i was wondering about the connection pooling in ibatis. Is it possible
>> > to bind a connection to a httpsession?
>> > Or are there any pros and cons to do it?
>> >
>> > - Andreas
>> >
>> >
>> >
>>
>>
>>
>


Re: Connection session bound

Posted by Larry Meadors <lm...@apache.org>.
If you are using a pool, it would give almost no benefit, IMO.

Try it simple, if you have problems, optimize them later - premature
optimization is the root of many evils. ;-)

Larry


On 12/16/06, Andreas Prudzilko <ap...@welho.com> wrote:
>
>  Hi Brandon,
>
>  well i was just reading some hibernate tutorials and there were some
> thought about binding a db connection at least to a http request to gain
> more performance.
>  Now im writing an ajax webapplication, so i have a lot of tiny http
> requests. So binding the db connection there wouldn't make much sense. So I
> thought, if its beneficial I would prefer binding it to a http sessions.
>  Well might be of course total bogus :-D. To be honest I'm not even sure how
> the performance would improve especially since there is a connection pooling
> to begin with.
>
>  Any remarks on my thoughts?
>
>  - Andreas
>
>
> I can't imagine a situation where I would tie a connection to an
> HttpSession. What is causing you to consider this? If you can provide some
> insight as to why you would want to do this we can provide more pointed
> advice.
>
>  Brandon
>
>
> On 12/16/06, Andreas Prudzilko <ap...@welho.com> wrote:
> > Hi,
> >
> > i was wondering about the connection pooling in ibatis. Is it possible
> > to bind a connection to a httpsession?
> > Or are there any pros and cons to do it?
> >
> > - Andreas
> >
> >
> >
>
>
>

Re: Connection session bound

Posted by Brandon Goodin <br...@gmail.com>.
I can't imagine a situation where I would tie a connection to an
HttpSession. What is causing you to consider this? If you can provide some
insight as to why you would want to do this we can provide more pointed
advice.

Brandon

On 12/16/06, Andreas Prudzilko <ap...@welho.com> wrote:
>
> Hi,
>
> i was wondering about the connection pooling in ibatis. Is it possible
> to bind a connection to a httpsession?
> Or are there any pros and cons to do it?
>
> - Andreas
>
>
>