FileDocCategorySizeDatePackage
XID.javaAPI DocGlassfish v2 API14340Fri May 04 22:36:40 BST 2007com.sun.jts.jtsxa

XID

public class XID extends Object implements Xid
The XID class provides an implementation of the X/Open transaction identifier it implements the javax.transaction.xa.Xid interface.

Fields Summary
private int
formatID
The format identifier for the XID. A value of -1 indicates that the NULLXID.
private int
gtrid_length
The number of bytes in the global transaction identfier
private int
bqual_length
The number of bytes in the branch qualifier
private byte[]
data
The data for the XID.

The XID is made up of two contiguous parts. The first (of size gtrid_length) is the global transaction identfier and the second (of size bqual_length) is the branch qualifier.

If the formatID is -1, indicating the NULLXID, the data is ignored.

private byte[]
cachedBqual
private byte[]
cachedGtrid
private static final int
XIDDATASIZE
The size of data.
public static final int
MAXGTRIDSIZE
The maximum size of the global transaction identifier.
public static final int
MAXBQUALSIZE
The maximum size of the branch qualifier.
private static final String
hextab
static Logger
_logger
Constructors Summary
public XID()
Constructs a new null XID.

After construction the data within the XID should be initialized.


    //-----------------------------------------------------------------------//
    // XID::Constructor                                                      //
    //-----------------------------------------------------------------------//

                        
      
        data= new byte[XIDDATASIZE];
        formatID = -1;
    
Methods Summary
public voidcopy(com.sun.jts.jtsxa.XID from)
Initialize an XID using another XID as the source of data.

param
from the XID to initialize this XID from

        int i;

        formatID = -1;                    // Default, null transaction
        if (from == null)                // If source is physically null
        {
            return;                        // Return the NULL transaction
        }

        if (from.formatID == (-1))       // If source is a NULL transaction
        {
            return;                        // Return the NULL transaction
        }

        gtrid_length= from.gtrid_length;
        bqual_length= from.bqual_length;

        if (data != null && from.data != null) {
            System.arraycopy(from.data, 0, data, 0, XIDDATASIZE);
        }

        formatID= from.formatID;         // Last, in case of failure
    
public voidcopy(otid_t from)
Initialize an XID using an omg otid_t as the source of data.

param
from the OMG otid_t to initialize this XID from
see
org.omg.CosTransactions.otid_t

        int               i;
        int               L;

        formatID= -1;                    // Default, null transaction
        if (from == null)                // If source is physically null
        {
            return;                        // Return the NULL transaction
        }

        if (from.formatID == (-1))       // If source is a NULL transaction
        {
            return;                        // Return the NULL transaction
        }

        L= from.tid.length;
        gtrid_length= L - from.bqual_length;
        bqual_length= from.bqual_length;

        if (data != null && from.tid != null) {
            System.arraycopy(from.tid, 0, data, 0, L);
        }

        formatID= from.formatID;         // Last, in case of failure
    
public booleanequals(java.lang.Object o)
Determine whether or not two objects of this type are equal.

param
o the object to be compared with this XID.
return
Returns true of the supplied object represents the same global transaction as this, otherwise returns false.

        XID               other;   // The "other" XID
        int               L;       // Combined gtrid_length + bqual_length
        int               i;

        if (!(o instanceof XID))        // If the other XID isn't an XID
        {
            return false;                  // It can't be equal
        }

        other = (XID)o;                   // The other XID, now properly cast

        if (formatID == (-1) && other.formatID == (-1))
        {
            return true;
        }

        if (formatID != other.formatID
                ||gtrid_length != other.gtrid_length
                ||bqual_length != other.bqual_length) {
            return false;
        }

        L = gtrid_length + bqual_length;

        for (i = 0; i < L; i++) {
            if (data[i] != other.data[i]) {
                return false;
            }
        }

        return true;
    
public byte[]getBranchQualifier()
Returns the branch qualifier for this XID.

return
the branch qualifier

        if (cachedBqual != null) {
            return cachedBqual;
        }
        byte[] bqual = new byte[bqual_length];
        System.arraycopy(data,gtrid_length,bqual,0,bqual_length);
        return bqual;
    
public intgetFormatID()
Obtain the format identifier part of the XID.

return
Format identifier. -1 indicates a null XID

        return formatID;
    
public intgetFormatId()

        return getFormatID();
    
public byte[]getGlobalTransactionId()

        return getGlobalTransactionIdentifier();
    
public byte[]getGlobalTransactionIdentifier()
Returns the global transaction identifier for this XID.

return
the global transaction identifier

       if (cachedGtrid != null) {
           return cachedGtrid;
       }
        byte[] gtrid = new byte[gtrid_length];
        System.arraycopy(data, 0, gtrid, 0, gtrid_length);
        cachedGtrid = gtrid;
        return gtrid;
    
public inthashCode()
Compute the hash code.

return
the computed hashcode

        if (formatID == (-1)) {
            return (-1);
        }

        return formatID + gtrid_length - bqual_length;

    
public booleanisEqualBranchQualifier(byte[] data)
Compares the input parameter with the branch qualifier for equality.

return
true if equal


        int L = data.length > MAXBQUALSIZE?MAXBQUALSIZE:data.length;
        int i;

        if (L != bqual_length) {
            return false;
        }

        for (i = 0; i < L; i++) {
            if (data[i] != this.data[gtrid_length + i]) {
                return false;
            }
        }

        return true;
    
public booleanisEqualGtrid(com.sun.jts.jtsxa.XID xid)
Return whether the Gtrid of this is equal to the Gtrid of xid

        if (this.gtrid_length != xid.gtrid_length) {
            return false;
        }

        for (int i=0; i<gtrid_length; i++) {
            if (this.data[i] != xid.data[i]) {
                return false;
            }
        }

        return true;
    
public voidsetBranchQualifier(byte[] qual)
Set the branch qualifier for this XID.

param
qual a Byte array containing the branch qualifier to be set. If the size of the array exceeds MAXBQUALSIZE, only the first MAXBQUALSIZE elements of qual will be used.

        bqual_length = qual.length > MAXBQUALSIZE ? MAXBQUALSIZE : qual.length;
        System.arraycopy(qual, 0, data, gtrid_length, bqual_length);
        cachedBqual = qual;
    
public voidsetFormatID(int formatID)
Set the format identifier part of the XID.

param
Format identifier. -1 indicates a null Xid.

        this.formatID = formatID;
        return;
    
public java.lang.StringtoString()
Return a string representing this XID.

return
the string representation of this XID

        /* toString() method is slightly expensive and this needs to be done because 
	 * some of the drivers XAResource methods have the "trace("some thing " + xid)" 
         * kind of code which is executing this method resulting in performance degradation.
         */
        if (_logger.isLoggable(Level.FINE)) {
            StringBuffer      d;             // Data String, in Hexidecimal
            String            s;             // Resultant String

            int               i;
            int               v;
            int               L;

            L= gtrid_length + bqual_length;
            d= new StringBuffer(L + L);

            // Convert data string to hex
            for (i = 0; i < L; i++) {
                v = data[i] & 0xff;
                d.append(hextab.charAt(v/16));
                d.append(hextab.charAt(v&15));
                if ((i+1) % 4 == 0 && (i+1) < L) {
                    d.append(" ");
                }
            }

            s = new String("{XID: " +
                         "formatID("     + formatID     + "), " +
                         "gtrid_length(" + gtrid_length + "), " +
                         "bqual_length(" + bqual_length + "), " +
                         "data("         + d            + ")" +
                         "}"/*#Frozen*/);

            return s;
        }
        else
           return null;