1 21 22 package org.apache.derby.impl.store.raw.data; 23 24 import org.apache.derby.impl.store.raw.data.FileContainer; 25 26 import org.apache.derby.iapi.store.raw.ContainerKey; 27 28 import org.apache.derby.iapi.error.StandardException; 29 import org.apache.derby.iapi.store.raw.log.LogInstant; 30 import org.apache.derby.iapi.services.sanity.SanityManager; 31 import org.apache.derby.impl.store.raw.data.BaseDataFileFactory; 32 33 import org.apache.derby.iapi.services.io.InputStreamUtil; 34 import org.apache.derby.iapi.reference.SQLState; 35 36 import org.apache.derby.io.StorageFile; 37 38 import java.io.InputStream ; 39 import java.io.IOException ; 40 import java.io.DataInputStream ; 41 42 47 48 final class InputStreamContainer extends FileContainer { 49 50 private StorageFile containerPath; 51 52 55 56 InputStreamContainer(BaseDataFileFactory factory) { 57 super(factory); 58 canUpdate = false; 59 } 60 61 final boolean openContainer(ContainerKey newIdentity) throws StandardException { 62 DataInputStream dis = null; 63 try 64 { 65 InputStream is = null; 66 containerPath = dataFactory.getContainerPath(newIdentity, false); 67 try 68 { 69 is = containerPath.getInputStream(); 70 } 71 catch (IOException ioe) 72 { 73 containerPath = dataFactory.getContainerPath(newIdentity, true); 75 try 76 { 77 is = getInputStream(); 78 } 79 catch (IOException ioe2) 80 { 81 containerPath = null; 82 return false; 83 } 84 } 85 86 dis = new DataInputStream (is); 87 88 readHeader(dis); 93 94 return true; 95 96 } catch (IOException ioe) { 97 throw StandardException. 98 newException(SQLState.FILE_CONTAINER_EXCEPTION, ioe, this); 99 } finally { 100 if (dis != null) { 101 try { 102 dis.close(); 103 } catch (IOException ioe) {} 104 } 105 } 106 } 108 void closeContainer() 109 { 110 containerPath = null; 111 } 112 113 120 public final void clean(boolean forRemove) throws StandardException { 121 122 124 } 125 126 129 protected final int preAllocate(long lastPreallocPagenum, int preAllocSize) { 130 131 return 0; 133 } 134 135 protected void truncatePages(long lastValidPagenum) 136 { 137 return; 139 } 140 141 142 145 146 150 void createContainer(ContainerKey newIdentity) throws StandardException { 151 } 153 154 155 156 159 protected final void removeContainer(LogInstant instant, boolean leaveStub) throws StandardException 160 { 161 } 163 164 167 168 173 protected final void readPage(long pageNumber, byte[] pageData) 174 throws IOException , StandardException 175 { 176 177 if (SanityManager.DEBUG) { 178 SanityManager.ASSERT(!getCommittedDropState()); 179 } 180 181 long pageOffset = pageNumber * pageSize; 182 183 readPositionedPage(pageOffset, pageData); 184 185 if (dataFactory.databaseEncrypted() && 186 pageNumber != FIRST_ALLOC_PAGE_NUMBER) 187 { 188 decryptPage(pageData, pageSize); 189 } 190 } 191 192 197 protected void readPositionedPage(long pageOffset, byte[] pageData) throws IOException { 198 199 200 InputStream is = null; 201 try { 202 is = getInputStream(); 204 205 InputStreamUtil.skipBytes(is, pageOffset); 206 207 InputStreamUtil.readFully(is, pageData, 0, pageSize); 208 209 is.close(); 210 is = null; 211 } finally { 212 if (is != null) { 213 try {is.close();} catch (IOException ioe) {} 214 } 215 } 216 } 217 218 223 protected final void writePage(long pageNumber, byte[] pageData, boolean syncPage) 224 throws IOException , StandardException { 225 } 226 227 protected final void flushAll() { 228 } 229 230 233 protected InputStream getInputStream() throws IOException 234 { 235 return containerPath.getInputStream(); 236 } 237 238 239 247 protected void backupContainer(BaseContainerHandle handle, String backupLocation) 248 throws StandardException 249 { 250 throw StandardException.newException( 251 SQLState.STORE_FEATURE_NOT_IMPLEMENTED); 252 } 253 254 255 261 protected void encryptContainer(BaseContainerHandle handle, 262 String newFilePath) 263 throws StandardException 264 { 265 throw StandardException.newException( 266 SQLState.STORE_FEATURE_NOT_IMPLEMENTED); 267 } 268 269 } 270 | Popular Tags |