1 10 11 package com.triactive.jdo.test; 12 13 import javax.sql.DataSource ; 14 import org.apache.commons.pool.ObjectPool; 15 import org.apache.commons.pool.impl.GenericObjectPool; 16 import org.apache.commons.dbcp.ConnectionFactory; 17 import org.apache.commons.dbcp.PoolingDataSource; 18 import org.apache.commons.dbcp.PoolableConnectionFactory; 19 import org.apache.commons.dbcp.DriverManagerConnectionFactory; 20 import org.apache.log4j.Category; 21 22 23 29 30 public class DBCPDataSourceFactory implements PersistenceTestCase.DataSourceFactory 31 { 32 private static final Category LOG = Category.getInstance(PersistenceTestCase.class); 33 34 public DataSource makePooledDataSource(String dbDriver, 35 String dbURL, 36 String dbUser, 37 String dbPassword) throws Exception 38 { 39 Class.forName(dbDriver); 40 41 ObjectPool connectionPool = new GenericObjectPool(null); 42 43 ConnectionFactory connectionFactory = 44 new DriverManagerConnectionFactory(dbURL, dbUser, dbPassword); 45 46 PoolableConnectionFactory poolableConnectionFactory = 47 new PoolableConnectionFactory(connectionFactory, connectionPool, null, null, false, true); 48 49 DataSource ds = new PoolingDataSource(connectionPool); 50 51 LOG.info("Connection pool initialized: " + connectionPool); 52 53 return ds; 54 } 55 } 56 | Popular Tags |