public Database(String fileDir) throws DatabaseException {
  this.fileDir=fileDir;
  numTransactions=0;
  tableLookup=new ConcurrentHashMap<String,Table>();
  indexLookup=new ConcurrentHashMap<String,BPlusTree>();
  File dir=new File(fileDir);
  lockMan=new LockManager();
  if (!dir.exists()) {
    dir.mkdirs();
  }
  File[] files=dir.listFiles();
  for (  File f : files) {
    String fName=f.getName();
    if (fName.endsWith(Table.FILENAME_EXTENSION)) {
      int lastIndex=fName.lastIndexOf(Table.FILENAME_EXTENSION);
      String tableName=fName.substring(0,lastIndex);
      tableLookup.put(tableName,new Table(tableName,this.fileDir));
    }
 else     if (fName.endsWith(BPlusTree.FILENAME_EXTENSION)) {
      int lastIndex=fName.lastIndexOf(BPlusTree.FILENAME_EXTENSION);
      String indexName=fName.substring(0,lastIndex);
      indexLookup.put(indexName,new BPlusTree(indexName,this.fileDir));
    }
  }
}

public Database ( String fileDir ) throws DatabaseException { this . fileDir = fileDir ; numTransactions = 0 ; tableLookup = new ConcurrentHashMap < String , Table > ( ) ; indexLookup = new ConcurrentHashMap < String , BPlusTree > ( ) ; File dir = new File ( fileDir ) ; lockMan = new LockManager ( ) ; if ( ! dir . exists ( ) ) { dir . mkdirs ( ) ; } File [ ] files = dir . listFiles ( ) ; for ( File f : files ) { String fName = f . getName ( ) ; if ( fName . endsWith ( Table . FILENAME_EXTENSION ) ) { int lastIndex = fName . lastIndexOf ( Table . FILENAME_EXTENSION ) ; String tableName = fName . substring ( 0 , lastIndex ) ; tableLookup . put ( tableName , new Table ( tableName , this . fileDir ) ) ; } else if ( fName . endsWith ( BPlusTree . FILENAME_EXTENSION ) ) { int lastIndex = fName . lastIndexOf ( BPlusTree . FILENAME_EXTENSION ) ; String indexName = fName . substring ( 0 , lastIndex ) ; indexLookup . put ( indexName , new BPlusTree ( indexName , this . fileDir ) ) ; } } }
creates a new database .
