mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
xa support
This commit is contained in:
@@ -6,9 +6,10 @@ import oracle.jdbc.internal.OracleConnection;
|
||||
|
||||
public class DruidXAOracleException extends XAException {
|
||||
|
||||
private int xaError = 0;
|
||||
private int primary = 0;
|
||||
private int secondary = 0;
|
||||
private static final long serialVersionUID = 1L;
|
||||
private int xaError = 0;
|
||||
private int primary = 0;
|
||||
private int secondary = 0;
|
||||
|
||||
public DruidXAOracleException(){
|
||||
}
|
||||
@@ -40,6 +41,14 @@ public class DruidXAOracleException extends XAException {
|
||||
return this.xaError;
|
||||
}
|
||||
|
||||
public int getOracleError() {
|
||||
return this.primary;
|
||||
}
|
||||
|
||||
public int getOracleSQLError() {
|
||||
return this.secondary;
|
||||
}
|
||||
|
||||
public static int errorConvert(int err) {
|
||||
return errorConvert(err, -3);
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ import javax.transaction.xa.Xid;
|
||||
import oracle.jdbc.internal.OracleConnection;
|
||||
import oracle.jdbc.xa.OracleXAException;
|
||||
import oracle.jdbc.xa.OracleXAResource;
|
||||
import oracle.jdbc.xa.OracleXid;
|
||||
|
||||
import com.alibaba.druid.util.OracleUtils;
|
||||
|
||||
@@ -419,7 +418,7 @@ public class DruidXAOracleResource extends DruidXAResource {
|
||||
}
|
||||
Statement stmt = null;
|
||||
ResultSet rset = null;
|
||||
ArrayList xidCollection = new ArrayList(50);
|
||||
ArrayList<DruidXid> xidCollection = new ArrayList<DruidXid>(50);
|
||||
try {
|
||||
stmt = this.connection.createStatement();
|
||||
try {
|
||||
@@ -431,7 +430,7 @@ public class DruidXAOracleResource extends DruidXAResource {
|
||||
rset = stmt.executeQuery(this.recoverySqlRows);
|
||||
|
||||
while (rset.next()) {
|
||||
xidCollection.add(new OracleXid(rset.getInt(1), rset.getBytes(2), rset.getBytes(3)));
|
||||
xidCollection.add(new DruidXid(rset.getInt(1), rset.getBytes(2), rset.getBytes(3)));
|
||||
}
|
||||
|
||||
} catch (SQLException sqe) {
|
||||
|
||||
@@ -1,18 +1,13 @@
|
||||
package com.alibaba.druid.pool.xa;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Hashtable;
|
||||
|
||||
import javax.transaction.xa.XAException;
|
||||
import javax.transaction.xa.XAResource;
|
||||
import javax.transaction.xa.Xid;
|
||||
|
||||
import oracle.jdbc.xa.OracleXid;
|
||||
|
||||
import com.alibaba.druid.support.logging.Log;
|
||||
import com.alibaba.druid.support.logging.LogFactory;
|
||||
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
package com.alibaba.druid.pool.xa;
|
||||
|
||||
import javax.transaction.xa.XAException;
|
||||
import javax.transaction.xa.Xid;
|
||||
|
||||
public class DruidXid implements Xid {
|
||||
|
||||
private int formatId;
|
||||
private byte[] gtrid = null;
|
||||
private byte[] bqual = null;
|
||||
private byte[] txctx = null;
|
||||
public static final int MAXGTRIDSIZE = 64;
|
||||
public static final int MAXBQUALSIZE = 64;
|
||||
private int state;
|
||||
|
||||
public DruidXid(int fId, byte[] gId, byte[] bId) throws XAException{
|
||||
this(fId, gId, bId, null);
|
||||
}
|
||||
|
||||
public DruidXid(int fId, byte[] gId, byte[] bId, byte[] context) throws XAException{
|
||||
|
||||
this.formatId = fId;
|
||||
|
||||
if ((gId != null) && (gId.length > 64)) {
|
||||
throw new XAException(-4);
|
||||
}
|
||||
|
||||
this.gtrid = gId;
|
||||
|
||||
if ((bId != null) && (bId.length > 64)) {
|
||||
throw new XAException(-4);
|
||||
}
|
||||
|
||||
this.bqual = bId;
|
||||
this.txctx = context;
|
||||
this.state = 0;
|
||||
}
|
||||
|
||||
public void setState(int k) {
|
||||
this.state = k;
|
||||
}
|
||||
|
||||
public int getState() {
|
||||
return this.state;
|
||||
}
|
||||
|
||||
public int getFormatId() {
|
||||
return this.formatId;
|
||||
}
|
||||
|
||||
public byte[] getGlobalTransactionId() {
|
||||
return this.gtrid;
|
||||
}
|
||||
|
||||
public byte[] getBranchQualifier() {
|
||||
return this.bqual;
|
||||
}
|
||||
|
||||
public byte[] getTxContext() {
|
||||
return this.txctx;
|
||||
}
|
||||
|
||||
public void setTxContext(byte[] context) {
|
||||
this.txctx = context;
|
||||
}
|
||||
|
||||
public static final boolean isLocalTransaction(Xid xid) {
|
||||
|
||||
byte[] gtrid = xid.getGlobalTransactionId();
|
||||
|
||||
if (gtrid == null) {
|
||||
return true;
|
||||
}
|
||||
for (int i = 0; i < gtrid.length; i++) {
|
||||
if (gtrid[i] == 0) {
|
||||
continue;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user