View Javadoc

1   package org.apache.ojb.broker.locking;
2   
3   /* Copyright 2002-2005 The Apache Software Foundation
4    *
5    * Licensed under the Apache License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    *
9    *     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 2007-08-24 22:17:41 ewestfal Exp $
24   */
25  public class LockHelper
26  {
27      LockHelper()
28      {
29      }
30  
31      /**
32       * maps IsolationLevel literals to the corresponding id
33       * @param isoLevel
34       * @return the id
35       */
36      public static int getIsolationLevelFor(String isoLevel)
37      {
38          if(isoLevel == null || StringUtils.isEmpty(isoLevel))
39          {
40              LoggerFactory.getDefaultLogger().debug(
41                      "[LockHelper] Specified isolation level string is 'null', using the default isolation level");
42              return IsolationLevels.IL_DEFAULT;
43          }
44          if (isoLevel.equalsIgnoreCase(IsolationLevels.LITERAL_IL_READ_UNCOMMITTED))
45          {
46              return IsolationLevels.IL_READ_UNCOMMITTED;
47          }
48          else if (isoLevel.equalsIgnoreCase(IsolationLevels.LITERAL_IL_READ_COMMITTED))
49          {
50              return IsolationLevels.IL_READ_COMMITTED;
51          }
52          else if (isoLevel.equalsIgnoreCase(IsolationLevels.LITERAL_IL_REPEATABLE_READ))
53          {
54              return IsolationLevels.IL_REPEATABLE_READ;
55          }
56          else if (isoLevel.equalsIgnoreCase(IsolationLevels.LITERAL_IL_SERIALIZABLE))
57          {
58              return IsolationLevels.IL_SERIALIZABLE;
59          }
60          else if (isoLevel.equalsIgnoreCase(IsolationLevels.LITERAL_IL_OPTIMISTIC))
61          {
62              return IsolationLevels.IL_OPTIMISTIC;
63          }
64          else if (isoLevel.equalsIgnoreCase(IsolationLevels.LITERAL_IL_NONE))
65          {
66              return IsolationLevels.IL_NONE;
67          }
68          LoggerFactory.getDefaultLogger().warn("[LockHelper] Unknown isolation-level '" + isoLevel + "', using default isolation level");
69          return IsolationLevels.IL_DEFAULT;
70      }
71  }