1 21 22 package org.apache.derby.impl.store.raw.data; 23 24 import org.apache.derby.impl.store.raw.data.BaseContainerHandle; 25 import org.apache.derby.impl.store.raw.data.BasePage; 26 27 import org.apache.derby.iapi.services.cache.Cacheable; 28 import org.apache.derby.iapi.services.sanity.SanityManager; 29 30 import org.apache.derby.iapi.error.StandardException; 31 import org.apache.derby.iapi.store.raw.xact.RawTransaction; 32 import org.apache.derby.iapi.store.raw.ContainerHandle; 33 import org.apache.derby.iapi.store.raw.ContainerKey; 34 import org.apache.derby.iapi.store.raw.Page; 35 import org.apache.derby.iapi.store.raw.log.LogInstant; 36 import org.apache.derby.iapi.store.raw.data.RawContainerHandle; 37 38 import org.apache.derby.io.StorageFactory; 39 import org.apache.derby.io.StorageFile; 40 41 import java.io.IOException ; 42 43 52 class TempRAFContainer extends RAFContainer { 53 54 protected int inUseCount; 55 56 TempRAFContainer(BaseDataFileFactory factory) { 57 super(factory); 58 } 59 60 63 public Cacheable setIdentity(Object key) throws StandardException { 64 65 ContainerKey newIdentity = (ContainerKey) key; 66 if (newIdentity.getSegmentId() != ContainerHandle.TEMPORARY_SEGMENT) { 67 68 RAFContainer realContainer = new RAFContainer(dataFactory); 69 return realContainer.setIdent(newIdentity); 70 } 71 72 return super.setIdentity(newIdentity); 73 74 } 75 76 79 public Cacheable createIdentity(Object key, Object createParameter) throws StandardException { 80 81 ContainerKey newIdentity = (ContainerKey) key; 82 83 if (newIdentity.getSegmentId() != ContainerHandle.TEMPORARY_SEGMENT) { 84 RAFContainer realContainer = new RAFContainer(dataFactory); 85 return realContainer.createIdentity(newIdentity, createParameter); 86 } 87 88 return createIdent(newIdentity, createParameter); 89 } 90 91 94 public void removeContainer(LogInstant instant, boolean leaveStub) throws StandardException 95 { 96 pageCache.discard(identity); 98 99 synchronized(this) { 100 setDroppedState(true); 102 setCommittedDropState(true); 103 setDirty(false); 104 needsSync = false; 105 106 } 107 108 removeFile(getFileName(identity, false, false, false)); 109 } 110 111 115 protected int preAllocate(long lastPreallocPagenum, int preAllocSize) 116 { 117 return 0; 118 } 119 120 121 127 protected void writePage(long pageNumber, byte[] pageData, boolean syncPage) throws IOException , StandardException { 128 if (!this.getDroppedState()) { 129 super.writePage(pageNumber, pageData, false); 130 } 131 needsSync = false; 132 } 133 134 StorageFile getFileName(ContainerKey identity, boolean stub, 135 boolean errorOK, boolean tryAlternatePath) 136 { 137 return privGetFileName( identity, stub, errorOK, tryAlternatePath); 138 } 139 140 protected StorageFile privGetFileName(ContainerKey identity, boolean stub, 141 boolean errorOK, boolean tryAlternatePath) 142 { 143 return dataFactory.storageFactory.newStorageFile( dataFactory.storageFactory.getTempDir(), 144 "T" + identity.getContainerId() + ".tmp"); 145 } 146 147 153 public Page addPage(BaseContainerHandle handle, boolean isOverflow) throws StandardException { 154 155 BasePage newPage = newPage(handle, (RawTransaction) null, handle, isOverflow); 156 157 if (SanityManager.DEBUG) { 158 SanityManager.ASSERT(newPage.isLatched()); 159 } 160 161 return newPage; 162 } 163 164 167 public void truncate(BaseContainerHandle handle) throws StandardException { 168 169 synchronized(this) 171 { 172 setDroppedState(true); 173 setCommittedDropState(true); 174 setDirty(false); 175 needsSync = false; 176 } 177 178 while (pageCache.discard(identity) != true) 180 ; 181 182 removeFile(getFileName(identity, false, true, false)); 183 184 createIdent(identity, this); 185 186 addPage(handle, false).unlatch(); 187 } 188 197 protected boolean use(BaseContainerHandle handle, boolean forUpdate, 198 boolean droppedOK) 199 throws StandardException { 200 201 if (super.use(handle, forUpdate, droppedOK)) { 202 inUseCount++; 203 return true; 204 } 205 206 return false; 207 } 208 209 215 protected void letGo(BaseContainerHandle handle) { 216 217 inUseCount--; 218 super.letGo(handle); 219 } 220 221 222 225 public boolean isSingleUser() { 226 return inUseCount == 1; 227 } 228 } 229 | Popular Tags |