1 21 22 package org.apache.derby.impl.store.raw.data; 23 24 import org.apache.derby.iapi.services.locks.Lockable; 25 import org.apache.derby.iapi.services.sanity.SanityManager; 26 import org.apache.derby.iapi.error.StandardException; 27 import org.apache.derby.iapi.store.raw.StreamContainerHandle; 28 import org.apache.derby.iapi.store.raw.ContainerKey; 29 import org.apache.derby.iapi.store.raw.xact.RawTransaction; 30 31 import org.apache.derby.iapi.types.DataValueDescriptor; 32 33 import org.apache.derby.impl.store.raw.data.DropOnCommit; 34 35 import org.apache.derby.catalog.UUID; 36 37 import java.util.Observable ; 38 import java.util.Observer ; 39 import java.util.Properties ; 40 41 48 49 final class StreamFileContainerHandle 50 implements StreamContainerHandle, Observer 51 { 52 53 56 57 61 private final UUID rawStoreId; 62 63 67 protected final ContainerKey identity; 68 69 70 75 protected boolean active; 76 77 82 protected StreamFileContainer container; 83 84 89 protected RawTransaction xact; 90 91 97 private boolean hold; 98 99 102 public StreamFileContainerHandle( 103 UUID rawStoreId, 104 RawTransaction xact, 105 ContainerKey identity, 106 boolean hold) 107 { 108 this.identity = identity; 109 this.xact = xact; 110 this.rawStoreId = rawStoreId; 111 this.hold = hold; 112 } 113 114 public StreamFileContainerHandle( 115 UUID rawStoreId, 116 RawTransaction xact, 117 StreamFileContainer container, 118 boolean hold) 119 { 120 121 this.identity = container.getIdentity(); 122 this.xact = xact; 123 this.rawStoreId = rawStoreId; 124 this.hold = hold; 125 126 this.container = container; 127 128 } 130 131 134 135 142 public void getContainerProperties(Properties prop) 143 throws StandardException { 144 145 container.getContainerProperties(prop); 146 return; 147 } 148 149 154 public boolean fetchNext(DataValueDescriptor[] row) 155 throws StandardException { 156 157 return container.fetchNext(row); 158 } 159 160 165 public void close() 166 { 167 168 if (xact == null) { 169 170 if (SanityManager.DEBUG) 173 SanityManager.ASSERT(!active); 174 175 return; 176 } 177 178 active = false; 179 180 container.close(); 182 container = null; 183 184 xact.deleteObserver(this); 186 187 xact = null; 188 } 189 190 196 public void removeContainer() throws StandardException { 197 container.removeContainer(); 198 } 199 200 203 public ContainerKey getId() { 204 return identity; 205 } 206 207 210 211 216 public void update(Observable obj, Object arg) 217 { 218 if (SanityManager.DEBUG) { 219 if (arg == null) 220 SanityManager.THROWASSERT("still on observr list " + this); 221 } 222 223 if (xact == null) { 225 226 return; 227 } 228 229 if (SanityManager.DEBUG) { 230 232 if (obj != xact) 233 SanityManager.THROWASSERT("Observable passed to update is incorrect expected " 234 + xact + " got " + obj); 235 } 236 237 if (arg.equals(RawTransaction.COMMIT) || 239 arg.equals(RawTransaction.ABORT) || 240 arg.equals(identity)) 241 { 242 close(); 244 return; 245 246 } 247 248 if (arg.equals(RawTransaction.SAVEPOINT_ROLLBACK)) { 249 250 return; 252 } 253 } 254 255 262 263 269 public boolean useContainer() throws StandardException { 270 271 if (SanityManager.DEBUG) { 272 SanityManager.ASSERT(!active); 273 SanityManager.ASSERT(container != null); 274 } 275 276 if (!container.use(this)) { 278 container = null; 279 return false; 280 } 281 282 active = true; 283 284 if (!hold) 286 { 287 xact.addObserver(this); 288 xact.addObserver(new DropOnCommit(identity, true)); 289 } 290 291 return true; 292 } 293 294 297 public final RawTransaction getTransaction() { 298 299 if (SanityManager.DEBUG) { 300 SanityManager.ASSERT(xact != null); 301 } 302 303 return xact; 304 } 305 306 309 public String toString() { 310 if (SanityManager.DEBUG) { 311 String str = new String (); 312 str += "StreamContainerHandle:(" + identity.toString() + ")"; 313 return(str); 314 } else { 315 return(super.toString()); 316 } 317 } 318 } 319 320 | Popular Tags |