#51504: Eliminating redundant storage file name instance from LogFile. BLD200502231900
authormmatula@netbeans.org
Tue, 22 Feb 2005 13:40:13 +0000
changeset 166479270a45ef2d
parent 1663 4e4e7f740ebe
child 1665 abf774742624
#51504: Eliminating redundant storage file name instance from LogFile.
mdr/src/org/netbeans/mdr/persistence/btreeimpl/btreestorage/BtreeDatabase.java
mdr/src/org/netbeans/mdr/persistence/btreeimpl/btreestorage/FileCache.java
mdr/src/org/netbeans/mdr/persistence/btreeimpl/btreestorage/LogFile.java
     1.1 --- a/mdr/src/org/netbeans/mdr/persistence/btreeimpl/btreestorage/BtreeDatabase.java	Mon Feb 21 18:52:37 2005 +0000
     1.2 +++ b/mdr/src/org/netbeans/mdr/persistence/btreeimpl/btreestorage/BtreeDatabase.java	Tue Feb 22 13:40:13 2005 +0000
     1.3 @@ -145,19 +145,20 @@
     1.4          open(isNew);
     1.5      }
     1.6  
     1.7 -    private static final int DFL = 0;
     1.8 -    private static final int IFL = 1;
     1.9 -    private static final int LFL = 2;
    1.10 +    static final int DFL = 0;
    1.11 +    static final int IFL = 1;
    1.12 +    static final int LFL = 2;
    1.13 +    private static final String[] SUFFIXES = {".btd", ".btx", ".btb"};
    1.14  
    1.15      /* construct names of repository files */
    1.16      private static String[] getFileNames(String base) {
    1.17 -    	String names[] = new String[3];
    1.18 -	names[DFL] = base.concat(".btd");
    1.19 -	names[IFL] = base.concat(".btx");
    1.20 -	names[LFL] = base.concat(".btb");
    1.21 -
    1.22 +    	String names[] = new String[] {getFileName(base, 0), getFileName(base, 1), getFileName(base, 2)};
    1.23  	return names;
    1.24      }
    1.25 +    
    1.26 +    static String getFileName(String base, int type) {
    1.27 +        return base.concat(SUFFIXES[type]);
    1.28 +    }
    1.29  
    1.30      /** See if repository currenly exists */
    1.31      static boolean exists(String base) {
    1.32 @@ -268,7 +269,7 @@
    1.33  	    }
    1.34  	}
    1.35  
    1.36 -        fileCache = new FileCache(fileNames, names[LFL]);
    1.37 +        fileCache = new FileCache(fileNames, repositoryName);
    1.38          boolean failure = true;
    1.39          try {
    1.40              dataFile = new BtreeDataFile(this.myStorage, fileCache, 0);
    1.41 @@ -322,7 +323,7 @@
    1.42  
    1.43  	BtreeDataFile.create( this.myStorage, copyNames[DFL], new FileHeader(), PAGE_SIZE, false);
    1.44  	try {
    1.45 -	    copyCache = new FileCache(fileNames, copyNames[LFL]);
    1.46 +	    copyCache = new FileCache(fileNames, target);
    1.47  	    copyFile = new BtreeDataFile(this.myStorage, copyCache, 0);
    1.48  	    dataFile.copy(copyFile);
    1.49  	    copyCache.commit();
     2.1 --- a/mdr/src/org/netbeans/mdr/persistence/btreeimpl/btreestorage/FileCache.java	Mon Feb 21 18:52:37 2005 +0000
     2.2 +++ b/mdr/src/org/netbeans/mdr/persistence/btreeimpl/btreestorage/FileCache.java	Tue Feb 22 13:40:13 2005 +0000
     2.3 @@ -146,7 +146,7 @@
     2.4      * headers, or the log file exists but is not consistent with the files
     2.5      * @exception ConsistencyException if the log file exists and is corrupted
     2.6      */
     2.7 -    public FileCache(String fileNames[], String logName) 
     2.8 +    public FileCache(String fileNames[], String baseName) 
     2.9              throws StorageException {
    2.10  
    2.11          boolean failure = true;
    2.12 @@ -163,7 +163,7 @@
    2.13                  tmpHeader = new FileHeader(files[0]);
    2.14  
    2.15                  log = new LogFile(
    2.16 -                    this, logName, BtreeDatabase.PAGE_SIZE, fileNames.length, tmpHeader.fileId);
    2.17 +                    this, baseName, BtreeDatabase.PAGE_SIZE, fileNames.length, tmpHeader.fileId);
    2.18  
    2.19                  for (int i = 0; i < fileNames.length; i++) {
    2.20                      fileSize[i] = (int)files[i].length();
     3.1 --- a/mdr/src/org/netbeans/mdr/persistence/btreeimpl/btreestorage/LogFile.java	Mon Feb 21 18:52:37 2005 +0000
     3.2 +++ b/mdr/src/org/netbeans/mdr/persistence/btreeimpl/btreestorage/LogFile.java	Tue Feb 22 13:40:13 2005 +0000
     3.3 @@ -39,7 +39,7 @@
     3.4      private int numFiles;
     3.5  
     3.6      /* name of the log file */
     3.7 -    private String fileName;
     3.8 +    private final String baseName;
     3.9  
    3.10      /* the log file */
    3.11      private RandomAccessFile file;
    3.12 @@ -64,7 +64,7 @@
    3.13      /** Create the log file.  If the file already exists on disk, 
    3.14      * attempt recovery.  Note that exceptions pnly occur during recovery.
    3.15      * @param fCache the cache which owns this log file
    3.16 -    * @param name the name of the log file
    3.17 +    * @param baseName the name of the log file without the suffix - i.e. name of the repository
    3.18      * @param pgSz the page size
    3.19      * @param files the number of files being logged
    3.20      * @param id the fileId for the files being logged
    3.21 @@ -73,20 +73,20 @@
    3.22      * the files being recovered
    3.23      * @exception ConsistencyException the log file is corrupt on disk
    3.24      */
    3.25 -    LogFile(FileCache fCache, String name, int pgSz, int files, long id) 
    3.26 +    LogFile(FileCache fCache, String baseName, int pgSz, int files, long id) 
    3.27              throws StorageException {
    3.28          // Size must be a power of 2 and >= 4096
    3.29          // no more than 4096 files
    3.30          cache = fCache;
    3.31          pageSize = pgSz;
    3.32 -        fileName = name;
    3.33 +        this.baseName = baseName;
    3.34          numFiles = files;
    3.35          fileId = id;
    3.36          pageBitmaps = new BitSet[files];
    3.37          for (int i = 0; i < files; i++)
    3.38              pageBitmaps[i] = new BitSet();
    3.39  
    3.40 -        if (new File(name).exists())
    3.41 +        if (new File(BtreeDatabase.getFileName(baseName, BtreeDatabase.LFL)).exists())
    3.42              recover();
    3.43      }
    3.44  
    3.45 @@ -98,7 +98,7 @@
    3.46      /* create the log file */
    3.47      private void createPhysicalLog() throws StorageException {
    3.48          try {
    3.49 -            file = new RandomAccessFile(fileName, "rw");
    3.50 +            file = new RandomAccessFile(BtreeDatabase.getFileName(baseName, BtreeDatabase.LFL), "rw");
    3.51              file.setLength(0);
    3.52              writeMap();
    3.53          }
    3.54 @@ -203,7 +203,7 @@
    3.55          try {
    3.56              if (file != null) {
    3.57                  file.close();
    3.58 -                (new File(fileName)).delete();
    3.59 +                (new File(BtreeDatabase.getFileName(baseName, BtreeDatabase.LFL))).delete();
    3.60              }
    3.61          }
    3.62          catch (IOException ex) {
    3.63 @@ -246,7 +246,7 @@
    3.64  
    3.65          try {
    3.66              try {
    3.67 -                logFile = new RandomAccessFile(fileName, "r");
    3.68 +                logFile = new RandomAccessFile(BtreeDatabase.getFileName(baseName, BtreeDatabase.LFL), "r");
    3.69                  files = cache.getFiles();
    3.70  
    3.71                  if (files.length != numFiles) {
    3.72 @@ -287,7 +287,7 @@
    3.73  
    3.74                      page.truncateFiles(files);
    3.75                      logFile.close();
    3.76 -                    (new File(fileName)).delete();
    3.77 +                    (new File(BtreeDatabase.getFileName(baseName, BtreeDatabase.LFL))).delete();
    3.78                  }
    3.79              }
    3.80              finally  {