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 Eugeny N Dzhurinsky <bo...@redwerk.com> on 2006/09/19 14:40:43 UTC
passing connection to ibatis
Hello!
I have a problem - my application creates temporary views for set of talbes
and then I would like to execute some queries on this view using iBATIS. For
postgresql the temporary view is alife unless the connection is closed, so my
workflow might looks like this:
1) get the connection from pool/whatever
2) create view
3) invoke SQL using iBATIS
4) excplicitly close connection to avoid re-using it by some other module
how can I implement this?
--
Eugene N Dzhurinsky
Re: passing connection to ibatis
Posted by Larry Meadors <lm...@apache.org>.
Well, I have never imagined that anyone would want to. ;-)
Larry
On 9/20/06, Eugeny N Dzhurinsky <bo...@redwerk.com> wrote:
> On Tue, Sep 19, 2006 at 03:40:43PM +0300, Eugeny N Dzhurinsky wrote:
> > Hello!
> >
> > I have a problem - my application creates temporary views for set of talbes
> > and then I would like to execute some queries on this view using iBATIS. For
> > postgresql the temporary view is alife unless the connection is closed, so my
> > workflow might looks like this:
> >
> > 1) get the connection from pool/whatever
> > 2) create view
> > 3) invoke SQL using iBATIS
> > 4) excplicitly close connection to avoid re-using it by some other module
> >
> > how can I implement this?
>
> So it isn't possible at all ot nobody did such things before? ;)
>
> --
> Eugene N Dzhurinsky
>
Re: passing connection to ibatis
Posted by Eugeny N Dzhurinsky <bo...@redwerk.com>.
On Tue, Sep 19, 2006 at 03:40:43PM +0300, Eugeny N Dzhurinsky wrote:
> Hello!
>
> I have a problem - my application creates temporary views for set of talbes
> and then I would like to execute some queries on this view using iBATIS. For
> postgresql the temporary view is alife unless the connection is closed, so my
> workflow might looks like this:
>
> 1) get the connection from pool/whatever
> 2) create view
> 3) invoke SQL using iBATIS
> 4) excplicitly close connection to avoid re-using it by some other module
>
> how can I implement this?
So it isn't possible at all ot nobody did such things before? ;)
--
Eugene N Dzhurinsky
RE: passing connection to ibatis
Posted by Pa...@cexp.com.
>> If you're using DBCP, you might be able to your own implementation of
>> org.apache.commons.dbcp.ConnectionFactory that creates the temporary tables
>> before returning the connection from the createConnection() method.
>That might work in case if I need to create those tables/views for each
>request for database, which isn't my case. I need to create such views only in
>certain cases and don't create them in other cases. If it would be possible to
>pass a connection to iBATIS somehow - that would definitely solve my problem
That would only create the views when the connection is created, not on every request. If it's a very rare case to use those views, then I can see not wanting to do this for every connection. But keep in mind that your connections are probably going to live for a long time and service many requests, so if it's likely that the same connection will access the views at least twice, then you might as well create the views when creating a connection.
Re: passing connection to ibatis
Posted by Eugeny N Dzhurinsky <bo...@redwerk.com>.
On Thu, Sep 21, 2006 at 10:31:02AM -0600, Patrick.Higgins@cexp.com wrote:
> You're only going to want to create temporary tables when the connection is
> created, not at the beginning of every transaction.
>
> Depending on what kind of connection pool you're using, you may be able to
> use their connection lifecycle event handler to do this rather than rely on
> iBATIS to expose this functionality, which it probably can't do for most
> external pools, anyway (unless it wraps their mechanisms, but that assumes
> the API each connection pool exposes would be directly mappable onto the API
> that iBATIS would choose, which would probably not be true for many of
> them).
>
> If you're using DBCP, you might be able to your own implementation of
> org.apache.commons.dbcp.ConnectionFactory that creates the temporary tables
> before returning the connection from the createConnection() method.
That might work in case if I need to create those tables/views for each
request for database, which isn't my case. I need to create such views only in
certain cases and don't create them in other cases. If it would be possible to
pass a connection to iBATIS somehow - that would definitely solve my problem
--
Eugene N Dzhurinsky
RE: passing connection to ibatis
Posted by Pa...@cexp.com.
You're only going to want to create temporary tables when the connection is created, not at the beginning of every transaction.
Depending on what kind of connection pool you're using, you may be able to use their connection lifecycle event handler to do this rather than rely on iBATIS to expose this functionality, which it probably can't do for most external pools, anyway (unless it wraps their mechanisms, but that assumes the API each connection pool exposes would be directly mappable onto the API that iBATIS would choose, which would probably not be true for many of them).
If you're using DBCP, you might be able to your own implementation of org.apache.commons.dbcp.ConnectionFactory that creates the temporary tables before returning the connection from the createConnection() method.
-----Original Message-----
From: Eugeny N Dzhurinsky [mailto:bofh@redwerk.com]
Sent: Thursday, September 21, 2006 1:08 AM
To: user-java@ibatis.apache.org
Subject: Re: passing connection to ibatis
On Wed, Sep 20, 2006 at 09:59:12AM -0600, Patrick.Higgins@cexp.com wrote:
> This sounds like it could be solved by a connection lifecycle event handler that Clinton mentioned on Sept. 16th:
>
> http://www.mail-archive.com/user-java@ibatis.apache.org/msg06174.html
>
> Strangely, I've actually needed this functionality before. I created a bunch
> of temporary tables with Postgres and the fact that they didn't persist from
> connection to connection was a major pain, but somehow I worked a connection
> lifecycle event handler into the framework I was using (I can't even
> remember what it was, it's been so long ago now). So I guess we have at
> least two use cases for that feature now. I'll see if I can free up some
> time to write a patch. :-)
Well, I found another possible thing - if I call
SqlMapClient.startTransaction() method, then it is posible to obtain current
connection with SqlMapClient.getCurrentConnection() and do various things, but
I'm not sure will that connection be explicitly released after
SqlMapClient.commitTransation()/endTransaction() or it there is a possibility
to reuse that connection by some other module?
--
Eugene N Dzhurinsky
Re: passing connection to ibatis
Posted by Eugeny N Dzhurinsky <bo...@redwerk.com>.
On Wed, Sep 20, 2006 at 09:59:12AM -0600, Patrick.Higgins@cexp.com wrote:
> This sounds like it could be solved by a connection lifecycle event handler that Clinton mentioned on Sept. 16th:
>
> http://www.mail-archive.com/user-java@ibatis.apache.org/msg06174.html
>
> Strangely, I've actually needed this functionality before. I created a bunch
> of temporary tables with Postgres and the fact that they didn't persist from
> connection to connection was a major pain, but somehow I worked a connection
> lifecycle event handler into the framework I was using (I can't even
> remember what it was, it's been so long ago now). So I guess we have at
> least two use cases for that feature now. I'll see if I can free up some
> time to write a patch. :-)
Well, I found another possible thing - if I call
SqlMapClient.startTransaction() method, then it is posible to obtain current
connection with SqlMapClient.getCurrentConnection() and do various things, but
I'm not sure will that connection be explicitly released after
SqlMapClient.commitTransation()/endTransaction() or it there is a possibility
to reuse that connection by some other module?
--
Eugene N Dzhurinsky
RE: passing connection to ibatis
Posted by Pa...@cexp.com.
This sounds like it could be solved by a connection lifecycle event handler that Clinton mentioned on Sept. 16th:
http://www.mail-archive.com/user-java@ibatis.apache.org/msg06174.html
Strangely, I've actually needed this functionality before. I created a bunch of temporary tables with Postgres and the fact that they didn't persist from connection to connection was a major pain, but somehow I worked a connection lifecycle event handler into the framework I was using (I can't even remember what it was, it's been so long ago now). So I guess we have at least two use cases for that feature now. I'll see if I can free up some time to write a patch. :-)
-----Original Message-----
From: Eugeny N Dzhurinsky [mailto:bofh@redwerk.com]
Sent: Tuesday, September 19, 2006 6:41 AM
To: user-java@ibatis.apache.org
Subject: passing connection to ibatis
Hello!
I have a problem - my application creates temporary views for set of talbes
and then I would like to execute some queries on this view using iBATIS. For
postgresql the temporary view is alife unless the connection is closed, so my
workflow might looks like this:
1) get the connection from pool/whatever
2) create view
3) invoke SQL using iBATIS
4) excplicitly close connection to avoid re-using it by some other module
how can I implement this?
--
Eugene N Dzhurinsky