1 package org.apache.ojb.odmg.locking; 2 3 17 18 import org.apache.ojb.odmg.TransactionImpl; 19 20 34 public class ReadCommittedStrategy extends AbstractLockStrategy 35 { 36 37 44 public boolean readLock(TransactionImpl tx, Object obj) 45 { 46 47 LockEntry writer = getWriter(obj); 48 if (writer == null) 49 { 50 addReader(tx, obj); 51 if (getWriter(obj) == null) 53 return true; 54 else 55 { 56 removeReader(tx, obj); 57 return readLock(tx, obj); 58 } 59 } 60 if (writer.isOwnedBy(tx)) 61 { 62 return true; } 64 else 65 { 66 return false; 67 } 68 } 69 70 77 public boolean writeLock(TransactionImpl tx, Object obj) 78 { 79 LockEntry writer = getWriter(obj); 80 if (writer == null) 82 { 83 if (setWriter(tx, obj)) 85 return true; 86 else 88 return writeLock(tx, obj); 89 } 90 if (writer.isOwnedBy(tx)) 91 { 92 return true; } 94 95 return false; 96 } 97 98 105 public boolean upgradeLock(TransactionImpl tx, Object obj) 106 { 107 LockEntry writer = getWriter(obj); 108 if (writer == null) 109 { 110 if (setWriter(tx, obj)) 112 return true; 113 else 115 return upgradeLock(tx, obj); 116 } 117 if (writer.isOwnedBy(tx)) 118 { 119 return true; } 121 122 return false; 123 } 124 125 132 public boolean releaseLock(TransactionImpl tx, Object obj) 133 { 134 LockEntry writer = getWriter(obj); 135 136 if (writer != null && writer.isOwnedBy(tx)) 137 { 138 removeWriter(writer); 139 return true; 140 } 141 142 if (hasReadLock(tx, obj)) 143 { 144 removeReader(tx, obj); 145 return true; 146 } 147 return false; 148 } 149 150 156 public boolean checkRead(TransactionImpl tx, Object obj) 157 { 158 if (hasReadLock(tx, obj)) 159 { 160 return true; 161 } 162 LockEntry writer = getWriter(obj); 163 if (writer.isOwnedBy(tx)) 164 { 165 return true; 166 } 167 return false; 168 } 169 170 176 public boolean checkWrite(TransactionImpl tx, Object obj) 177 { 178 LockEntry writer = getWriter(obj); 179 if (writer == null) 180 return false; 181 else if (writer.isOwnedBy(tx)) 182 return true; 183 else 184 return false; 185 } 186 } 187 | Popular Tags |