Java Transaction Xid Check sameTransaction(Xid x1, Xid x2)

Here you can find the source of sameTransaction(Xid x1, Xid x2)

Description

Compares two Xid instances at the gtid level only.

License

LGPL

Parameter

Parameter Description
x1 first Xid
x2 second Xid

Return

true if the two instances are the same, false otherwise.

Declaration


public static boolean sameTransaction(Xid x1, Xid x2) 

Method Source Code

//package com.java2s;
/*/*from w  w w.  j  a v  a 2  s  .  co  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 at the gtid level only.
     *
     * @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 sameTransaction(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;
                    }

                    return true;
                } else
                    return false;
            } else
                return false;
        }
    }
}

Related

  1. getRedisKey(String keyPrefix, Xid xid)
  2. getXidSize(Xid xid)
  3. sameXID(Xid x1, Xid x2)
  4. xidToString(Xid xid, boolean includeBranchQualifier)