00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 package org.objectweb.jonas.jdbc_xa;
00028
00029 import java.sql.Connection;
00030 import java.sql.SQLException;
00031 import java.util.Vector;
00032 import javax.transaction.xa.XAResource;
00033 import javax.sql.ConnectionEvent;
00034 import javax.sql.ConnectionEventListener;
00035 import javax.sql.XAConnection;
00036 import org.objectweb.jonas.common.Log;
00037 import org.objectweb.util.monolog.api.Logger;
00038 import org.objectweb.util.monolog.api.BasicLevel;
00039
00050 class XAConnectionImpl implements XAConnection {
00051
00052 static private Logger logger = null;
00053
00054 XAResource xaRes = null;
00055 Connection implConn = null;
00056 Connection actConn = null;
00057 Vector eventListeners = new Vector();
00058
00059
00060
00061
00062
00063 public XAConnectionImpl(Connection conn, XADataSourceImpl ds) {
00064
00065 this.actConn = conn;
00066
00067
00068 this.implConn = new ConnectionImpl(this, conn);
00069 this.xaRes = new XAResourceImpl(this, conn, ds);
00070 logger = Log.getLogger(Log.JONAS_JDBCXA_PREFIX);
00071 logger.log(BasicLevel.DEBUG, "constructor");
00072 }
00073
00074
00075
00076
00077
00085 public XAResource getXAResource() throws SQLException {
00086 return xaRes;
00087 }
00088
00089
00090
00091
00092
00098 public Connection getConnection() throws SQLException {
00099
00100
00101 return implConn;
00102 }
00103
00109 public void close() throws SQLException {
00110
00111 logger.log(BasicLevel.DEBUG, "");
00112
00113
00114 if (actConn != null) {
00115 actConn.close();
00116 } else {
00117 logger.log(BasicLevel.ERROR, "Connection already closed");
00118 }
00119 actConn = null;
00120
00121
00122 xaRes = null;
00123 implConn = null;
00124 }
00125
00131 public void addConnectionEventListener(ConnectionEventListener listener) {
00132
00133 logger.log(BasicLevel.DEBUG, "");
00134 eventListeners.addElement(listener);
00135 }
00136
00142 public void removeConnectionEventListener(ConnectionEventListener listener) {
00143
00144 logger.log(BasicLevel.DEBUG, "");
00145 eventListeners.removeElement(listener);
00146 }
00147
00148
00149
00150
00151
00152
00153
00154
00155 public void notifyClose() {
00156
00157 logger.log(BasicLevel.DEBUG, "");
00158
00159
00160 for (int i = 0; i < eventListeners.size(); i++) {
00161 ConnectionEventListener l = (ConnectionEventListener) eventListeners.elementAt(i);
00162 l.connectionClosed(new ConnectionEvent(this));
00163 }
00164 }
00165
00166
00167
00168
00169 public void notifyError(SQLException ex) {
00170
00171 logger.log(BasicLevel.DEBUG, "");
00172
00173
00174 for (int i = 0; i < eventListeners.size(); i++) {
00175 ConnectionEventListener l = (ConnectionEventListener) eventListeners.elementAt(i);
00176 l.connectionErrorOccurred(new ConnectionEvent(this, ex));
00177 }
00178 }
00179
00180
00181 }