changing lock bucket size
[csql.git] / src / jdbc / JdbcSqlPooledConnection.java
blob09f093bec648c250826b47586729d59933f56127
1 package csql.jdbc;
3 import java.util.*;
4 import java.sql.*;
5 import javax.sql.*;
6 import javax.naming.*;
7 import java.io.*;
8 import java.lang.*;
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;
29 //Constructor
30 public JdbcSqlPooledConnection(Connection connection) {
31 logicalConn = null;
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");
63 isclose = true;
66 /* if(isclose != true || logicalConn != null){
67 isclose = true;
68 logicalConn.rollback();
69 eventListentionMethod(true,null);
70 }*/
71 logicalConn = JdbcSqlConnectionWrapper.getInstance(this,physicalConn);
72 isclose = false;
73 return logicalConn;
76 //Pooled connection method.
77 public synchronized void close() throws SQLException {
78 if (physicalConn != null) {
79 physicalConn.close();
80 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();
96 if (isclose) {
97 conEventListener.connectionClosed(conEvent);
98 } else {
99 conEventListener.connectionErrorOccurred(conEvent);
105 public void addStatementEventListener(StatementEventListener listener) {
106 //part of JDBC4
110 public void removeStatementEventListener(StatementEventListener listener) {
111 //part of JDBC4