KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > object > tx > TxnType


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.object.tx;
5
6 import com.tc.util.Assert;
7
8 /**
9  * 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(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 JavaDoc 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 JavaDoc 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