1 29 30 package com.caucho.db.jdbc; 31 32 import com.caucho.db.Database; 33 import com.caucho.util.L10N; 34 35 import javax.sql.ConnectionEvent ; 36 import javax.sql.ConnectionEventListener ; 37 import javax.sql.PooledConnection ; 38 import java.sql.Connection ; 39 import java.sql.SQLException ; 40 import java.util.ArrayList ; 41 42 45 class PooledConnectionImpl implements PooledConnection { 46 private final static L10N L = new L10N(PooledConnectionImpl.class); 47 48 private final Database _db; 49 50 private ArrayList <ConnectionEventListener > _listeners = 51 new ArrayList <ConnectionEventListener >(); 52 53 private boolean _isClosed; 54 55 PooledConnectionImpl(Database db) 56 { 57 _db = db; 58 59 if (_db == null) 60 throw new NullPointerException (); 61 } 62 63 66 Database getDatabase() 67 { 68 return _db; 69 } 70 71 74 public Connection getConnection() 75 throws SQLException 76 { 77 if (_isClosed) 78 throw new IllegalStateException (L.l("getting connection after close")); 79 80 82 return new ConnectionImpl(this); 83 } 84 85 88 public void addConnectionEventListener(ConnectionEventListener listener) 89 { 90 if (! _listeners.contains(listener)) 91 _listeners.add(listener); 92 } 93 94 97 public void removeConnectionEventListener(ConnectionEventListener listener) 98 { 99 _listeners.remove(listener); 100 } 101 102 void closeEvent(Connection conn) 103 { 104 ConnectionEvent event = new ConnectionEvent (this); 105 106 for (int i = 0; i < _listeners.size(); i++) { 107 ConnectionEventListener listener = _listeners.get(i); 108 109 listener.connectionClosed(event); 110 } 111 } 112 113 public void close() 114 throws SQLException 115 { 116 _isClosed = true; 117 } 118 } 119 | Popular Tags |