Ejemplo n.º 1
0
  protected void upgradeDatabaseToLatest(DatabaseAccess.Transaction dat, Log l)
      throws SQLException, IllegalArgumentException {

    /* add all database updates here
     * first get the database version by reading the navconfig table
     */
    String currversion = OmVersion.getVersion();
    l.logDebug("DatabaseUpgrade " + currversion);

    NavVersion DBversion = new NavVersion("");

    /* read the navconfig table into a namepair list */
    ResultSet rs = queryNavConfig(dat);

    NameValuePairs navconfigDB = new NameValuePairs();
    while (rs.next()) {
      navconfigDB.add(rs.getString(1), rs.getString(2));
    }

    /* now find the version */
    String Names[] = navconfigDB.getNames();
    String Values[] = navconfigDB.getValues();
    /* read the current version from the database */
    for (int i = 0; i < Names.length; i++) {
      if (Names[i].compareToIgnoreCase("dbversion") == 0) {
        DBversion.setVersion(Values[i]);
      }
    }
    /* if the current database version is less than the navigator version, check for updates */
    if (DBversion.isLessThanStr(currversion)) {
      /* make sure these are listed in version order, because the function updates the DB version as we go */
      l.logDebug(
          "DatabaseUpgrade",
          "Applying database upgrades, version before update " + DBversion.getVersion());

      updateDatabase(
          "1.10.1",
          DBversion,
          "ALTER TABLE " + getPrefix() + "params ALTER COLUMN paramvalue NVARCHAR(4000)",
          l,
          dat);

      /* finally having applied all the updates set the DB version to the current */
      l.logDebug("DatabaseUpgrade", "Update DB version to current " + currversion);
      dat.update(
          "UPDATE "
              + getPrefix()
              + "navconfig SET value = \'"
              + currversion
              + "\' where name=\'dbversion\'");

      applyUpdateForEmailNotification(dat, l, DBversion);

    } else {
      l.logDebug(
          "DatabaseUpgrade",
          "Database up to date at version " + DBversion.getVersion() + " no updates attempted.");
    }
  }
Ejemplo n.º 2
0
  /**
   * checks the version stored in the database against a pre-defined version and performs the
   * appropriate database upgrade
   *
   * @param version the version that the DB versions is compared against, hard coded by developer in
   *     call
   * @param dbv the database version read from the database
   * @param update the database update to perform
   * @param l log
   * @param dat database connection
   * @throws SQLException
   * @throws IllegalArgumentException
   */
  public void updateDatabase(
      String version, NavVersion dbv, String update, Log l, DatabaseAccess.Transaction dat)
      throws SQLException, IllegalArgumentException {
    /* now get the version in the navigator.xml file
    /* now apply the updates one at a time , first we apply the historic one */
    try {
      if (dbv.isLessThanStr(version)) {
        l.logDebug("DatabaseUpgrade", "Database version less than " + version);
        try {
          /* perform the update */
          dat.update(update);
          /* if that worked, update the database version */
          dat.update(
              "UPDATE "
                  + getPrefix()
                  + "navconfig SET value = \'"
                  + version
                  + "\' where name=\'dbversion\'");
        } catch (SQLException e) {
          l.logError(
              "DatabaseUpgrade",
              e.getMessage() + "Unable to perform database upgrade for DB less than " + version);
          throw new SQLException(e);
        }
      } else {
        l.logDebug(
            "DatabaseUpgrade", "UpgradeDatabaseToLatest no upgrade necessary for " + version);
      }

    } catch (IllegalArgumentException e) {
      l.logError(
          "DatabaseUpgrade",
          e.getMessage() + "Invalid versions in attempt to compare to database version " + version);
      throw new IllegalArgumentException(e);
    }
  }