Esempio n. 1
0
  public static synchronized void checkEvolutionsState() {

    for (Entry<String, VirtualFile> moduleRoot : modulesWithEvolutions.entrySet()) {

      if (EvolutionQuery.getDatasource() != null) {
        List<Evolution> evolutionScript =
            getEvolutionScript(moduleRoot.getKey(), moduleRoot.getValue());
        Connection connection = null;
        try {
          connection = EvolutionQuery.getNewConnection();
          ResultSet rs = EvolutionQuery.getEvolutionsToApply(connection, moduleRoot.getKey());
          if (rs.next()) {
            int revision = rs.getInt("id");
            String state = rs.getString("state");
            String hash = rs.getString("hash").substring(0, 7);
            String script = "";
            if (state.equals("applying_up")) {
              script = rs.getString("apply_script");
            } else {
              script = rs.getString("revert_script");
            }
            script =
                "# --- Rev:"
                    + revision
                    + ","
                    + (state.equals("applying_up") ? "Ups" : "Downs")
                    + " - "
                    + hash
                    + "\n\n"
                    + script;
            String error = rs.getString("last_problem");
            throw new InconsistentDatabase(script, error, revision, moduleRoot.getKey());
          }
        } catch (SQLException e) {
          throw new UnexpectedException(e);
        } finally {
          EvolutionQuery.closeConnection(connection);
        }

        if (!evolutionScript.isEmpty()) {
          throw new InvalidDatabaseRevision(toHumanReadableScript(evolutionScript));
        }
      }
    }
  }