1 package in.co.daffodil.db.jdbc; 2 3 import javax.sql.*; 4 import java.sql.SQLException ; 5 import java.sql.Connection ; 6 import java.util.Vector ; 7 import java.util.Hashtable ; 8 import com.daffodilwoods.database.resource.*; 9 import com.daffodilwoods.daffodildb.server.serversystem._Connection; 10 11 public class DBPooledConnection implements PooledConnection { 12 13 private Vector connectionEventListeners; 14 protected DBXADataSource dbxaResource; 15 protected Connection connection; 16 protected int client = 0; 17 18 public DBPooledConnection(DBXADataSource dbxaResource0,Connection connection0){ 19 dbxaResource = dbxaResource0; 20 connection = connection0; 21 connectionEventListeners = new Vector (5); 22 } 23 24 public void addConnectionEventListener(ConnectionEventListener pooledConnectionDataSource) { 25 connectionEventListeners.add(pooledConnectionDataSource); 26 } 27 28 public void close() { 29 try { 30 ((DaffodilDBConnection)connection).getServerConnection().commit(); 31 } catch ( Exception except ) { 32 except.printStackTrace(); 33 } 34 } 35 36 public void notifyClose() { 37 ConnectionEvent closeEvent = new ConnectionEvent(this); 38 for(int i=0; i<connectionEventListeners.size(); i++) { 39 ConnectionEventListener connEvntLst = (ConnectionEventListener)connectionEventListeners.get(i); 40 connEvntLst.connectionClosed(closeEvent); 41 } 42 } 43 44 public Connection getConnection() throws SQLException { 45 connection.setAutoCommit(true); 46 DBClientConnection con = new DBClientConnection(this,connection); 47 return con; 48 } 49 50 public void removeConnectionEventListener(ConnectionEventListener pooledConnectionDataSource ) { 51 connectionEventListeners.remove(pooledConnectionDataSource); 52 ConnectionEvent closeEvent = new ConnectionEvent(this); 53 pooledConnectionDataSource.connectionClosed(closeEvent); 54 } 55 public boolean inGlobatTransaction() { 56 return dbxaResource.inGlobalTransaction(); 57 } 58 } 59 | Popular Tags |