Coverage Report - org.apache.ojb.broker.locking.LockIsolationManager
 
Classes in this File Line Coverage Branch Coverage Complexity
LockIsolationManager
N/A
N/A
1.308
LockIsolationManager$ReadCommittedIsolation
N/A
N/A
1.308
LockIsolationManager$ReadUncommittedIsolation
N/A
N/A
1.308
LockIsolationManager$RepeatableReadIsolation
N/A
N/A
1.308
LockIsolationManager$SerializableIsolation
N/A
N/A
1.308
 
 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  
 
 19  
 
 20  
 /**
 21  
  * Factory class used to obtain the proper {@link LockIsolation} level.
 22  
  *
 23  
  * @version $Id: LockIsolationManager.java,v 1.1 2007-08-24 22:17:41 ewestfal Exp $
 24  
  */
 25  
 class LockIsolationManager
 26  
 {
 27  
     private LockIsolation readUncommitedStrategy;
 28  
     private LockIsolation readCommitedStrategy;
 29  
     private LockIsolation readRepeatableStrategy;
 30  
     private LockIsolation serializableStrategy;
 31  
 
 32  
     LockIsolationManager()
 33  
     {
 34  
         readUncommitedStrategy = new ReadUncommittedIsolation();
 35  
         readCommitedStrategy = new ReadCommittedIsolation();
 36  
         readRepeatableStrategy = new RepeatableReadIsolation();
 37  
         serializableStrategy = new SerializableIsolation();
 38  
     }
 39  
 
 40  
     /**
 41  
      * Obtains a lock isolation for Object obj. The Strategy to be used is
 42  
      * selected by evaluating the ClassDescriptor of obj.getClass().
 43  
      */
 44  
     public LockIsolation getStrategyFor(int isolationLevel)
 45  
     {
 46  
         switch(isolationLevel)
 47  
         {
 48  
             case LockManager.IL_READ_UNCOMMITTED:
 49  
                 return readUncommitedStrategy;
 50  
             case LockManager.IL_READ_COMMITTED:
 51  
                 return readCommitedStrategy;
 52  
             case LockManager.IL_REPEATABLE_READ:
 53  
                 return readRepeatableStrategy;
 54  
             case LockManager.IL_SERIALIZABLE:
 55  
                 return serializableStrategy;
 56  
             default:
 57  
                 return readUncommitedStrategy;
 58  
         }
 59  
     }
 60  
 
 61  
     //===============================================
 62  
     // inner class, LockIsolation implementation
 63  
     //===============================================
 64  
     /**
 65  
      * The implementation of the Uncommited Reads Locking strategy.
 66  
      * This strategy is the loosest of them all.  It says
 67  
      * you shouldn't need to get any Read locks whatsoever,
 68  
      * but since it will probably try to get them, it will
 69  
      * always give it to them.
 70  
      * <p/>
 71  
      * Allows:
 72  
      * Dirty Reads
 73  
      * Non-Repeatable Reads
 74  
      * Phantom Reads
 75  
      */
 76  
     class ReadUncommittedIsolation extends LockIsolation
 77  
     {
 78  
         ReadUncommittedIsolation()
 79  
         {
 80  
         }
 81  
 
 82  
         public int getIsolationLevel()
 83  
         {
 84  
             return LockManager.IL_READ_UNCOMMITTED;
 85  
         }
 86  
 
 87  
         public String getIsolationLevelAsString()
 88  
         {
 89  
             return LockManager.LITERAL_IL_READ_UNCOMMITTED;
 90  
         }
 91  
 
 92  
         public boolean allowMultipleRead()
 93  
         {
 94  
             return true;
 95  
         }
 96  
 
 97  
         public boolean allowWriteWhenRead()
 98  
         {
 99  
             return true;
 100  
         }
 101  
 
 102  
         public boolean allowReadWhenWrite()
 103  
         {
 104  
             return true;
 105  
         }
 106  
     }
 107  
 
 108  
 
 109  
     //===============================================
 110  
     // inner class, LockIsolation implementation
 111  
     //===============================================
 112  
     /**
 113  
      * The implementation of the Commited Reads Locking strategy.
 114  
      * ReadCommitted - Reads and Writes require locks.
 115  
      * <p/>
 116  
      * Locks are acquired for reading and modifying the database.
 117  
      * Locks are released after reading but locks on modified objects
 118  
      * are held until EOT.
 119  
      * <p/>
 120  
      * Allows:
 121  
      * Non-Repeatable Reads,
 122  
      * Phantom Reads.
 123  
      */
 124  
     class ReadCommittedIsolation extends LockIsolation
 125  
     {
 126  
         ReadCommittedIsolation()
 127  
         {
 128  
         }
 129  
 
 130  
         public int getIsolationLevel()
 131  
         {
 132  
             return LockManager.IL_READ_COMMITTED;
 133  
         }
 134  
 
 135  
         public String getIsolationLevelAsString()
 136  
         {
 137  
             return LockManager.LITERAL_IL_READ_COMMITTED;
 138  
         }
 139  
 
 140  
         public boolean allowMultipleRead()
 141  
         {
 142  
             return true;
 143  
         }
 144  
 
 145  
         public boolean allowWriteWhenRead()
 146  
         {
 147  
             return true;
 148  
         }
 149  
 
 150  
         public boolean allowReadWhenWrite()
 151  
         {
 152  
             return false;
 153  
         }
 154  
     }
 155  
 
 156  
 
 157  
     //===============================================
 158  
     // inner class, LockIsolation implementation
 159  
     //===============================================
 160  
     /**
 161  
      * The implementation of the Repeatable Reads Locking strategy.
 162  
      * Locks are obtained for reading and modifying the database.
 163  
      * Locks on all modified objects are held until EOT.
 164  
      * Locks obtained for reading data are held until EOT.
 165  
      * Allows:
 166  
      * Phantom Reads
 167  
      */
 168  
     class RepeatableReadIsolation extends LockIsolation
 169  
     {
 170  
         public RepeatableReadIsolation()
 171  
         {
 172  
         }
 173  
 
 174  
         public int getIsolationLevel()
 175  
         {
 176  
             return LockManager.IL_REPEATABLE_READ;
 177  
         }
 178  
 
 179  
         public String getIsolationLevelAsString()
 180  
         {
 181  
             return LockManager.LITERAL_IL_REPEATABLE_READ;
 182  
         }
 183  
 
 184  
         public boolean allowMultipleRead()
 185  
         {
 186  
             return true;
 187  
         }
 188  
 
 189  
         public boolean allowWriteWhenRead()
 190  
         {
 191  
             return false;
 192  
         }
 193  
 
 194  
         public boolean allowReadWhenWrite()
 195  
         {
 196  
             return false;
 197  
         }
 198  
     }
 199  
 
 200  
 
 201  
     //===============================================
 202  
     // inner class, LockIsolation implementation
 203  
     //===============================================
 204  
     /**
 205  
      * The implementation of the Serializable Locking strategy.
 206  
      */
 207  
     class SerializableIsolation extends LockIsolation
 208  
     {
 209  
 
 210  
         SerializableIsolation()
 211  
         {
 212  
         }
 213  
 
 214  
         public int getIsolationLevel()
 215  
         {
 216  
             return LockManager.IL_SERIALIZABLE;
 217  
         }
 218  
 
 219  
         public String getIsolationLevelAsString()
 220  
         {
 221  
             return LockManager.LITERAL_IL_SERIALIZABLE;
 222  
         }
 223  
 
 224  
         public boolean allowMultipleRead()
 225  
         {
 226  
             return false;
 227  
         }
 228  
 
 229  
         public boolean allowWriteWhenRead()
 230  
         {
 231  
             return false;
 232  
         }
 233  
 
 234  
         public boolean allowReadWhenWrite()
 235  
         {
 236  
             return false;
 237  
         }
 238  
     }
 239  
 }