1 21 package org.apache.derby.client; 22 23 import javax.transaction.xa.Xid ; 24 25 public class ClientXid implements Xid { 26 private int formatID_; 31 32 private int gtrid_length_; 36 37 private int bqual_length_; 41 42 private byte data_[]; 51 52 static private final int XidDATASIZE = 128; 56 57 static public final int MAXGTRIDSIZE = 64; 61 62 static public final int MAXBQUALSIZE = 64; 66 67 static private final String hextab_ = "0123456789ABCDEF"; 68 69 70 public ClientXid() { 75 data_ = new byte[XidDATASIZE]; 76 gtrid_length_ = 0; 77 bqual_length_ = 0; 78 formatID_ = -1; 79 } 80 81 public ClientXid(int formatID, byte[] gtrid, byte[] bqual) { 85 86 formatID_ = formatID; 87 gtrid_length_ = gtrid.length; 88 bqual_length_ = bqual.length; 89 data_ = new byte[XidDATASIZE]; 90 System.arraycopy(gtrid, 0, data_, 0, gtrid_length_); 91 System.arraycopy(bqual, 0, data_, gtrid_length_, bqual_length_); 92 } 93 94 public String toString() { 100 StringBuffer d; String s; int i; 103 int v; 104 int L; 105 106 L = gtrid_length_ + bqual_length_; 107 d = new StringBuffer (L + L); 108 109 for (i = 0; i < L; i++) { 110 v = data_[i] & 0xff; 112 d.append(hextab_.charAt(v / 16)); 113 d.append(hextab_.charAt(v & 15)); 114 if ((i + 1) % 4 == 0 && (i + 1) < L) { 115 d.append(" "); 116 } 117 } 118 119 s = "{ClientXid: " + 120 "formatID(" + formatID_ + "), " + 121 "gtrid_length(" + gtrid_length_ + "), " + 122 "bqual_length(" + bqual_length_ + "), " + 123 "data(" + d.toString() + ")" + 124 "}"; 125 return s; 126 } 127 128 public byte[] getBranchQualifier() { 134 byte[] bqual = new byte[bqual_length_]; 135 System.arraycopy(data_, gtrid_length_, bqual, 0, bqual_length_); 136 return bqual; 137 } 138 139 public void setBranchQualifier(byte[] qual) { 147 bqual_length_ = qual.length > MAXBQUALSIZE ? MAXBQUALSIZE : qual.length; 148 System.arraycopy(qual, 0, data_, gtrid_length_, bqual_length_); 149 } 150 151 public int getFormatId() { 157 return formatID_; 158 } 159 160 public void setFormatID(int formatID) { 166 formatID_ = formatID; 167 return; 168 } 169 170 public byte[] getGlobalTransactionId() { 176 byte[] gtrid = new byte[gtrid_length_]; 177 System.arraycopy(data_, 0, gtrid, 0, gtrid_length_); 178 return gtrid; 179 } 180 181 public byte[] getData() { 185 return data_; 186 } 187 188 public int getGtridLength() { 189 return gtrid_length_; 190 } 191 192 public int getBqualLength() { 193 return bqual_length_; 194 } 195 196 public int hashCode() { 197 if (formatID_ == (-1)) { 198 return (-1); 199 } 200 return formatID_ + gtrid_length_ - bqual_length_; 201 } 202 203 public boolean equals(Object obj) { 204 return org.apache.derby.client.net.NetXAResource.xidsEqual(this, (javax.transaction.xa.Xid ) obj); 205 } 206 } | Popular Tags |