01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.object.tx;
05:
06: import com.tc.util.Assert;
07:
08: /**
09: * Type safe enumeration of transaction types
10: */
11: public class TxnType {
12: private static final byte TYPE_RO = 1;
13: private static final byte TYPE_NORMAL = 2;
14: private static final byte TYPE_CONCURRENT = 3;
15:
16: public static final TxnType READ_ONLY = new TxnType(TYPE_RO);
17: public static final TxnType NORMAL = new TxnType(TYPE_NORMAL);
18: public static final TxnType CONCURRENT = new TxnType(
19: TYPE_CONCURRENT);
20:
21: /**
22: * Map type to enumerated value
23: * @param type Type code
24: * @return Type instance
25: */
26: public static TxnType typeFor(byte type) {
27: switch (type) {
28: case TYPE_RO: {
29: return READ_ONLY;
30: }
31: case TYPE_NORMAL: {
32: return NORMAL;
33: }
34: case TYPE_CONCURRENT: {
35: return CONCURRENT;
36: }
37: default: {
38: throw Assert.failure("unknown transaction type " + type);
39: }
40: }
41: }
42:
43: /**
44: * @return True if concurrent
45: */
46: public boolean isConcurrent() {
47: return this == CONCURRENT;
48: }
49:
50: public boolean equals(Object other) {
51: return this == other;
52: }
53:
54: public int hashCode() {
55: return this .type;
56: }
57:
58: private final byte type;
59:
60: private TxnType(byte type) {
61: this .type = type;
62: }
63:
64: /**
65: * @return Type code
66: */
67: public byte getType() {
68: return type;
69: }
70:
71: public String toString() {
72: switch (type) {
73: case TYPE_RO: {
74: return "READ_ONLY";
75: }
76: case TYPE_NORMAL: {
77: return "NORMAL";
78: }
79: case TYPE_CONCURRENT: {
80: return "CONCURRENT";
81: }
82: default: {
83: return "UNKNOWN (" + type + ")";
84: }
85: }
86: }
87:
88: }
|