1 25 26 27 package org.objectweb.jonas.jdbc_xa; 28 29 import java.sql.Connection ; 30 import java.sql.SQLException ; 31 import java.util.Vector ; 32 import javax.transaction.xa.XAResource ; 33 import javax.sql.ConnectionEvent ; 34 import javax.sql.ConnectionEventListener ; 35 import javax.sql.XAConnection ; 36 import org.objectweb.jonas.common.Log; 37 import org.objectweb.util.monolog.api.Logger; 38 import org.objectweb.util.monolog.api.BasicLevel; 39 40 49 50 class XAConnectionImpl implements XAConnection { 51 52 static private Logger logger = null; 53 54 XAResource xaRes = null; 55 Connection implConn = null; 56 Connection actConn = null; 57 Vector eventListeners = new Vector (); 58 59 63 public XAConnectionImpl(Connection conn, XADataSourceImpl ds) { 64 65 this.actConn = conn; 66 67 this.implConn = new ConnectionImpl(this, conn); 69 this.xaRes = new XAResourceImpl(this, conn, ds); 70 logger = Log.getLogger(Log.JONAS_JDBCXA_PREFIX); 71 if (logger.isLoggable(BasicLevel.DEBUG)) { 72 logger.log(BasicLevel.DEBUG, "constructor"); 73 } 74 } 75 76 80 87 public XAResource getXAResource() throws SQLException { 88 return xaRes; 89 } 90 91 95 100 public Connection getConnection() throws SQLException { 101 102 return implConn; 104 } 105 106 111 public void close() throws SQLException { 112 113 if (logger.isLoggable(BasicLevel.DEBUG)) { 114 logger.log(BasicLevel.DEBUG, ""); 115 } 116 117 if (actConn != null) { 119 actConn.close(); 120 } else { 121 logger.log(BasicLevel.ERROR, "Connection already closed"); 122 } 123 actConn = null; 124 125 xaRes = null; 127 implConn = null; 128 } 129 130 135 public void addConnectionEventListener(ConnectionEventListener listener) { 136 137 if (logger.isLoggable(BasicLevel.DEBUG)) { 138 logger.log(BasicLevel.DEBUG, ""); 139 } 140 eventListeners.addElement(listener); 141 } 142 143 148 public void removeConnectionEventListener(ConnectionEventListener listener) { 149 150 if (logger.isLoggable(BasicLevel.DEBUG)) { 151 logger.log(BasicLevel.DEBUG, ""); 152 } 153 eventListeners.removeElement(listener); 154 } 155 156 160 163 public void notifyClose() { 164 165 if (logger.isLoggable(BasicLevel.DEBUG)) { 166 logger.log(BasicLevel.DEBUG, ""); 167 } 168 169 for (int i = 0; i < eventListeners.size(); i++) { 171 ConnectionEventListener l = (ConnectionEventListener ) eventListeners.elementAt(i); 172 l.connectionClosed(new ConnectionEvent (this)); 173 } 174 } 175 176 179 public void notifyError(SQLException ex) { 180 181 if (logger.isLoggable(BasicLevel.DEBUG)) { 182 logger.log(BasicLevel.DEBUG, ""); 183 } 184 185 for (int i = 0; i < eventListeners.size(); i++) { 187 ConnectionEventListener l = (ConnectionEventListener ) eventListeners.elementAt(i); 188 l.connectionErrorOccurred(new ConnectionEvent (this, ex)); 189 } 190 } 191 192 193 } 194 | Popular Tags |