001: /*
002:
003: Derby - Class org.apache.derby.impl.drda.DRDAXid.java
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to You under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: /**
023: * This class provides an Xid implementation for Network Server XA
024: */package org.apache.derby.impl.drda;
025:
026: import javax.transaction.xa.Xid;
027:
028: class DRDAXid implements Xid {
029:
030: private final int format_id;
031: private final byte[] global_id;
032: private final byte[] branch_id;
033:
034: DRDAXid(int formatid, byte[] globalid, byte[] branchid) {
035:
036: format_id = formatid;
037: global_id = globalid;
038: branch_id = branchid;
039:
040: }
041:
042: /**
043: * Obtain the format id part of the Xid.
044: * <p>
045: *
046: * @return Format identifier. O means the OSI CCR format.
047: **/
048: public int getFormatId() {
049: return (format_id);
050: }
051:
052: /**
053: * Obtain the global transaction identifier part of XID as an array of
054: * bytes.
055: * <p>
056: *
057: * @return A byte array containing the global transaction identifier.
058: **/
059: public byte[] getGlobalTransactionId() {
060: return (global_id);
061: }
062:
063: /**
064: * Obtain the transaction branch qualifier part of the Xid in a byte array.
065: * <p>
066: *
067: * @return A byte array containing the branch qualifier of the transaction.
068: **/
069: public byte[] getBranchQualifier() {
070: return (branch_id);
071: }
072:
073: public String toString() {
074:
075: String s = "{DRDAXid: " + "formatId(" + format_id + "), "
076: + "globalTransactionId("
077: + convertToHexString(global_id) + ")"
078: + "branchQualifier(" + convertToHexString(branch_id)
079: + ")";
080: return s;
081: }
082:
083: /**
084: * convert byte array to a Hex string
085: *
086: * @param buf buffer to convert
087: * @return hex string representation of byte array
088: */
089: private static String convertToHexString(byte[] buf) {
090: if (buf == null)
091: return null;
092: StringBuffer str = new StringBuffer();
093: str.append("0x");
094: String val;
095: int byteVal;
096: for (int i = 0; i < buf.length; i++) {
097: byteVal = buf[i] & 0xff;
098: val = Integer.toHexString(byteVal);
099: if (val.length() < 2)
100: str.append("0");
101: str.append(val);
102: }
103: return str.toString();
104: }
105: }
|