Ejemplo n.º 1
0
  /** Runs check on the prior schema version, and then upgrades. */
  private void upgradeFrom(UpdateUI ui, CurrentSchemaVersion curr, ReviewDb db)
      throws OrmException, SQLException {
    List<SchemaVersion> pending = pending(curr.versionNbr);
    updateSchema(pending, ui, db);
    migrateData(pending, ui, curr, db);

    JdbcSchema s = (JdbcSchema) db;
    final List<String> pruneList = new ArrayList<>();
    s.pruneSchema(
        new StatementExecutor() {
          @Override
          public void execute(String sql) {
            pruneList.add(sql);
          }

          @Override
          public void close() {
            // Do nothing.
          }
        });

    try (JdbcExecutor e = new JdbcExecutor(s)) {
      if (!pruneList.isEmpty()) {
        ui.pruneSchema(e, pruneList);
      }
    }
  }
Ejemplo n.º 2
0
 private void migrateData(
     List<SchemaVersion> pending, UpdateUI ui, CurrentSchemaVersion curr, ReviewDb db)
     throws OrmException, SQLException {
   for (SchemaVersion v : pending) {
     ui.message(String.format("Migrating data to schema %d ...", v.getVersionNbr()));
     v.migrateData(db, ui);
     v.finish(curr, db);
   }
 }
Ejemplo n.º 3
0
  /** Runs check on the prior schema version, and then upgrades. */
  protected void upgradeFrom(
      UpdateUI ui, CurrentSchemaVersion curr, ReviewDb db, boolean toTargetVersion)
      throws OrmException, SQLException {
    final JdbcSchema s = (JdbcSchema) db;

    if (curr.versionNbr > versionNbr) {
      throw new OrmException(
          "Cannot downgrade database schema from version "
              + curr.versionNbr
              + " to "
              + versionNbr
              + ".");
    }

    prior.get().check(ui, curr, db, false);

    ui.message(
        "Upgrading database schema from version " + curr.versionNbr + " to " + versionNbr + " ...");

    preUpdateSchema(db);
    final JdbcExecutor e = new JdbcExecutor(s);
    try {
      s.updateSchema(e);
      migrateData(db, ui);

      if (toTargetVersion) {
        final List<String> pruneList = new ArrayList<String>();
        s.pruneSchema(
            new StatementExecutor() {
              public void execute(String sql) {
                pruneList.add(sql);
              }
            });

        if (!pruneList.isEmpty()) {
          ui.pruneSchema(e, pruneList);
        }
      }
    } finally {
      e.close();
    }
    finish(curr, db);
  }