source: Ballon/out/artifacts/geisa_artifact/WEB-INF/lib/mysql-connector-java-5.1.21/src/com/mysql/jdbc/jdbc2/optional/MysqlXid.java @ 848

Last change on this file since 848 was 766, checked in by npipsl, 11 years ago
File size: 2.8 KB
Line 
1/*
2 Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
3 
4
5  The MySQL Connector/J is licensed under the terms of the GPLv2
6  <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most MySQL Connectors.
7  There are special exceptions to the terms and conditions of the GPLv2 as it is applied to
8  this software, see the FLOSS License Exception
9  <http://www.mysql.com/about/legal/licensing/foss-exception.html>.
10
11  This program is free software; you can redistribute it and/or modify it under the terms
12  of the GNU General Public License as published by the Free Software Foundation; version 2
13  of the License.
14
15  This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
16  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17  See the GNU General Public License for more details.
18
19  You should have received a copy of the GNU General Public License along with this
20  program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth
21  Floor, Boston, MA 02110-1301  USA
22
23*/
24
25package com.mysql.jdbc.jdbc2.optional;
26
27import javax.transaction.xa.Xid;
28
29/**
30 * Implementation of the XID interface for MySQL XA
31 *
32 * @version $Id: $
33 */
34public class MysqlXid implements Xid {
35
36        int hash = 0;
37
38        byte[] myBqual;
39
40        int myFormatId;
41
42        byte[] myGtrid;
43
44        public MysqlXid(byte[] gtrid, byte[] bqual, int formatId) {
45                this.myGtrid = gtrid;
46                this.myBqual = bqual;
47                this.myFormatId = formatId;
48        }
49
50        public boolean equals(Object another) {
51
52                if (another instanceof Xid) {
53                        Xid anotherAsXid = (Xid) another;
54
55                        if (this.myFormatId != anotherAsXid.getFormatId()) {
56                                return false;
57                        }
58
59                        byte[] otherBqual = anotherAsXid.getBranchQualifier();
60                        byte[] otherGtrid = anotherAsXid.getGlobalTransactionId();
61
62                        if (otherGtrid != null && otherGtrid.length == this.myGtrid.length) {
63                                int length = otherGtrid.length;
64
65                                for (int i = 0; i < length; i++) {
66                                        if (otherGtrid[i] != this.myGtrid[i]) {
67                                                return false;
68                                        }
69                                }
70
71                                if (otherBqual != null && otherBqual.length == myBqual.length) {
72                                        length = otherBqual.length;
73
74                                        for (int i = 0; i < length; i++) {
75                                                if (otherBqual[i] != this.myBqual[i]) {
76                                                        return false;
77                                                }
78                                        }
79                                } else {
80                                        return false;
81                                }
82
83                                return true;
84                        }
85                }
86
87                return false;
88        }
89
90        public byte[] getBranchQualifier() {
91                return this.myBqual;
92        }
93
94        public int getFormatId() {
95                return this.myFormatId;
96        };
97
98        public byte[] getGlobalTransactionId() {
99                return this.myGtrid;
100        }
101
102        public synchronized int hashCode() {
103                if (this.hash == 0) {
104                        for (int i = 0; i < this.myGtrid.length; i++) {
105                                this.hash = 33 * this.hash + this.myGtrid[i];
106                        }
107                }
108
109                return this.hash;
110        }
111}
Note: See TracBrowser for help on using the repository browser.