1 16 17 package org.apache.commons.dbcp; 18 19 import java.sql.Connection ; 20 import java.sql.SQLException ; 21 import javax.sql.DataSource ; 22 23 29 public class DataSourceConnectionFactory implements ConnectionFactory { 30 public DataSourceConnectionFactory(DataSource source) { 31 this(source,null,null); 32 } 33 34 public DataSourceConnectionFactory(DataSource source, String uname, String passwd) { 35 _source = source; 36 _uname = uname; 37 _passwd = passwd; 38 } 39 40 public Connection createConnection() throws SQLException { 41 if(null == _uname && null == _passwd) { 42 return _source.getConnection(); 43 } else { 44 return _source.getConnection(_uname,_passwd); 45 } 46 } 47 48 protected String _uname = null; 49 protected String _passwd = null; 50 protected DataSource _source = null; 51 } 52 | Popular Tags |