package connector;
import javax.transaction.xa.Xid;
/**
* The XID class provides an implementation of the X/Open
* transaction identifier it implements the javax.transaction.xa.Xid interface.
*/
public class XID implements Xid {
private static int ID = initializeID();
private static int initializeID() {
return (int)(Math.random()*100000);
}
public int formatID; // Format identifier
// (-1) means that the XID is null
public int branchQualifier;
public int globalTxID;
static public final int MAXGTRIDSIZE= 64;
static public final int MAXBQUALSIZE= 64;
public XID() {
int foo = ID++;
formatID = foo;
branchQualifier = foo;
globalTxID = foo;
}
public boolean equals(Object o) {
XID other; // The "other" XID
int L; // Combined gtrid_length + bqual_length
int i;
if (!(o instanceof XID)) // If the other XID isn't an XID
{
return false; // It can't be equal
}
other = (XID)o; // The other XID, now properly cast
if (this.formatID == other.formatID
&& this.branchQualifier == other.branchQualifier
&& this.globalTxID == other.globalTxID) {
return true;
}
return false;
}
/**
* Compute the hash code.
*
* @return the computed hashcode
*/
public int hashCode() {
if (formatID == (-1)) {
return (-1);
}
return formatID + branchQualifier + globalTxID;
}
/*
* Convert to String
*
* <p> This is normally used to display the XID when debugging.
*/
/**
* Return a string representing this XID.
*
* @return the string representation of this XID
*/
public String toString() {
String s = new String("{XID: " +
"formatID(" + formatID + "), " +
"branchQualifier (" + branchQualifier + "), " +
"globalTxID(" + globalTxID + ")}");
return s;
}
/*
* Return branch qualifier
*/
/**
* Returns the branch qualifier for this XID.
*
* @return the branch qualifier
*/
public byte[] getBranchQualifier() {
String foo = (new Integer(branchQualifier)).toString();
return foo.getBytes();
}
public int getFormatId() {
return formatID;
}
public byte[] getGlobalTransactionId() {
String foo = (new Integer(globalTxID)).toString();
return foo.getBytes();
}
}