1 23 24 28 50 package com.sun.jts.jtsxa; 51 52 import org.omg.CosTransactions.*; 53 import javax.transaction.xa.Xid ; 54 55 import java.util.logging.Logger ; 56 import java.util.logging.Level ; 57 import com.sun.logging.LogDomains; 58 import com.sun.jts.utils.LogFormatter; 59 60 64 public class XID implements Xid { 65 66 70 74 private int formatID; 79 private int gtrid_length; 81 84 private int bqual_length; 86 94 private byte data[]; 96 private byte cachedBqual[] = null; 98 private byte cachedGtrid[] = null; 99 100 101 105 108 static private final int XIDDATASIZE= 128; 110 113 static public final int MAXGTRIDSIZE= 64; 115 118 static public final int MAXBQUALSIZE= 64; 120 static private final String hextab= "0123456789ABCDEF"; 121 122 static Logger _logger = LogDomains.getLogger(LogDomains.TRANSACTION_LOGGER); 123 124 128 132 public XID() { 133 data= new byte[XIDDATASIZE]; 134 formatID = -1; 135 } 136 137 141 147 public void copy(XID from) { 148 int i; 149 150 formatID = -1; if (from == null) { 153 return; } 155 156 if (from.formatID == (-1)) { 158 return; } 160 161 gtrid_length= from.gtrid_length; 162 bqual_length= from.bqual_length; 163 164 if (data != null && from.data != null) { 165 System.arraycopy(from.data, 0, data, 0, XIDDATASIZE); 166 } 167 168 formatID= from.formatID; } 170 171 174 175 182 public void copy(otid_t from) { 183 int i; 184 int L; 185 186 formatID= -1; if (from == null) { 189 return; } 191 192 if (from.formatID == (-1)) { 194 return; } 196 197 L= from.tid.length; 198 gtrid_length= L - from.bqual_length; 199 bqual_length= from.bqual_length; 200 201 if (data != null && from.tid != null) { 202 System.arraycopy(from.tid, 0, data, 0, L); 203 } 204 205 formatID= from.formatID; } 207 208 211 212 220 public boolean equals(Object o) { 221 XID other; int L; int i; 224 225 if (!(o instanceof XID)) { 227 return false; } 229 230 other = (XID)o; 232 if (formatID == (-1) && other.formatID == (-1)) 233 { 234 return true; 235 } 236 237 if (formatID != other.formatID 238 ||gtrid_length != other.gtrid_length 239 ||bqual_length != other.bqual_length) { 240 return false; 241 } 242 243 L = gtrid_length + bqual_length; 244 245 for (i = 0; i < L; i++) { 246 if (data[i] != other.data[i]) { 247 return false; 248 } 249 } 250 251 return true; 252 } 253 254 257 258 263 public int hashCode() { 264 if (formatID == (-1)) { 265 return (-1); 266 } 267 268 return formatID + gtrid_length - bqual_length; 269 270 } 271 272 277 278 283 public String toString() { 284 288 if (_logger.isLoggable(Level.FINE)) { 289 StringBuffer d; String s; 292 int i; 293 int v; 294 int L; 295 296 L= gtrid_length + bqual_length; 297 d= new StringBuffer (L + L); 298 299 for (i = 0; i < L; i++) { 301 v = data[i] & 0xff; 302 d.append(hextab.charAt(v/16)); 303 d.append(hextab.charAt(v&15)); 304 if ((i+1) % 4 == 0 && (i+1) < L) { 305 d.append(" "); 306 } 307 } 308 309 s = new String ("{XID: " + 310 "formatID(" + formatID + "), " + 311 "gtrid_length(" + gtrid_length + "), " + 312 "bqual_length(" + bqual_length + "), " + 313 "data(" + d + ")" + 314 "}"); 315 316 return s; 317 } 318 else 319 return null; 320 } 321 322 325 326 331 public byte[] getBranchQualifier() { 332 if (cachedBqual != null) { 333 return cachedBqual; 334 } 335 byte[] bqual = new byte[bqual_length]; 336 System.arraycopy(data,gtrid_length,bqual,0,bqual_length); 337 return bqual; 338 } 339 340 345 346 353 public void setBranchQualifier(byte[] qual) { 354 bqual_length = qual.length > MAXBQUALSIZE ? MAXBQUALSIZE : qual.length; 355 System.arraycopy(qual, 0, data, gtrid_length, bqual_length); 356 cachedBqual = qual; 357 } 358 359 364 public int getFormatID() { 365 return formatID; 366 } 367 368 373 public void setFormatID(int formatID) { 374 this.formatID = formatID; 375 return; 376 } 377 378 381 382 387 public boolean isEqualBranchQualifier(byte[] data) { 388 389 int L = data.length > MAXBQUALSIZE?MAXBQUALSIZE:data.length; 390 int i; 391 392 if (L != bqual_length) { 393 return false; 394 } 395 396 for (i = 0; i < L; i++) { 397 if (data[i] != this.data[gtrid_length + i]) { 398 return false; 399 } 400 } 401 402 return true; 403 } 404 405 407 410 public boolean isEqualGtrid(XID xid) { 411 if (this.gtrid_length != xid.gtrid_length) { 412 return false; 413 } 414 415 for (int i=0; i<gtrid_length; i++) { 416 if (this.data[i] != xid.data[i]) { 417 return false; 418 } 419 } 420 421 return true; 422 } 423 424 427 428 433 public byte[] getGlobalTransactionIdentifier() { 434 if (cachedGtrid != null) { 435 return cachedGtrid; 436 } 437 byte[] gtrid = new byte[gtrid_length]; 438 System.arraycopy(data, 0, gtrid, 0, gtrid_length); 439 cachedGtrid = gtrid; 440 return gtrid; 441 } 442 443 446 public int getFormatId() { 447 return getFormatID(); 448 } 449 450 public byte[] getGlobalTransactionId() { 451 return getGlobalTransactionIdentifier(); 452 } 453 } 454 | Popular Tags |