Exemplo n.º 1
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.º 2
0
  /**
   * Method declaration
   *
   * @param db
   * @param file
   * @param full
   * @param session
   * @throws SQLException
   */
  static void scriptToFile(Database db, String file, boolean full, Session session)
      throws SQLException {

    if ((new File(file)).exists()) {

      // there must be no such file; overwriting not allowed for security
      throw Trace.error(Trace.FILE_IO_ERROR, file);
    }

    try {
      long time = 0;

      if (Trace.TRACE) {
        time = System.currentTimeMillis();
      }

      // only ddl commands; needs not so much memory
      Result r;

      if (full) {

        // no drop, no insert, and no positions for cached tables
        r = db.getScript(false, false, false, session);
      } else {

        // no drop, no insert, but positions for cached tables
        r = db.getScript(false, false, true, session);
      }

      Record n = r.rRoot;
      FileWriter w = new FileWriter(file);

      while (n != null) {
        writeLine(w, (String) n.data[0]);

        n = n.next;
      }

      // inserts are done separetely to save memory
      HsqlArrayList tables = db.getTables();

      for (int i = 0; i < tables.size(); i++) {
        Table t = (Table) tables.get(i);

        // cached tables have the index roots set in the ddl script
        if ((full || !t.isCached())
            && !t.isTemp()
            && !t.isView()
            && (!t.isText() || !t.isDataReadOnly())) {
          Index primary = t.getPrimaryIndex();
          Node x = primary.first();

          while (x != null) {
            writeLine(w, t.getInsertStatement(x.getData()));

            x = primary.next(x);
          }
        }

        // fredt@users 20020221 - patch 513005 by sqlbob@users (RMP)
        if (t.isDataReadOnly() && !t.isTemp() && !t.isText()) {
          HsqlStringBuffer a = new HsqlStringBuffer("SET TABLE ");

          a.append(t.getName().statementName);
          a.append(" READONLY TRUE");
          writeLine(w, a.toString());
        }
      }

      w.close();

      if (Trace.TRACE) {
        Trace.trace(time - System.currentTimeMillis());
      }
    } catch (IOException e) {
      throw Trace.error(Trace.FILE_IO_ERROR, file + " " + e);
    }
  }