KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jodd > db > pool > CpdsPool


1 package jodd.db.pool;
2
3 import java.sql.Connection;
4 import java.sql.SQLException;
5
6 import javax.sql.ConnectionPoolDataSource;
7 import javax.sql.PooledConnection;
8
9 /**
10  * Wrapper arroung ConnectionPoolDataSource implementation.
11  */

12 public class CpdsPool implements ConnectionPool {
13
14     // ---------------------------------------------------------------- properties
15

16     private ConnectionPoolDataSource cpds;
17     public void setPool(ConnectionPoolDataSource p) {
18         cpds = p;
19     }
20
21     // ---------------------------------------------------------------- init/close
22

23     public void init() throws SQLException {
24         if (cpds == null) {
25             throw new SQLException("ConnectionPoolDataSource not specified");
26         }
27     }
28
29     public void close() {
30         cpds = null;
31     }
32
33     // ---------------------------------------------------------------- get/free
34

35     public Connection getConnection() throws SQLException {
36         PooledConnection pconn = cpds.getPooledConnection();
37         return pconn.getConnection();
38     }
39
40     public void freeConnection(Connection conn) {
41         try {
42             if (conn != null) {
43                 conn.close();
44             }
45         } catch (SQLException e) {
46         }
47     }
48
49 }
50
51
Popular Tags