示例#1
0
  public static synchronized boolean applyScript(
      boolean runScript, String moduleKey, VirtualFile evolutionsDirectory) {
    try {
      Connection connection = EvolutionQuery.getNewConnection(Evolutions.autoCommit());
      int applying = -1;
      try {
        for (Evolution evolution : getEvolutionScript(moduleKey, evolutionsDirectory)) {
          applying = evolution.revision;
          EvolutionQuery.apply(connection, runScript, evolution, moduleKey);
        }
        return true;
      } catch (Exception e) {
        String message = e.getMessage();
        if (e instanceof SQLException) {
          SQLException ex = (SQLException) e;
          message += " [ERROR:" + ex.getErrorCode() + ", SQLSTATE:" + ex.getSQLState() + "]";
        }

        EvolutionQuery.setProblem(connection, applying, moduleKey, message);
        EvolutionQuery.closeConnection(connection);
        Logger.error(e, "Can't apply evolution");
        return false;
      }
    } catch (Exception e) {
      throw new UnexpectedException(e);
    }
  }