Esempio n. 1
0
  /**
   * DB切替時、新たに取得したStatementに対して 更新処理を再実行する。
   *
   * @param
   */
  public void reupdateStatement(Statement st) throws SQLException {
    try {
      this.st.close();
    } catch (SQLException se) {
    }
    this.st = st;

    for (int i = 0; i < methodList.size(); i++) {
      CalledMethod calledMethod = methodList.get(i);
      try {
        calledMethod.invoke(st); // 戻り値は無視して良い
      } catch (Exception e) {
        logger.error("reupdate failed", e);
        throw new SQLException(MSG_ERR_REUPDATE);
      }
    }
  }
Esempio n. 2
0
  /**
   * クラスタリング対応のメソッド実行処理。
   *
   * @param methodName
   * @param args
   * @return
   * @throws SQLException
   */
  private Object clusterCall(
      String methodName, Object[] args, Class<?>[] parameterTypes, boolean saveMethod)
      throws SQLException {
    Object result = null;
    CalledMethod calledMethod = new CalledMethod(methodName, args, parameterTypes);

    logger.debug(calledMethod.toString());

    try {
      result = calledMethod.invoke(st);
    } catch (Exception e) {
      logger.warn(MSG_WARN_SWITCH_DB, e);
      // try { st.close(); } catch (SQLException se) {}
      con.notifyError(this); // エラーを通知。ここでstは新しいものになっているはず。
      try {
        // 再度実行。ここでもさらにエラーがでるならSQLExceptionにラップする。
        result = calledMethod.invoke(st);
      } catch (InvocationTargetException e2) {
        // 例外がSQLExceptionならそのままthrow
        Throwable t = e2.getTargetException();
        if (t instanceof SQLException) {
          throw (SQLException) t;
        }
        // それ以外ならwrapしてthrow
        SQLException sqle = new SQLException();
        sqle.initCause(e2.getTargetException());
        throw sqle;
      } catch (Exception e2) {
        SQLException sqle = new SQLException();
        sqle.initCause(e2);
        throw sqle;
      }
    }
    if (saveMethod) {
      methodList.add(calledMethod);
    }

    return result;
  }