1 4 package com.tc.object.tx; 5 6 import com.tc.util.Assert; 7 8 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(TYPE_CONCURRENT); 19 20 public static TxnType typeFor(byte type) { 21 switch (type) { 22 case TYPE_RO: { 23 return READ_ONLY; 24 } 25 case TYPE_NORMAL: { 26 return NORMAL; 27 } 28 case TYPE_CONCURRENT: { 29 return CONCURRENT; 30 } 31 default: { 32 throw Assert.failure("unknown transaction type " + type); 33 } 34 } 35 } 36 37 public boolean isConcurrent() { 38 return this == CONCURRENT; 39 } 40 41 public boolean equals(Object other) { 42 return this == other; 43 } 44 45 public int hashCode() { 46 return this.type; 47 } 48 49 private final byte type; 50 51 private TxnType(byte type) { 52 this.type = type; 53 } 54 55 public byte getType() { 56 return type; 57 } 58 59 public String toString() { 60 switch (type) { 61 case TYPE_RO: { 62 return "READ_ONLY"; 63 } 64 case TYPE_NORMAL: { 65 return "NORMAL"; 66 } 67 case TYPE_CONCURRENT: { 68 return "CONCURRENT"; 69 } 70 default: { 71 return "UNKNOWN (" + type + ")"; 72 } 73 } 74 } 75 76 } 77 | Popular Tags |