001 package org.apache.ojb.broker.locking;
002
003 /* Copyright 2002-2005 The Apache Software Foundation
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018 import org.apache.ojb.broker.util.logging.LoggerFactory;
019 import org.apache.commons.lang.StringUtils;
020
021 /**
022 * @author <a href="mailto:arminw@apache.org">Armin Waibel</a>
023 * @version $Id: LockHelper.java,v 1.1 2007-08-24 22:17:41 ewestfal Exp $
024 */
025 public class LockHelper
026 {
027 LockHelper()
028 {
029 }
030
031 /**
032 * maps IsolationLevel literals to the corresponding id
033 * @param isoLevel
034 * @return the id
035 */
036 public static int getIsolationLevelFor(String isoLevel)
037 {
038 if(isoLevel == null || StringUtils.isEmpty(isoLevel))
039 {
040 LoggerFactory.getDefaultLogger().debug(
041 "[LockHelper] Specified isolation level string is 'null', using the default isolation level");
042 return IsolationLevels.IL_DEFAULT;
043 }
044 if (isoLevel.equalsIgnoreCase(IsolationLevels.LITERAL_IL_READ_UNCOMMITTED))
045 {
046 return IsolationLevels.IL_READ_UNCOMMITTED;
047 }
048 else if (isoLevel.equalsIgnoreCase(IsolationLevels.LITERAL_IL_READ_COMMITTED))
049 {
050 return IsolationLevels.IL_READ_COMMITTED;
051 }
052 else if (isoLevel.equalsIgnoreCase(IsolationLevels.LITERAL_IL_REPEATABLE_READ))
053 {
054 return IsolationLevels.IL_REPEATABLE_READ;
055 }
056 else if (isoLevel.equalsIgnoreCase(IsolationLevels.LITERAL_IL_SERIALIZABLE))
057 {
058 return IsolationLevels.IL_SERIALIZABLE;
059 }
060 else if (isoLevel.equalsIgnoreCase(IsolationLevels.LITERAL_IL_OPTIMISTIC))
061 {
062 return IsolationLevels.IL_OPTIMISTIC;
063 }
064 else if (isoLevel.equalsIgnoreCase(IsolationLevels.LITERAL_IL_NONE))
065 {
066 return IsolationLevels.IL_NONE;
067 }
068 LoggerFactory.getDefaultLogger().warn("[LockHelper] Unknown isolation-level '" + isoLevel + "', using default isolation level");
069 return IsolationLevels.IL_DEFAULT;
070 }
071 }