type was not being initialized since the else part was also commented
[csql/przemoc.git] / src / jdbc / JdbcSqlPooledConnection.java
blobc484dca15d7d9a19b213fee5bdc2188d0c154d76
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 try{
62 if (physicalConn == null) {
63 System.out.println("Connection not Exit");
64 isclose = true;
67 if(isclose != true || logicalConn != null){
68 isclose = true;
69 logicalConn.rollback();
70 eventListentionMethod(true,null);
72 logicalConn = (Connection)physicalConn;
73 isclose = false;
74 } catch (SQLException exception){
75 eventListentionMethod(false,exception);
76 throw exception;
79 return logicalConn;
82 //Pooled connection method.
83 public synchronized void close() throws SQLException {
84 if (physicalConn != null) {
85 physicalConn.close();
86 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();
102 if (isclose) {
103 conEventListener.connectionClosed(conEvent);
104 } else {
105 conEventListener.connectionErrorOccurred(conEvent);
111 public void addStatementEventListener(StatementEventListener listener) {
112 //part of JDBC4
116 public void removeStatementEventListener(StatementEventListener listener) {
117 //part of JDBC4