1 21 22 package org.apache.derby.impl.io; 23 24 import org.apache.derby.iapi.services.sanity.SanityManager; 25 26 import org.apache.derby.io.WritableStorageFactory; 27 import org.apache.derby.io.StorageFile; 28 import org.apache.derby.io.StorageRandomAccessFile; 29 30 import java.io.File ; 31 import java.io.FileNotFoundException ; 32 import java.io.FileOutputStream ; 33 import java.io.FileInputStream ; 34 import java.io.InputStream ; 35 import java.io.OutputStream ; 36 import java.io.IOException ; 37 import java.io.SyncFailedException ; 38 39 import java.util.Properties ; 40 41 45 46 public class DirStorageFactory extends BaseStorageFactory 47 implements WritableStorageFactory 48 { 49 56 public final StorageFile newStorageFile( String path) 57 { 58 return newPersistentFile( path); 59 } 60 61 69 public final StorageFile newStorageFile( String directoryName, String fileName) 70 { 71 return newPersistentFile( directoryName, fileName); 72 } 73 74 82 public final StorageFile newStorageFile( StorageFile directoryName, String fileName) 83 { 84 return newPersistentFile( directoryName, fileName); 85 } 86 94 StorageFile newPersistentFile( String path) 95 { 96 if( path == null) 97 return new DirFile( dataDirectory); 98 return new DirFile(dataDirectory, path); 99 } 100 101 110 StorageFile newPersistentFile( String directoryName, String fileName) 111 { 112 return new DirFile( separatedDataDirectory + directoryName, fileName); 113 } 114 115 124 StorageFile newPersistentFile( StorageFile directoryName, String fileName) 125 { 126 return new DirFile( (DirFile) directoryName, fileName); 127 } 128 129 145 public void sync( OutputStream stream, boolean metaData) throws IOException , SyncFailedException 146 { 147 ((FileOutputStream ) stream).getFD().sync(); 148 } 149 150 158 public boolean supportsRws() 159 { 160 return false; 161 } 162 163 public boolean isReadOnlyDatabase() 164 { 165 return false; 166 } 167 168 174 public boolean supportsRandomAccess() 175 { 176 return true; 177 } 178 179 void doInit() throws IOException 180 { 181 if( dataDirectory != null) 182 { 183 File dataDirectoryFile = new File( dataDirectory); 184 File databaseRoot = null; 185 if( dataDirectoryFile.isAbsolute()) 186 databaseRoot = dataDirectoryFile; 187 else if( home != null && dataDirectory.startsWith( home)) 188 databaseRoot = dataDirectoryFile; 189 else 190 { 191 databaseRoot = new File( home, dataDirectory); 192 if (home != null) 193 dataDirectory = home + getSeparator() + dataDirectory; 194 } 195 canonicalName = databaseRoot.getCanonicalPath(); 196 createTempDir(); 197 separatedDataDirectory = dataDirectory + getSeparator(); 198 } 199 else if( home != null) 200 { 201 File root = new File( home); 202 dataDirectory = root.getCanonicalPath(); 203 separatedDataDirectory = dataDirectory + getSeparator(); 204 } 205 } } 207 | Popular Tags |