1 3 package jodd.db.connection; 4 5 import jodd.db.DbSqlException; 6 7 import javax.sql.ConnectionPoolDataSource ; 8 import javax.sql.PooledConnection ; 9 import java.sql.Connection ; 10 import java.sql.SQLException ; 11 12 15 public class ConnectionPoolDataSourceConnectionProvider implements ConnectionProvider { 16 18 private ConnectionPoolDataSource cpds; 19 20 public ConnectionPoolDataSourceConnectionProvider(ConnectionPoolDataSource cpds) { 21 this.cpds = cpds; 22 } 23 24 26 public void init() { 27 } 28 29 public void close() { 30 cpds = null; 31 } 32 33 35 public Connection getConnection() { 36 PooledConnection pconn; 37 try { 38 pconn = cpds.getPooledConnection(); 39 } catch (SQLException sex) { 40 throw new DbSqlException("Unable to get pooled connection.", sex); 41 } 42 try { 43 return pconn.getConnection(); 44 } catch (SQLException sex) { 45 throw new DbSqlException("Unable to get connection from pooled connection.", sex); 46 } 47 } 48 49 public void closeConnection(Connection conn) { 50 try { 51 if (conn != null) { 52 conn.close(); 53 } 54 } catch (SQLException sex) { 55 } 57 } 58 } 59 | Popular Tags |