01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package org.apache.commons.dbcp;
19:
20: import java.sql.Connection;
21: import java.sql.SQLException;
22: import javax.sql.DataSource;
23:
24: /**
25: * A {@link DataSource}-based implementation of {@link ConnectionFactory}.
26: *
27: * @author Rodney Waldhoff
28: * @version $Revision: 479137 $ $Date: 2006-11-25 08:51:48 -0700 (Sat, 25 Nov 2006) $
29: */
30: public class DataSourceConnectionFactory implements ConnectionFactory {
31: public DataSourceConnectionFactory(DataSource source) {
32: this (source, null, null);
33: }
34:
35: public DataSourceConnectionFactory(DataSource source, String uname,
36: String passwd) {
37: _source = source;
38: _uname = uname;
39: _passwd = passwd;
40: }
41:
42: public Connection createConnection() throws SQLException {
43: if (null == _uname && null == _passwd) {
44: return _source.getConnection();
45: } else {
46: return _source.getConnection(_uname, _passwd);
47: }
48: }
49:
50: protected String _uname = null;
51: protected String _passwd = null;
52: protected DataSource _source = null;
53: }
|