Exemplo n.º 1
0
  /**
   * Shuts down the logging process using the specified mode.
   *
   * <p>
   *
   * @param closemode The mode in which to shut down the logging process
   *     <OL>
   *       <LI>closemode -1 performs SHUTDOWN IMMEDIATELY, equivalent to a poweroff or crash.
   *       <LI>closemode 0 performs a normal SHUTDOWN that checkpoints the database normally.
   *       <LI>closemode 1 performs a shutdown compact that scripts out the contents of any CACHED
   *           tables to the log then deletes the existing *.data file that contains the data for
   *           all CACHED table before the normal checkpoint process which in turn creates a new,
   *           compact *.data file.
   *     </OL>
   *
   * @return true if closed with no problems or false if a problem was encountered.
   */
  boolean closeLog(int closemode) {

    if (lLog == null) {
      return true;
    }

    try {
      lLog.stop();

      switch (closemode) {
        case Database.CLOSEMODE_IMMEDIATELY:
          lLog.shutdown();
          break;

        case Database.CLOSEMODE_NORMAL:
          lLog.close(false, true);
          break;

        case Database.CLOSEMODE_COMPACT:
        case Database.CLOSEMODE_SCRIPT:
          lLog.close(true, true);
          break;
      }
    } catch (Throwable e) {
      lLog = null;

      return false;
    }

    lLog = null;

    return true;
  }
Exemplo n.º 2
0
  /**
   * Method declaration
   *
   * @throws SQLException
   */
  void checkpoint(boolean defrag) throws SQLException {

    if (defrag) {
      ArrayList rootsArray = cCache.defrag();

      for (int i = 0; i < rootsArray.size(); i++) {
        int[] roots = (int[]) rootsArray.get(i);

        if (roots != null) {
          Trace.printSystemOut(org.hsqldb.lib.StringUtil.getList(roots, " ", ""));
        }
      }

      DataFileDefrag2.updateTableIndexRoots(dDatabase.getTables(), rootsArray);
    }

    close(false);
    pProperties.setProperty("modified", "yes");
    pProperties.save();

    if (cCache != null) {
      cCache.open(false);
    }

    reopenAllTextCaches();
    openScript();
  }
Exemplo n.º 3
0
  /**
   * When opening a database, the hsqldb.compatible_version property is used to determine if this
   * version of the engine is equal to or greater than the earliest version of the engine capable of
   * opening that database.
   *
   * <p>
   *
   * @return
   * @throws SQLException
   */
  boolean open() throws SQLException {

    if (Trace.TRACE) {
      Trace.trace();
    }

    if (!pProperties.checkFileExists()) {
      create();
      open();

      // this is a new database
      return true;
    }

    // todo: some parts are not necessary for ready-only access
    pProperties.load();

    sFileScript = sName + ".script";
    sFileCache = sName + ".data";
    sFileBackup = sName + ".backup";
    scriptChecker = new File(sFileScript);

    // tony_lai@users 20020820
    // Allows the user to modify log size from the properties file.
    iLogSize = pProperties.getIntegerProperty("hsqldb.log_size", iLogSize);

    String version = pProperties.getProperty("hsqldb.compatible_version");

    // fredt@users 20020428 - patch 1.7.0 by fredt
    int check = version.substring(0, 5).compareTo(jdbcDriver.VERSION);

    Trace.check(check <= 0, Trace.WRONG_DATABASE_FILE_VERSION);

    // save the current version
    pProperties.setProperty("hsqldb.version", jdbcDriver.VERSION);

    if (pProperties.isPropertyTrue("readonly")) {
      bReadOnly = true;

      dDatabase.setReadOnly();

      if (cCache != null) {
        cCache.open(true);
      }

      reopenAllTextCaches();
      runScript();

      return false;
    }

    boolean needbackup = false;
    String state = pProperties.getProperty("modified");

    if (state.equals("yes-new-files")) {
      renameNewToCurrent(sFileScript);
      renameNewToCurrent(sFileBackup);
    } else if (state.equals("yes")) {
      if (isAlreadyOpen()) {
        throw Trace.error(Trace.DATABASE_ALREADY_IN_USE);
      }

      // recovering after a crash (or forgot to close correctly)
      restoreBackup();

      needbackup = true;
    }

    pProperties.setProperty("modified", "yes");
    pProperties.save();

    if (cCache != null) {
      cCache.open(false);
    }

    reopenAllTextCaches();
    runScript();

    if (needbackup) {
      close(false);
      pProperties.setProperty("modified", "yes");
      pProperties.save();

      if (cCache != null) {
        cCache.open(false);
      }

      reopenAllTextCaches();
    }

    openScript();

    // this is an existing database
    return false;
  }