dbcp configuration

125 views
Skip to first unread message

Jamie

unread,
Apr 22, 2013, 9:48:41 AM4/22/13
to mybati...@googlegroups.com
Currently working on upgrading ibatis to Mybatis, not using Spring or Guice, and I'm having an issue recreating a connection of type DBCP.  I understand there are new datasource types in mybatis (unpooled, pooled, jndi) but would like the option to use DBCP if possible for comparing performance between the two in mybatis.  There have been several posts in mybatis-user either mentioning the use of DBCP or asking about it, I'm hoping someone can point me in the right direction.  I've tried passing in various dbcp datasource factories in my configuration file without any luck.  I did find an implementation for Guice (org.mybatis.guice.datasource.dbcp.SharedPoolDataSourceProvider), but was unable to find anything for mybatis without Guice.

Has anyone successfully set up a dbcp connection without Spring or Guice?  Could you post an example of your configuration?  Or do I have to build my own Provider as was done for Guice?

Here's my old configuration from ibatis

    <transactionManager type="JDBC" commitRequired="false">
        <dataSource type="DBCP">
            <property name="driverClassName" value="${driver}" />
            <property name="url" value="${url}" />
            <property name="username" value="${username}" />
            <property name="password" value="${password}" />
            <property name="defaultAutoCommit" value="false" />
            <property name="maxActive" value="20"/>
            <property name="maxIdle" value="0"/>          
            <property name="maxWait" value="30000"/>
            <property name="validationQuery" value="select 1 from sysibm.sysdummy1 with ur"/>          
            <property name="minIdle" value="0"/>
            <property name="timeBetweenEvictionRunsMillis" value="300000"/>
            <property name="numTestsPerEvictionRun" value="5"/>
            <property name="minEvictableIdleTimeMillis" value="900000"/>       
        </dataSource>
    </transactionManager>



Eduardo Macarron

unread,
Apr 23, 2013, 2:14:27 AM4/23/13
to mybatis-user
Hi Jaimie,

Plugging a new datasource is quite easy. For your case it would be
just porting this code:

https://github.com/mybatis/mybatis-2/blob/master/src/main/java/com/ibatis/common/jdbc/DbcpConfiguration.java

To a bean similar to this one:

https://github.com/mybatis/mybatis-3/blob/master/src/main/java/org/apache/ibatis/datasource/unpooled/UnpooledDataSourceFactory.java

And write a test. For example the base test using dbcp instead of unpooled:

https://code.google.com/p/mybatis/wiki/Test

And we will be more than happy to accept a contribution.


2013/4/22 Jamie <monkeyme...@gmail.com>:
> --
> You received this message because you are subscribed to the Google Groups
> "mybatis-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to mybatis-user...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Eduardo

unread,
Mar 18, 2014, 5:19:30 PM3/18/14
to mybati...@googlegroups.com
BTW. I know this mail is very old but just in case it is useful. Setting DBCP is just adding this adapter:

import org.apache.commons.dbcp.BasicDataSource;
import org.apache.ibatis.datasource.unpooled.UnpooledDataSourceFactory;

public class DbcpDataSourceFactory extends UnpooledDataSourceFactory {

  public DbcpDataSourceFactory() {
    this.dataSource = new BasicDataSource();
  }
}

I have just included a paragraph in the docs to explain a bit more how to plug a 3rd party datasource.
Reply all
Reply to author
Forward
0 new messages