Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / derby-10.3.2.1 / java / drda / org / apache / derby / impl / drda / DRDAXid.java
diff --git a/JMCR-Stable/real-world application/derby-10.3.2.1/java/drda/org/apache/derby/impl/drda/DRDAXid.java b/JMCR-Stable/real-world application/derby-10.3.2.1/java/drda/org/apache/derby/impl/drda/DRDAXid.java
new file mode 100644 (file)
index 0000000..b82c04f
--- /dev/null
@@ -0,0 +1,124 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.impl.drda.DRDAXid.java\r
+\r
+   Licensed to the Apache Software Foundation (ASF) under one or more\r
+   contributor license agreements.  See the NOTICE file distributed with\r
+   this work for additional information regarding copyright ownership.\r
+   The ASF licenses this file to You under the Apache License, Version 2.0\r
+   (the "License"); you may not use this file except in compliance with\r
+   the License.  You may obtain a copy of the License at\r
+\r
+      http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+\r
+ */\r
+\r
+/**\r
+ * This class provides an Xid implementation for Network Server XA\r
+ */\r
+\r
+package org.apache.derby.impl.drda;\r
+import javax.transaction.xa.Xid;\r
+\r
+class DRDAXid implements Xid\r
+{\r
+\r
+       private final int format_id;\r
+       private final byte[] global_id;\r
+       private final byte[] branch_id;\r
+\r
+\r
+       DRDAXid(int formatid, byte[] globalid, byte[] branchid)\r
+       {\r
+\r
+               format_id = formatid;\r
+               global_id = globalid;\r
+               branch_id = branchid;\r
+               \r
+       }\r
+\r
+    /**\r
+     * Obtain the format id part of the Xid.\r
+     * <p>\r
+     *\r
+     * @return Format identifier. O means the OSI CCR format.\r
+     **/\r
+    public int getFormatId()\r
+    {\r
+        return(format_id);\r
+    }\r
+\r
+    /**\r
+     * Obtain the global transaction identifier part of XID as an array of \r
+     * bytes.\r
+     * <p>\r
+     *\r
+        * @return A byte array containing the global transaction identifier.\r
+     **/\r
+    public byte[] getGlobalTransactionId()\r
+    {\r
+        return(global_id);\r
+    }\r
+\r
+    /**\r
+     * Obtain the transaction branch qualifier part of the Xid in a byte array.\r
+     * <p>\r
+     *\r
+        * @return A byte array containing the branch qualifier of the transaction.\r
+     **/\r
+    public byte[] getBranchQualifier()\r
+    {\r
+        return(branch_id);\r
+    }\r
+\r
+       public String toString()\r
+       {\r
+               \r
+          String s =  "{DRDAXid: " +\r
+                  "formatId("     + format_id   + "), " +\r
+                  "globalTransactionId(" +  convertToHexString(global_id) + ")" +\r
+                  "branchQualifier(" +  convertToHexString(branch_id) + ")";\r
+          return s;\r
+       }\r
+\r
+\r
+       /**\r
+        * convert byte array to a Hex string\r
+        * \r
+        * @param buf buffer to  convert\r
+        * @return hex string representation of byte array\r
+        */\r
+       private static String convertToHexString(byte [] buf)\r
+       {\r
+               if (buf == null)\r
+                       return null;\r
+               StringBuffer str = new StringBuffer();\r
+               str.append("0x");\r
+               String val;\r
+               int byteVal;\r
+               for (int i = 0; i < buf.length; i++)\r
+               {\r
+                       byteVal = buf[i] & 0xff;\r
+                       val = Integer.toHexString(byteVal);\r
+                       if (val.length() < 2)\r
+                               str.append("0");\r
+                       str.append(val);\r
+               }\r
+               return str.toString();\r
+       }\r
+}\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r