Esempio n. 1
0
 public void forciblyReleaseConnection() {
   try {
     Connection con = dataSource.getConnection(dataSource.numTypecheckReconnectAttempts());
     if (con != null) {
       dataSource.actuallyReleaseConnection(con);
     }
   } catch (StreamBaseException e) {
     Msg.debug(e);
   }
 }
Esempio n. 2
0
  /**
   * @param dataSource
   * @param sql array of sql commands to execute
   * @return array of booleans where each is true iff sql execution for corresponding statement
   *     succeeded
   * @throws StreamBaseException
   */
  public List<Result> executeSql(DataSourceInfo dataSource, boolean ignoreErrors, String[] sql)
      throws StreamBaseException {
    Connection con = null;
    Statement statement = null;
    List<Result> result = new ArrayList<SqlScript.Result>();

    try {
      con = dataSource.getConnection(dataSource.numTypecheckReconnectAttempts());

      try {
        statement = con.createStatement();
      } catch (SQLException e) {
        throw new StreamBaseException("Unable to create statement", e);
      }

      for (int i = 0; i < sql.length; ++i) {
        boolean success = false;
        Error e = null;
        String s = sql[i].trim();

        try {
          success = execute(statement, s);
          logger.info("SqlScript executed {}", s);
        } catch (Throwable ex) {
          e = new Error(ex);
          logger.error(MessageFormat.format("SqlScript error executing {0}", s), ex);
        }
        result.add(new Result(success, e));

        if (e != null && !ignoreErrors) {
          throw e;
        }
      }
    } finally {
      if (statement != null) {
        try {
          statement.close();
        } catch (SQLException e) {
        }
        statement = null;
      }
      if (con != null) {
        dataSource.releaseConnection(con);
        con = null;
      }
    }
    return result;
  }