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 Carl Brodeur <ca...@modelio.com> on 2005/01/06 18:41:46 UTC

Connections

Hi:

Would like to know how Ibatis releases or close its connections.  I use 
a JNDI datasource type (connection pool).  I look at the debug trace, 
see when connection are requested but not when they are released.

Can someone help ?








Re: Connections

Posted by Clinton Begin <cl...@gmail.com>.
Well, I we don't log any such information, so this would mostly have
to do with your DataSource implementation.  It has little to do with
iBATIS.

We simply call DataSource.getConnection() and Connection.close().

No magic.

Clinton


On Thu,  6 Jan 2005 12:41:46 -0500, Carl Brodeur
<ca...@modelio.com> wrote:
> 
> Hi:
> 
> Would like to know how Ibatis releases or close its connections.  I use
> a JNDI datasource type (connection pool).  I look at the debug trace,
> see when connection are requested but not when they are released.
> 
> Can someone help ?
> 
>

Re: Connections

Posted by Clinton Begin <cl...@gmail.com>.
When it comes to connection pools, it's the responsibility of each
pool to ensure that their connections are closed.  iBATIS can't do
much in this regard. I suggest you enforce a manual shutdown policy
for your datasources, as simply shutting down a JVM (i.e. service)
won't cut it.

If you're using iBATIS SimpleDataSource, you can call .forceCloseAll()
to release all Connection resources.  For any other DataSource
implementation, you'll need to check the docs (it's non-standard
behavior).

Cheers,
Clinton


On Fri, 07 Jan 2005 10:24:52 +0530, Vamsee Kanakala <va...@gmail.com> wrote:
> Carl Brodeur wrote:
> 
> >Would like to know how Ibatis releases or close its connections.  I use
> >a JNDI datasource type (connection pool).  I look at the debug trace,
> >see when connection are requested but not when they are released.
> >
> >
> >
> I have a similar problem. I am using sqlmaps only, and I'm getting the
> datasource connection from the container itself, like this:
> 
> public class BatsSqlConfig {
>     private static final SqlMapClient sqlMap;
> 
>     static {
>         try {
>             String resource = "com/mafoi/bats/sql-map-config.xml";
>             Reader reader = Resources.getResourceAsReader(resource);
>             sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);
>         } catch (Exception e){
>             e.printStackTrace();
>             throw new RuntimeException("Init error: BatsSqlConfig class.
> cause: " + e);
>         }
>     }
> 
>     public static SqlMapClient getSqlMapInstance() {
>         return sqlMap;
>     }
> }
> 
> And, I'm using the code like this:
> 
> public class LoginBean {
> 
>     SqlMapClient sqlMap;
> 
>     public LoginBean() {
>         sqlMap = BatsSqlConfig.getSqlMapInstance();
>     }
> 
>     public User getUser(String userName, String password) throws
> SQLException {
> 
>         return (User)sqlMap.queryForObject("getUser",
> userName);
>     }
> }
> 
> But, I'm using Tomcat Ant tasks to stop and start the container. I get
> the feeling that the connections are not closed, because 2 developer
> machines (linux) just hung after doing a few start/stops of the
> application inside Tomcat. It never happened before, while we used to
> shutdown tomcat fully before deploying the application again. How can I
> make sure that the PoolableConnection objects are actually released
> before I restart the application in Tomcat?
> 
> TIA,
> Vamsee.
>

Re: Connections

Posted by Vamsee Kanakala <va...@gmail.com>.
Carl Brodeur wrote:

>Would like to know how Ibatis releases or close its connections.  I use 
>a JNDI datasource type (connection pool).  I look at the debug trace, 
>see when connection are requested but not when they are released.
>
>  
>
I have a similar problem. I am using sqlmaps only, and I'm getting the 
datasource connection from the container itself, like this:

public class BatsSqlConfig {
    private static final SqlMapClient sqlMap;
   
    static {
        try {
            String resource = "com/mafoi/bats/sql-map-config.xml";
            Reader reader = Resources.getResourceAsReader(resource);
            sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);
        } catch (Exception e){
            e.printStackTrace();
            throw new RuntimeException("Init error: BatsSqlConfig class. 
cause: " + e);
        }
    }
   
    public static SqlMapClient getSqlMapInstance() {
        return sqlMap;
    }
}

And, I'm using the code like this:

public class LoginBean {

 
    SqlMapClient sqlMap;
      
    public LoginBean() {
        sqlMap = BatsSqlConfig.getSqlMapInstance();
    }

    public User getUser(String userName, String password) throws 
SQLException {       

        return (User)sqlMap.queryForObject("getUser", 
userName);                               
    }
}

But, I'm using Tomcat Ant tasks to stop and start the container. I get 
the feeling that the connections are not closed, because 2 developer 
machines (linux) just hung after doing a few start/stops of the 
application inside Tomcat. It never happened before, while we used to 
shutdown tomcat fully before deploying the application again. How can I 
make sure that the PoolableConnection objects are actually released 
before I restart the application in Tomcat?

TIA,
Vamsee.

Re: Connections

Posted by Brandon Goodin <br...@gmail.com>.
Depends on your configuration. First, i would suggest you read the
sqlmap and/or dao manual. Then, if you do not see the answer there go
ahead and post your dao and/or sqlmap configs along with a sample of
how you are calling the code.

Brandon


On Thu,  6 Jan 2005 12:41:46 -0500, Carl Brodeur
<ca...@modelio.com> wrote:
> 
> Hi:
> 
> Would like to know how Ibatis releases or close its connections.  I use
> a JNDI datasource type (connection pool).  I look at the debug trace,
> see when connection are requested but not when they are released.
> 
> Can someone help ?
> 
>