01: /**********************************************************************
02: Copyright (c) 2007 Andy Jefferson and others. All rights reserved.
03: Licensed under the Apache License, Version 2.0 (the "License");
04: you may not use this file except in compliance with the License.
05: You may obtain a copy of the License at
06:
07: http://www.apache.org/licenses/LICENSE-2.0
08:
09: Unless required by applicable law or agreed to in writing, software
10: distributed under the License is distributed on an "AS IS" BASIS,
11: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: See the License for the specific language governing permissions and
13: limitations under the License.
14:
15: Contributors:
16: ...
17: **********************************************************************/package org.jpox.transaction;
18:
19: import org.jpox.UserTransaction;
20:
21: /**
22: * Utility methods relating to transactions.
23: *
24: * @version $Revision: 1.1 $
25: */
26: public class TransactionUtils {
27: /**
28: * Accessor for a string name of a transaction isolation level.
29: * @param isolation The isolation level (as defined by UserTransaction).
30: * @return The name
31: */
32: public static String getNameForTransactionIsolationLevel(
33: int isolation) {
34: if (isolation == UserTransaction.TRANSACTION_NONE) {
35: return "NONE";
36: } else if (isolation == UserTransaction.TRANSACTION_READ_COMMITTED) {
37: return "READ_COMMITTED";
38: } else if (isolation == UserTransaction.TRANSACTION_READ_UNCOMMITTED) {
39: return "READ_UNCOMMITTED";
40: } else if (isolation == UserTransaction.TRANSACTION_REPEATABLE_READ) {
41: return "REPEATABLE_READ";
42: } else if (isolation == UserTransaction.TRANSACTION_SERIALIZABLE) {
43: return "SERIALIZABLE";
44: } else {
45: return "UNKNOWN";
46: }
47: }
48:
49: /**
50: * Convenience method to convert the supplied isolation level name into the
51: * associated UserTransaction type number.
52: * @param isolationName The name of the isolation level
53: * @return Isolation level type
54: */
55: public static int getTransactionIsolationLevelForName(
56: String isolationName) {
57: if (isolationName.equalsIgnoreCase("NONE")) {
58: return UserTransaction.TRANSACTION_NONE;
59: } else if (isolationName.equalsIgnoreCase("READ_COMMITTED")) {
60: return UserTransaction.TRANSACTION_READ_COMMITTED;
61: } else if (isolationName.equalsIgnoreCase("READ_UNCOMMITTED")) {
62: return UserTransaction.TRANSACTION_READ_UNCOMMITTED;
63: } else if (isolationName.equalsIgnoreCase("REPEATABLE_READ")) {
64: return UserTransaction.TRANSACTION_REPEATABLE_READ;
65: } else if (isolationName.equalsIgnoreCase("SERIALIZABLE")) {
66: return UserTransaction.TRANSACTION_SERIALIZABLE;
67: } else {
68: return -1;
69: }
70: }
71: }
|