/*
 * JBoss, Home of Professional Open Source
 * Copyright 2005, JBoss Inc., and individual contributors as indicated
 * by the @authors tag. See the copyright.txt in the distribution for a
 * full listing of individual contributors.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package org.jboss.cache.lock;


/**
 * Factory to create LockStragtegy instance.
 *
 * @author Ben Wang
 */
public class LockStrategyFactory
{

   /**
    * Transaction locking isolation level. Default.
    */
   private static IsolationLevel lockingLevel_ = IsolationLevel.REPEATABLE_READ;

   /**
    *
    */
   protected LockStrategyFactory()
   {
   }

   public static LockStrategy getLockStrategy() {
      return getLockStrategy(lockingLevel_);
   }

   public static LockStrategy getLockStrategy(IsolationLevel lockingLevel)
   {
      //if(log_.isTraceEnabled()) {
        // log_.trace("LockStrategy is: " + lockingLevel);
      //}
      if (lockingLevel == null || lockingLevel == IsolationLevel.NONE)
         return new LockStrategyNone();
      if (lockingLevel == IsolationLevel.REPEATABLE_READ)
         return new LockStrategyRepeatableRead();
      if (lockingLevel == IsolationLevel.SERIALIZABLE)
         return new LockStrategySerializable();
      if (lockingLevel == IsolationLevel.READ_COMMITTED)
         return new LockStrategyReadCommitted();
      if (lockingLevel == IsolationLevel.READ_UNCOMMITTED)
         return new LockStrategyReadUncommitted();
      if(lockingLevel == IsolationLevel.BELA)
         return new BelasLockStrategy();
      throw new RuntimeException("getLockStrategy: LockStrategy selection not recognized." +
            " selection: " + lockingLevel);
   }

   public static void setIsolationLevel(IsolationLevel level)
   {
      lockingLevel_ = level;
   }

}
