org.apache.derby.iapi.store.access
abstract public class: GlobalXact [javadoc |
source]
java.lang.Object
org.apache.derby.iapi.store.access.GlobalXact
Direct Known Subclasses:
GlobalXactId, XAXactId
This abstract class represents a global transaction id which can be tested
for equality against other transaction ids, which can be hashed into a
hash table, and which can be output as a string.
This class has 2 direct subclasses.
- org.apache.derby.iapi.store.access.xa.XAXactId :
this class is a specific implementation of the JTA Xid interface
- org.apache.derby.impl.store.access.GlobalXactId :
this class represents internal Derby transaction ids
The main reason for this class is to ensure that equality etc. works in a
consistent way across both subclasses.
Field Summary |
---|
protected int | format_id | Protected Fields of the class |
protected byte[] | global_id | |
protected byte[] | branch_id | |
Methods from java.lang.Object: |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method from org.apache.derby.iapi.store.access.GlobalXact Detail: |
public boolean equals(Object other) {
if (other == this)
return true;
if (other instanceof GlobalXact) {
GlobalXact other_xact = (GlobalXact) other;
return(
java.util.Arrays.equals(
other_xact.global_id,
this.global_id) &&
java.util.Arrays.equals(
other_xact.branch_id,
this.branch_id) &&
other_xact.format_id == this.format_id);
}
return false;
}
|
public int hashCode() {
// make sure hash does not overflow int, the only unknown is
// format_id. Lop off top bits.
int hash = global_id.length + branch_id.length + (format_id & 0xFFFFFFF);
for (int i = 0; i < global_id.length; i++)
{
hash += global_id[i];
}
for (int i = 0; i < branch_id.length; i++)
{
hash += branch_id[i];
}
return(hash);
}
Provide a hashCode which is compatable with the equals() method. |
public String toString() {
String globalhex = "";
String branchhex = "";
if (global_id != null)
{
int mask = 0;
for (int i = 0; i < global_id.length; i++)
{
mask = (global_id[i] & 0xFF);
if (mask < 16) {
globalhex += "0" + Integer.toHexString(mask);
} else {
globalhex += Integer.toHexString(mask);
}
}
}
if (branch_id != null)
{
int mask = 0;
for (int i = 0; i < branch_id.length; i++)
{
mask = (branch_id[i] & 0xFF);
if (mask < 16) {
branchhex += "0" + Integer.toHexString(mask);
} else {
branchhex += Integer.toHexString(mask);
}
}
}
return("(" + format_id + "," + globalhex + "," + branchhex + ")");
}
|