KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > dbcp > DataSourceConnectionFactory


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.commons.dbcp;
18
19 import java.sql.Connection JavaDoc;
20 import java.sql.SQLException JavaDoc;
21 import javax.sql.DataSource JavaDoc;
22
23 /**
24  * A {@link DataSource}-based implementation of {@link ConnectionFactory}.
25  *
26  * @author Rodney Waldhoff
27  * @version $Revision: 1.7 $ $Date: 2004/02/28 12:18:17 $
28  */

29 public class DataSourceConnectionFactory implements ConnectionFactory {
30     public DataSourceConnectionFactory(DataSource JavaDoc source) {
31         this(source,null,null);
32     }
33
34     public DataSourceConnectionFactory(DataSource JavaDoc source, String JavaDoc uname, String JavaDoc passwd) {
35         _source = source;
36         _uname = uname;
37         _passwd = passwd;
38     }
39
40     public Connection JavaDoc createConnection() throws SQLException JavaDoc {
41         if(null == _uname && null == _passwd) {
42             return _source.getConnection();
43         } else {
44             return _source.getConnection(_uname,_passwd);
45         }
46     }
47
48     protected String JavaDoc _uname = null;
49     protected String JavaDoc _passwd = null;
50     protected DataSource JavaDoc _source = null;
51 }
52
Popular Tags