Here you can find the source of sameXID(Xid x1, Xid x2)
Parameter | Description |
---|---|
x1 | first Xid |
x2 | second Xid |
true
if the two instances are the same, false
otherwise.
public static boolean sameXID(Xid x1, Xid x2)
//package com.java2s; /*// w w w. jav a 2 s . c o m * JBoss, Home of Professional Open Source * Copyright 2006, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. * See the copyright.txt in the distribution for a * full listing of individual contributors. * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions * of the GNU Lesser General Public License, v. 2.1. * This program is distributed in the hope that it will be useful, but WITHOUT A * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. * You should have received a copy of the GNU Lesser General Public License, * v.2.1 along with this distribution; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. * * (C) 2005-2006, * @author JBoss Inc. */ import javax.transaction.xa.Xid; public class Main { /** * Compares two Xid instances. * * @param x1 first Xid * @param x2 second Xid * * @return <code>true</code> if the two instances are the same, * <code>false</code> otherwise. */ public static boolean sameXID(Xid x1, Xid x2) { if (x1 == x2) return true; else { if (x1.getFormatId() == x2.getFormatId()) { byte[] gtrid1 = x1.getGlobalTransactionId(); byte[] gtrid2 = x2.getGlobalTransactionId(); if (gtrid1.length == gtrid2.length) { for (int i = 0; i < gtrid1.length; i++) { if (gtrid1[i] != gtrid2[i]) return false; } } else return false; byte[] bqual1 = x1.getBranchQualifier(); final int bqual1Len = (bqual1 == null ? 0 : bqual1.length); byte[] bqual2 = x2.getBranchQualifier(); final int bqual2Len = (bqual2 == null ? 0 : bqual2.length); if (bqual1Len == bqual2Len) { for (int i = 0; i < bqual1Len; i++) { if (bqual1[i] != bqual2[i]) return false; } } else return false; return true; } else return false; } } }