mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
add xa support
This commit is contained in:
@@ -28,24 +28,23 @@ public class DruidAXDataSource extends DruidDataSource implements XADataSource {
|
||||
|
||||
Connection physicalConn = conn.unwrap(Connection.class);
|
||||
|
||||
XAConnection rawXAConnection;
|
||||
if (JdbcUtils.ORACLE.equals(dbType)) {
|
||||
try {
|
||||
return OracleUtils.OracleXAConnection(physicalConn);
|
||||
rawXAConnection = OracleUtils.OracleXAConnection(physicalConn);
|
||||
} catch (XAException xae) {
|
||||
LOG.error("create xaConnection error", xae);
|
||||
return null;
|
||||
}
|
||||
} else if (JdbcUtils.MYSQL.equals(dbType)) {
|
||||
rawXAConnection = MySqlUtils.createXAConnection(physicalConn);
|
||||
} else if (JdbcUtils.POSTGRESQL.equals(dbType)) {
|
||||
rawXAConnection = PGUtils.createXAConnection(physicalConn);
|
||||
} else {
|
||||
throw new SQLException("xa not support dbType : " + this.dbType);
|
||||
}
|
||||
|
||||
if (JdbcUtils.MYSQL.equals(dbType)) {
|
||||
return MySqlUtils.createXAConnection(physicalConn);
|
||||
}
|
||||
|
||||
if (JdbcUtils.POSTGRESQL.equals(dbType)) {
|
||||
return PGUtils.createXAConnection(physicalConn);
|
||||
}
|
||||
|
||||
throw new SQLException("xa not support dbType : " + this.dbType);
|
||||
return new DruidPooledXAConnection(conn, rawXAConnection);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.alibaba.druid.pool.xa;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import javax.sql.ConnectionEventListener;
|
||||
import javax.sql.StatementEventListener;
|
||||
import javax.sql.XAConnection;
|
||||
import javax.transaction.xa.XAResource;
|
||||
|
||||
import com.alibaba.druid.pool.DruidPooledConnection;
|
||||
|
||||
public class DruidPooledXAConnection implements XAConnection {
|
||||
|
||||
private DruidPooledConnection pooledConnection;
|
||||
private XAConnection xaConnection;
|
||||
|
||||
public DruidPooledXAConnection(DruidPooledConnection pooledConnection, XAConnection xaConnection){
|
||||
this.pooledConnection = pooledConnection;
|
||||
this.xaConnection = xaConnection;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection getConnection() throws SQLException {
|
||||
return pooledConnection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws SQLException {
|
||||
pooledConnection.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addConnectionEventListener(ConnectionEventListener listener) {
|
||||
pooledConnection.addConnectionEventListener(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeConnectionEventListener(ConnectionEventListener listener) {
|
||||
pooledConnection.removeConnectionEventListener(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addStatementEventListener(StatementEventListener listener) {
|
||||
pooledConnection.addStatementEventListener(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeStatementEventListener(StatementEventListener listener) {
|
||||
pooledConnection.removeStatementEventListener(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public XAResource getXAResource() throws SQLException {
|
||||
return xaConnection.getXAResource();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user