9 import java
.lang
.Class
;
11 public class JdbcSqlPooledConnection
implements javax
.sql
.PooledConnection
14 //To store the connection Event Listions Hash manner for faster access
15 private Map connectionEventListeners
;
18 // logical connection for connenction pool
19 private Connection logicalConn
;
22 // Actual or physical connection
23 private JdbcSqlConnection physicalConn
;
26 //says logical connection open or close
27 boolean isclose
= true;
30 public JdbcSqlPooledConnection(Connection connection
) {
32 physicalConn
=(JdbcSqlConnection
) connection
;
33 connectionEventListeners
= new HashMap();
39 //Pooled connection methods. Here connection event listener is insert into hashed map.
40 public synchronized void addConnectionEventListener(ConnectionEventListener conEventListener
)
42 if(connectionEventListeners
!= null)
43 connectionEventListeners
.put(conEventListener
,conEventListener
);
48 //Pooled connection method. Here the connection event listioner is removed from hash map
49 public synchronized void removeConnectionEventListener(ConnectionEventListener conEventListener
)
51 if(connectionEventListeners
!= null)
52 connectionEventListeners
.remove(conEventListener
);
58 //Pooled connection method.
59 public synchronized Connection
getConnection() throws SQLException
62 if (physicalConn
== null) {
63 System
.out
.println("Connection not Exit");
67 if(isclose
!= true || logicalConn
!= null){
69 logicalConn
.rollback();
70 eventListentionMethod(true,null);
72 logicalConn
= (Connection
)physicalConn
;
74 } catch (SQLException exception
){
75 eventListentionMethod(false,exception
);
82 //Pooled connection method.
83 public synchronized void close() throws SQLException
{
84 if (physicalConn
!= null) {
88 if (connectionEventListeners
!= null) {
89 connectionEventListeners
.clear();
90 connectionEventListeners
= null;
95 synchronized void eventListentionMethod(boolean isclose
,SQLException sqlException
) {
96 if(connectionEventListeners
== null){ return; }
97 Iterator iterater
= connectionEventListeners
.entrySet().iterator();
99 ConnectionEvent conEvent
= new ConnectionEvent(this,sqlException
);
100 while (iterater
.hasNext()) {
101 ConnectionEventListener conEventListener
= (ConnectionEventListener
) ((Map
.Entry
)iterater
.next()).getValue();
103 conEventListener
.connectionClosed(conEvent
);
105 conEventListener
.connectionErrorOccurred(conEvent
);
111 public void addStatementEventListener(StatementEventListener listener
) {
116 public void removeStatementEventListener(StatementEventListener listener
) {