void postClose(boolean keep) throws HsqlException {

    SimpleLog appLog = database.logger.appLog;

    if (cacheReadonly) {
      return;
    }

    try {
      appLog.sendLine(SimpleLog.LOG_NORMAL, "DataFileCache.postClose(" + keep + ") : start");

      if (keep) {
        database
            .getProperties()
            .setProperty(
                HsqlDatabaseProperties.hsqldb_cache_version,
                HsqlDatabaseProperties.VERSION_STRING_1_7_0);
        database.getProperties().save();
        appLog.sendLine(SimpleLog.LOG_NORMAL, "DataFileCache.postClose() : save props");

        if (fileModified) {
          backup();
        }
      } else {
        fa.removeElement(backupFileName);
        appLog.sendLine(SimpleLog.LOG_NORMAL, "DataFileCache.postClose() : delete backup");
        deleteOrResetFreePos(database, fileName);
        appLog.sendLine(SimpleLog.LOG_NORMAL, "DataFileCache.postClose() : delete file");
      }
    } catch (IOException e) {
      throw new HsqlException(e, Trace.getMessage(Trace.GENERAL_IO_ERROR), Trace.GENERAL_IO_ERROR);
    }
  }
  void postClose(boolean keep) throws HsqlException {

    if (cacheReadonly) {
      return;
    }

    try {
      if (keep) {
        database
            .getProperties()
            .setProperty("hsqldb.cache_version", HsqlDatabaseProperties.VERSION_STRING_1_7_0);
        database.getProperties().save();

        if (fileModified) {
          backup();
        }
      } else {
        fa.removeElement(backupFileName);
        deleteOrResetFreePos(database, fileName);
      }
    } catch (IOException e) {
      throw new HsqlException(e, Trace.getMessage(Trace.GENERAL_IO_ERROR), Trace.GENERAL_IO_ERROR);
    }
  }
  /** Writes out all the rows to a new file without fragmentation. */
  public void defrag() throws HsqlException {

    if (cacheReadonly) {
      return;
    }

    if (fileFreePosition == INITIAL_FREE_POS) {
      return;
    }

    try {
      boolean wasNio = dataFile.wasNio();
      DataFileDefrag dfd = new DataFileDefrag(database, this, fileName);

      dfd.process();
      close(false);
      Trace.printSystemOut("closed old cache");

      // first attemp to delete
      fa.removeElement(fileName);

      if (wasNio) {
        System.gc();

        if (fa.isStreamElement(fileName)) {
          fa.removeElement(fileName);

          if (fa.isStreamElement(fileName)) {
            fa.renameElement(fileName, fileName + ".old");

            File oldfile = new File(fileName + ".old");

            FileUtil.deleteOnExit(oldfile);
          }
        }
      }

      // [email protected] - change to file access api
      fa.renameElement(fileName + ".new", fileName);
      backup();
      database
          .getProperties()
          .setProperty("hsqldb.cache_version", HsqlDatabaseProperties.VERSION_STRING_1_7_0);
      database.getProperties().save();
      initParams();

      cache = new Cache(this);

      open(cacheReadonly);
      dfd.updateTableIndexRoots();
      Trace.printSystemOut("opened cache");
    } catch (Exception e) {
      database.logger.appLog.logContext(e);

      throw new HsqlException(e, Trace.getMessage(Trace.GENERAL_IO_ERROR), Trace.GENERAL_IO_ERROR);
      /*
      Trace.error(Trace.FILE_IO_ERROR, Trace.DataFileCache_defrag, new Object[] {
          e, fileName
      });
      */
    }
  }