001: /*
002: Copyright (C) 2005 MySQL AB
003:
004: This program is free software; you can redistribute it and/or modify
005: it under the terms of version 2 of the GNU General Public License as
006: published by the Free Software Foundation.
007:
008: There are special exceptions to the terms and conditions of the GPL
009: as it is applied to this software. View the full text of the
010: exception in file EXCEPTIONS-CONNECTOR-J in the directory of this
011: software distribution.
012:
013: This program is distributed in the hope that it will be useful,
014: but WITHOUT ANY WARRANTY; without even the implied warranty of
015: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016: GNU General Public License for more details.
017:
018: You should have received a copy of the GNU General Public License
019: along with this program; if not, write to the Free Software
020: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
021:
022: */
023:
024: package com.mysql.jdbc.jdbc2.optional;
025:
026: import javax.transaction.xa.Xid;
027:
028: /**
029: * Implementation of the XID interface for MySQL XA
030: *
031: * @version $Id: $
032: */
033: public class MysqlXid implements Xid {
034:
035: int hash = 0;
036:
037: byte[] myBqual;
038:
039: int myFormatId;
040:
041: byte[] myGtrid;
042:
043: public MysqlXid(byte[] gtrid, byte[] bqual, int formatId) {
044: this .myGtrid = gtrid;
045: this .myBqual = bqual;
046: this .myFormatId = formatId;
047: }
048:
049: public boolean equals(Object another) {
050:
051: if (another instanceof Xid) {
052: Xid anotherAsXid = (Xid) another;
053:
054: if (this .myFormatId != anotherAsXid.getFormatId()) {
055: return false;
056: }
057:
058: byte[] otherBqual = anotherAsXid.getBranchQualifier();
059: byte[] otherGtrid = anotherAsXid.getGlobalTransactionId();
060:
061: if (otherGtrid != null
062: && otherGtrid.length == this .myGtrid.length) {
063: int length = otherGtrid.length;
064:
065: for (int i = 0; i < length; i++) {
066: if (otherGtrid[i] != this .myGtrid[i]) {
067: return false;
068: }
069: }
070:
071: if (otherBqual != null
072: && otherBqual.length == myBqual.length) {
073: length = otherBqual.length;
074:
075: for (int i = 0; i < length; i++) {
076: if (otherBqual[i] != this .myBqual[i]) {
077: return false;
078: }
079: }
080: } else {
081: return false;
082: }
083:
084: return true;
085: } else {
086: return false;
087: }
088: } else {
089: return false;
090: }
091: }
092:
093: public byte[] getBranchQualifier() {
094: return this .myBqual;
095: }
096:
097: public int getFormatId() {
098: return this .myFormatId;
099: };
100:
101: public byte[] getGlobalTransactionId() {
102: return this .myGtrid;
103: }
104:
105: public synchronized int hashCode() {
106: if (this .hash == 0) {
107: for (int i = 0; i < this .myGtrid.length; i++) {
108: this .hash = 33 * this.hash + this.myGtrid[i];
109: }
110: }
111:
112: return this.hash;
113: }
114: }
|