01: package org.apache.ojb.broker.locking;
02:
03: /* Copyright 2002-2005 The Apache Software Foundation
04: *
05: * Licensed under the Apache License, Version 2.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: import org.apache.ojb.broker.util.logging.LoggerFactory;
19: import org.apache.commons.lang.StringUtils;
20:
21: /**
22: * @author <a href="mailto:arminw@apache.org">Armin Waibel</a>
23: * @version $Id: LockHelper.java,v 1.1.2.2 2005/12/21 22:25:32 tomdz Exp $
24: */
25: public class LockHelper {
26: LockHelper() {
27: }
28:
29: /**
30: * maps IsolationLevel literals to the corresponding id
31: * @param isoLevel
32: * @return the id
33: */
34: public static int getIsolationLevelFor(String isoLevel) {
35: if (isoLevel == null || StringUtils.isEmpty(isoLevel)) {
36: LoggerFactory
37: .getDefaultLogger()
38: .debug(
39: "[LockHelper] Specified isolation level string is 'null', using the default isolation level");
40: return IsolationLevels.IL_DEFAULT;
41: }
42: if (isoLevel
43: .equalsIgnoreCase(IsolationLevels.LITERAL_IL_READ_UNCOMMITTED)) {
44: return IsolationLevels.IL_READ_UNCOMMITTED;
45: } else if (isoLevel
46: .equalsIgnoreCase(IsolationLevels.LITERAL_IL_READ_COMMITTED)) {
47: return IsolationLevels.IL_READ_COMMITTED;
48: } else if (isoLevel
49: .equalsIgnoreCase(IsolationLevels.LITERAL_IL_REPEATABLE_READ)) {
50: return IsolationLevels.IL_REPEATABLE_READ;
51: } else if (isoLevel
52: .equalsIgnoreCase(IsolationLevels.LITERAL_IL_SERIALIZABLE)) {
53: return IsolationLevels.IL_SERIALIZABLE;
54: } else if (isoLevel
55: .equalsIgnoreCase(IsolationLevels.LITERAL_IL_OPTIMISTIC)) {
56: return IsolationLevels.IL_OPTIMISTIC;
57: } else if (isoLevel
58: .equalsIgnoreCase(IsolationLevels.LITERAL_IL_NONE)) {
59: return IsolationLevels.IL_NONE;
60: }
61: LoggerFactory.getDefaultLogger().warn(
62: "[LockHelper] Unknown isolation-level '" + isoLevel
63: + "', using default isolation level");
64: return IsolationLevels.IL_DEFAULT;
65: }
66: }
|