/**
   * Closes this Database using the specified mode.
   *
   * <p>
   *
   * <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>
   */
  public void close(int closemode) {

    HsqlException he = null;

    setState(DATABASE_CLOSING);
    sessionManager.closeAllSessions();
    sessionManager.clearAll();

    if (filesReadOnly) {
      closemode = CLOSEMODE_IMMEDIATELY;
    }

    /**
     * @todo fredt - impact of possible error conditions in closing the log should be investigated
     *     for the CLOSEMODE_COMPACT mode
     */
    logger.closePersistence(closemode);
    lobManager.close();

    try {
      if (closemode == CLOSEMODE_COMPACT) {
        clearStructures();
        reopen();
        setState(DATABASE_CLOSING);
        logger.closePersistence(CLOSEMODE_NORMAL);
      }
    } catch (Throwable t) {
      if (t instanceof HsqlException) {
        he = (HsqlException) t;
      } else {
        he = Error.error(ErrorCode.GENERAL_ERROR, t.toString());
      }
    }

    logger.releaseLock();
    setState(DATABASE_SHUTDOWN);
    clearStructures();

    // fredt - this could change to avoid removing a db from the
    // DatabaseManager repository if there are pending getDatabase()
    // calls
    DatabaseManager.removeDatabase(this);

    if (he != null) {
      throw he;
    }
  }
  /**
   * Closes this Database using the specified mode.
   *
   * <p>
   *
   * <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>
   */
  void close(int closemode) throws HsqlException {

    HsqlException he = null;

    setState(DATABASE_CLOSING);
    sessionManager.closeAllSessions();
    sessionManager.clearAll();

    // fredt - impact of possible error conditions in closing the log
    // should be investigated for the CLOSEMODE_COMPACT mode
    logger.closeLog(closemode);

    try {
      if (closemode == CLOSEMODE_COMPACT && !filesReadOnly) {
        clearStructures();
        reopen();
        setState(DATABASE_CLOSING);
        logger.closeLog(CLOSEMODE_NORMAL);
      }
    } catch (Throwable t) {
      if (t instanceof HsqlException) {
        he = (HsqlException) t;
      } else {
        he = Trace.error(Trace.GENERAL_ERROR, t.toString());
      }
    }

    classLoader = null;

    logger.releaseLock();
    setState(DATABASE_SHUTDOWN);
    clearStructures();

    // fredt - this could change to avoid removing a db from the
    // DatabaseManager repository if there are pending getDatabase()
    // calls
    DatabaseManager.removeDatabase(this);

    if (he != null) {
      throw he;
    }
  }
Esempio n. 3
0
  /**
   * Closes this Database using the specified mode.
   *
   * <p>
   *
   * <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>
   */
  public void close(int closemode) {

    HsqlException he = null;

    // multiple simultaneous close
    synchronized (this) {
      if (getState() != DATABASE_ONLINE) {
        return;
      }

      setState(DATABASE_CLOSING);
    }

    sessionManager.closeAllSessions();

    if (filesReadOnly) {
      closemode = CLOSEMODE_IMMEDIATELY;
    }

    /** impact of possible error conditions in closing the log for the CLOSEMODE_COMPACT mode */
    boolean result = logger.close(closemode);

    lobManager.close();
    sessionManager.close();

    try {
      if (result && closemode == CLOSEMODE_COMPACT) {
        clearStructures();
        reopen();
        setState(DATABASE_CLOSING);
        sessionManager.closeAllSessions();
        logger.close(CLOSEMODE_NORMAL);
        lobManager.close();
        sessionManager.close();
      }
    } catch (Throwable t) {
      if (t instanceof HsqlException) {
        he = (HsqlException) t;
      } else {
        he = Error.error(ErrorCode.GENERAL_ERROR, t);
      }
    }

    lobManager = null;

    logger.releaseLock();
    setState(DATABASE_SHUTDOWN);
    clearStructures();

    // fredt - this could change to avoid removing a db from the
    // DatabaseManager repository if there are pending getDatabase()
    // calls
    DatabaseManager.removeDatabase(this);

    // todo - when hsqldb.sql. framework logging is supported, add another call
    FrameworkLogger.clearLoggers("hsqldb.db." + getUniqueName());

    if (he != null) {
      throw he;
    }
  }