KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cayenne > conn > PoolDataSource


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

19
20
21 package org.apache.cayenne.conn;
22
23 import java.io.PrintWriter JavaDoc;
24 import java.sql.SQLException JavaDoc;
25
26 import javax.sql.ConnectionPoolDataSource JavaDoc;
27 import javax.sql.DataSource JavaDoc;
28 import javax.sql.PooledConnection JavaDoc;
29
30 /**
31  * <p>PoolDataSource allows to generate pooled connections.</p>
32  *
33  * <p>It is implemented as a wrapper around a non-pooled data source object.
34  * Delegates all method calls except for "getPooledConnection" to the underlying
35  * datasource.
36  * </p>
37  *
38  * @author Andrus Adamchik
39  */

40 public class PoolDataSource implements ConnectionPoolDataSource JavaDoc {
41     private DataSource JavaDoc nonPooledDatasource;
42
43     /** Creates new PoolDataSource */
44     public PoolDataSource(DataSource JavaDoc nonPooledDatasource) {
45         this.nonPooledDatasource = nonPooledDatasource;
46     }
47
48     public PoolDataSource(String JavaDoc jdbcDriver, String JavaDoc connectionUrl) throws SQLException JavaDoc {
49         nonPooledDatasource = new DriverDataSource(jdbcDriver, connectionUrl);
50     }
51
52     public int getLoginTimeout() throws SQLException JavaDoc {
53         return nonPooledDatasource.getLoginTimeout();
54     }
55
56     public void setLoginTimeout(int seconds) throws SQLException JavaDoc {
57         nonPooledDatasource.setLoginTimeout(seconds);
58     }
59
60     public PrintWriter JavaDoc getLogWriter() throws SQLException JavaDoc {
61         return nonPooledDatasource.getLogWriter();
62     }
63
64     public void setLogWriter(PrintWriter JavaDoc out) throws SQLException JavaDoc {
65         nonPooledDatasource.setLogWriter(out);
66     }
67
68     public PooledConnection JavaDoc getPooledConnection() throws SQLException JavaDoc {
69         return new PooledConnectionImpl(nonPooledDatasource, null, null);
70     }
71
72     public PooledConnection JavaDoc getPooledConnection(String JavaDoc user, String JavaDoc password) throws SQLException JavaDoc {
73         return new PooledConnectionImpl(nonPooledDatasource, user, password);
74     }
75 }
76
Popular Tags