01: /*
02: * Copyright 2003 (C) TJDO.
03: * All rights reserved.
04: *
05: * This software is distributed under the terms of the TJDO License version 1.0.
06: * See the terms of the TJDO License in the documentation provided with this software.
07: *
08: * $Id: DBCPDataSourceFactory.java,v 1.1 2003/02/17 07:16:14 jackknifebarber Exp $
09: */
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: * Makes DataSources whose DB connections are pooled using Jakarta DBCP.
24: *
25: * @author <a href="mailto:mmartin5@austin.rr.com">Mike Martin</a>
26: * @version $Revision: 1.1 $
27: */
28:
29: public class DBCPDataSourceFactory implements
30: PersistenceTestCase.DataSourceFactory {
31: private static final Category LOG = Category
32: .getInstance(PersistenceTestCase.class);
33:
34: public DataSource makePooledDataSource(String dbDriver,
35: String dbURL, String dbUser, String dbPassword)
36: throws Exception {
37: Class.forName(dbDriver);
38:
39: ObjectPool connectionPool = new GenericObjectPool(null);
40:
41: ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(
42: dbURL, dbUser, dbPassword);
43:
44: PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(
45: connectionFactory, connectionPool, null, null, false,
46: true);
47:
48: DataSource ds = new PoolingDataSource(connectionPool);
49:
50: LOG.info("Connection pool initialized: " + connectionPool);
51:
52: return ds;
53: }
54: }
|