1 package org.apache.ojb.broker.locking; 2 3 17 18 19 20 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 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 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 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 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 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 } 240 | Popular Tags |