Coverage Report - org.apache.ojb.odmg.locking.LockManagerDefaultImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
LockManagerDefaultImpl
N/A
N/A
1.462
 
 1  
 package org.apache.ojb.odmg.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.Identity;
 19  
 import org.apache.ojb.broker.util.logging.Logger;
 20  
 import org.apache.ojb.broker.util.logging.LoggerFactory;
 21  
 import org.apache.ojb.odmg.TransactionImpl;
 22  
 
 23  
 /**
 24  
  * The OJB default implementation of a Locking mechanism.
 25  
  * This Implementation supports 4 transaction isolation levels
 26  
  * as specified in the interface {@link org.apache.ojb.broker.locking.IsolationLevels}:
 27  
  *     public final int IL_READ_UNCOMMITTED = 0;
 28  
  *     public final int IL_READ_COMMITTED = 1;
 29  
  *     public final int IL_REPEATABLE_READ = 2;
 30  
  *     public final int IL_SERIALIZABLE = 3;
 31  
  * Isolationlevels can be adjusted per class.
 32  
  * The proper lockhandling is done in the respective LockStrategy implementation.
 33  
  * This default implementation provides persistent Locks that are stored in
 34  
  * a special database table.
 35  
  * To keep the locks in the database and not in memory allows to use
 36  
  * them accross multiple distributed ODMG clients.
 37  
  *
 38  
  * Of course this solution causes a lot of database reads and writes even if
 39  
  * no real application data is written to the database. This solution may
 40  
  * thus not be suited for all environments. As the LockManager is pluggable
 41  
  * its possible to replace the default implementation by user defined
 42  
  * implementations.
 43  
  * A different solution might be to implement the LockManager as an additional
 44  
  * standalone server, that allows to elminate additional db reads and writes.
 45  
  *
 46  
  * @author thma
 47  
  * @deprecated 
 48  
  */
 49  
 public class LockManagerDefaultImpl implements LockManager
 50  
 {
 51  
     private Logger log = LoggerFactory.getLogger(LockManagerDefaultImpl.class);
 52  
 
 53  
     public LockManagerDefaultImpl()
 54  
     {
 55  
     }
 56  
 
 57  
     /**
 58  
      * aquires a readlock for transaction tx on object obj.
 59  
      * Returns true if successful, else false.
 60  
      */
 61  
     public synchronized boolean readLock(TransactionImpl tx, Object obj)
 62  
     {
 63  
         if (log.isDebugEnabled()) log.debug("LM.readLock(tx-" + tx.getGUID() + ", " + new Identity(obj, tx.getBroker()).toString() + ")");
 64  
         LockStrategy lockStrategy = LockStrategyFactory.getStrategyFor(obj);
 65  
         return lockStrategy.readLock(tx, obj);
 66  
     }
 67  
 
 68  
     public boolean readLock(TransactionImpl tx, Identity oid, Object obj)
 69  
     {
 70  
         return readLock(tx,obj);
 71  
     }
 72  
 
 73  
     /**
 74  
      * aquires a writelock for transaction tx on object obj.
 75  
      * Returns true if successful, else false.
 76  
      */
 77  
     public synchronized boolean writeLock(TransactionImpl tx, Object obj)
 78  
     {
 79  
         if (log.isDebugEnabled()) log.debug("LM.writeLock(tx-" + tx.getGUID() + ", " + new Identity(obj, tx.getBroker()).toString() + ")");
 80  
         LockStrategy lockStrategy = LockStrategyFactory.getStrategyFor(obj);
 81  
         return lockStrategy.writeLock(tx, obj);
 82  
     }
 83  
 
 84  
     public boolean writeLock(TransactionImpl tx, Identity oid, Object obj)
 85  
     {
 86  
         return writeLock(tx, obj);
 87  
     }
 88  
 
 89  
     /**
 90  
      * upgrades readlock for transaction tx on object obj to a writelock.
 91  
      * If no readlock existed a writelock is acquired anyway.
 92  
      * Returns true if successful, else false.
 93  
      */
 94  
     public synchronized boolean upgradeLock(TransactionImpl tx, Object obj)
 95  
     {
 96  
         if (log.isDebugEnabled()) log.debug("LM.upgradeLock(tx-" + tx.getGUID() + ", " + new Identity(obj, tx.getBroker()).toString() + ")");
 97  
         LockStrategy lockStrategy = LockStrategyFactory.getStrategyFor(obj);
 98  
         return lockStrategy.upgradeLock(tx, obj);
 99  
     }
 100  
 
 101  
     public boolean upgradeLock(TransactionImpl tx, Identity oid, Object obj)
 102  
     {
 103  
         return upgradeLock(tx, obj);
 104  
     }
 105  
 
 106  
     /**
 107  
      * releases a lock for transaction tx on object obj.
 108  
      * Returns true if successful, else false.
 109  
      */
 110  
     public synchronized boolean releaseLock(TransactionImpl tx, Object obj)
 111  
     {
 112  
         if (log.isDebugEnabled()) log.debug("LM.releaseLock(tx-" + tx.getGUID() + ", " + new Identity(obj, tx.getBroker()).toString() + ")");
 113  
         LockStrategy lockStrategy = LockStrategyFactory.getStrategyFor(obj);
 114  
         return lockStrategy.releaseLock(tx, obj);
 115  
     }
 116  
 
 117  
     public boolean releaseLock(TransactionImpl tx, Identity oid, Object obj)
 118  
     {
 119  
         return releaseLock(tx, obj);
 120  
     }
 121  
 
 122  
     /**
 123  
      * checks if there is a readlock for transaction tx on object obj.
 124  
      * Returns true if so, else false.
 125  
      */
 126  
     public synchronized boolean checkRead(TransactionImpl tx, Object obj)
 127  
     {
 128  
         if (log.isDebugEnabled()) log.debug("LM.checkRead(tx-" + tx.getGUID() + ", " + new Identity(obj, tx.getBroker()).toString() + ")");
 129  
         LockStrategy lockStrategy = LockStrategyFactory.getStrategyFor(obj);
 130  
         return lockStrategy.checkRead(tx, obj);
 131  
     }
 132  
 
 133  
     public boolean checkRead(TransactionImpl tx, Identity oid, Object obj)
 134  
     {
 135  
         return checkRead(tx, obj);
 136  
     }
 137  
 
 138  
     /**
 139  
      * checks if there is a writelock for transaction tx on object obj.
 140  
      * Returns true if so, else false.
 141  
      */
 142  
     public synchronized boolean checkWrite(TransactionImpl tx, Object obj)
 143  
     {
 144  
         if (log.isDebugEnabled()) log.debug("LM.checkWrite(tx-" + tx.getGUID() + ", " + new Identity(obj, tx.getBroker()).toString() + ")");
 145  
         LockStrategy lockStrategy = LockStrategyFactory.getStrategyFor(obj);
 146  
         return lockStrategy.checkWrite(tx, obj);
 147  
     }
 148  
 
 149  
     public boolean checkWrite(TransactionImpl tx, Identity oid, Object obj)
 150  
     {
 151  
         return checkWrite(tx, obj);
 152  
     }
 153  
 }