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
61 if (physicalConn
== null) {
62 System
.out
.println("Connection not Exit");
66 /* if(isclose != true || logicalConn != null){
68 logicalConn.rollback();
69 eventListentionMethod(true,null);
71 logicalConn
= JdbcSqlConnectionWrapper
.getInstance(this,physicalConn
);
76 //Pooled connection method.
77 public synchronized void close() throws SQLException
{
78 if (physicalConn
!= null) {
82 if (connectionEventListeners
!= null) {
83 connectionEventListeners
.clear();
84 connectionEventListeners
= null;
89 public synchronized void eventListentionMethod(boolean isclose
,SQLException sqlException
) {
90 if(connectionEventListeners
== null){ return; }
91 Iterator iterater
= connectionEventListeners
.entrySet().iterator();
93 ConnectionEvent conEvent
= new ConnectionEvent(this,sqlException
);
94 while (iterater
.hasNext()) {
95 ConnectionEventListener conEventListener
= (ConnectionEventListener
) ((Map
.Entry
)iterater
.next()).getValue();
97 conEventListener
.connectionClosed(conEvent
);
99 conEventListener
.connectionErrorOccurred(conEvent
);
105 public void addStatementEventListener(StatementEventListener listener
) {
110 public void removeStatementEventListener(StatementEventListener listener
) {