EMMA Coverage Report (generated Sun Mar 01 22:06:14 CET 2015)
[all classes][org.h2.jdbcx]

COVERAGE SUMMARY FOR SOURCE FILE [JdbcXid.java]

nameclass, %method, %block, %line, %
JdbcXid.java100% (1/1)100% (5/5)90%  (83/92)86%  (19/22)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class JdbcXid100% (1/1)100% (5/5)90%  (83/92)86%  (19/22)
JdbcXid (JdbcDataSourceFactory, int, String): void 100% (1/1)81%  (38/47)77%  (10/13)
getBranchQualifier (): byte [] 100% (1/1)100% (6/6)100% (2/2)
getFormatId (): int 100% (1/1)100% (6/6)100% (2/2)
getGlobalTransactionId (): byte [] 100% (1/1)100% (6/6)100% (2/2)
toString (Xid): String 100% (1/1)100% (27/27)100% (3/3)

1/*
2 * Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0,
3 * and the EPL 1.0 (http://h2database.com/html/license.html).
4 * Initial Developer: H2 Group
5 */
6package org.h2.jdbcx;
7 
8import java.util.StringTokenizer;
9import javax.transaction.xa.Xid;
10 
11import org.h2.api.ErrorCode;
12import org.h2.message.DbException;
13import org.h2.message.TraceObject;
14import org.h2.util.StringUtils;
15 
16/**
17 * An object of this class represents a transaction id.
18 */
19public class JdbcXid extends TraceObject implements Xid {
20 
21    private static final String PREFIX = "XID";
22 
23    private final int formatId;
24    private final byte[] branchQualifier;
25    private final byte[] globalTransactionId;
26 
27    JdbcXid(JdbcDataSourceFactory factory, int id, String tid) {
28        setTrace(factory.getTrace(), TraceObject.XID, id);
29        try {
30            StringTokenizer tokenizer = new StringTokenizer(tid, "_");
31            String prefix = tokenizer.nextToken();
32            if (!PREFIX.equals(prefix)) {
33                throw DbException.get(ErrorCode.WRONG_XID_FORMAT_1, tid);
34            }
35            formatId = Integer.parseInt(tokenizer.nextToken());
36            branchQualifier = StringUtils.convertHexToBytes(tokenizer.nextToken());
37            globalTransactionId = StringUtils.convertHexToBytes(tokenizer.nextToken());
38        } catch (RuntimeException e) {
39            throw DbException.get(ErrorCode.WRONG_XID_FORMAT_1, tid);
40        }
41    }
42 
43    /**
44     * INTERNAL
45     */
46    public static String toString(Xid xid) {
47        StringBuilder buff = new StringBuilder(PREFIX);
48        buff.append('_').
49            append(xid.getFormatId()).
50            append('_').
51            append(StringUtils.convertBytesToHex(xid.getBranchQualifier())).
52            append('_').
53            append(StringUtils.convertBytesToHex(xid.getGlobalTransactionId()));
54        return buff.toString();
55    }
56 
57    /**
58     * Get the format id.
59     *
60     * @return the format id
61     */
62    @Override
63    public int getFormatId() {
64        debugCodeCall("getFormatId");
65        return formatId;
66    }
67 
68    /**
69     * The transaction branch identifier.
70     *
71     * @return the identifier
72     */
73    @Override
74    public byte[] getBranchQualifier() {
75        debugCodeCall("getBranchQualifier");
76        return branchQualifier;
77    }
78 
79    /**
80     * The global transaction identifier.
81     *
82     * @return the transaction id
83     */
84    @Override
85    public byte[] getGlobalTransactionId() {
86        debugCodeCall("getGlobalTransactionId");
87        return globalTransactionId;
88    }
89 
90}

[all classes][org.h2.jdbcx]
EMMA 2.0.5312 (C) Vladimir Roubtsov