Ejemplo n.º 1
0
  /**
   * SQL実行計画のレコードを追加します。<br>
   *
   * @param database データベース名
   * @param sqlPlan 挿入するSQL実行計画
   * @throws SQLException SQL 実行時に例外が発生した場合
   */
  public static void insert(final String database, final SqlPlan sqlPlan) throws SQLException {
    Connection conn = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
      conn = getConnection(database);
      pstmt =
          conn.prepareStatement(
              "insert into "
                  + SQL_PLAN
                  + " (MEASUREMENT_ITEM_NAME, SQL_STATEMENT,"
                  + " EXECUTION_PLAN, GETTING_PLAN_TIME, STACK_TRACE)"
                  + " values (?,?,?,?,?)");
      PreparedStatement delegated = getDelegatingStatement(pstmt);
      // CHECKSTYLE:OFF
      String measurementItemName = sqlPlan.measurementItemName;
      String sqlStatement = sqlPlan.sqlStatement;
      String executionPlan = sqlPlan.executionPlan;
      Timestamp gettingPlanTime = sqlPlan.gettingPlanTime;
      String stackTrace = sqlPlan.stackTrace;

      delegated.setString(1, measurementItemName);
      delegated.setString(2, sqlStatement);
      delegated.setString(3, executionPlan);
      delegated.setTimestamp(4, gettingPlanTime);
      delegated.setString(5, stackTrace);
      // CHECKSTYLE:ON
      delegated.execute();
    } finally {
      SQLUtil.closeResultSet(rs);
      SQLUtil.closeStatement(pstmt);
      SQLUtil.closeConnection(conn);
    }
  }
  /**
   * Get the SummarySignalDefinition sequence id num. <br>
   *
   * @param dataBaseName データベース名
   * @param summarySignalDefinition summarySignal
   * @return SummarySignalDefinitionのID
   * @throws SQLException SQL 実行時に例外が発生した場合
   */
  public int selectSequenceNum(String dataBaseName, SummarySignalDefinition summarySignalDefinition)
      throws SQLException {
    int result = 0;
    String summarySignalName = summarySignalDefinition.getSummarySignalName();
    Connection conn = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
      conn = getConnection(dataBaseName, false);

      String sql =
          "select SUMMARY_SIGNAL_ID from "
              + SUMMARY_SIGNAL_DEFINITION
              + " where SUMMARY_SIGNAL_NAME=?";
      pstmt = conn.prepareStatement(sql);
      pstmt.setString(1, summarySignalName);
      rs = pstmt.executeQuery();
      while (rs.next() == true) {
        int summarySignalId = rs.getInt(1);
        result = summarySignalId;
      }

    } finally {
      SQLUtil.closeResultSet(rs);
      SQLUtil.closeStatement(pstmt);
      SQLUtil.closeConnection(conn);
    }

    return result;
  }
  /**
   * Get the SummarySignalDefinition List according to the selected name.<br>
   *
   * @param dbName データベース名
   * @param summarySignalName SummarySignal名
   * @return SummarySignalDefinitionのリスト
   * @throws SQLException SQL 実行時に例外が発生した場合
   */
  public List<SummarySignalDefinition> selectByName(String dbName, String summarySignalName)
      throws SQLException {
    List<SummarySignalDefinition> result = new ArrayList<SummarySignalDefinition>();
    List<String> summarySignalList = new ArrayList<String>();
    Connection conn = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    String summarySignal;
    try {
      conn = getConnection(dbName, false);
      String sql = "select * from " + SUMMARY_SIGNAL_DEFINITION + " where SUMMARY_SIGNAL_NAME=?";
      pstmt = conn.prepareStatement(sql);
      pstmt.setString(1, summarySignalName);
      rs = pstmt.executeQuery();
      while (rs.next() == true) {
        // CHECKSTYLE:OFF
        SummarySignalDefinition summarySignalInfo = new SummarySignalDefinition();
        summarySignalInfo.summarySignalId = rs.getLong(1);
        summarySignalInfo.summarySignalName = rs.getString(2);
        summarySignal = rs.getString(3);
        String[] temp = null;
        temp = summarySignal.split(",");
        for (int index = 0; index < temp.length; index++) {
          summarySignalList.add(temp[index]);
        }
        summarySignalInfo.signalList = summarySignalList;
        summarySignalInfo.summarySignalType = rs.getInt(4);
        summarySignalInfo.priority = rs.getInt(5);
        // CHECKSTYLE:ON
        result.add(summarySignalInfo);
      }
    } finally {
      SQLUtil.closeResultSet(rs);
      SQLUtil.closeStatement(pstmt);
      SQLUtil.closeConnection(conn);
    }

    return result;
  }
  /**
   * Get the SummarySignalDefinition List by ordering the priority.<br>
   *
   * @param dataBaseName データベース名
   * @return SummarySignalDefinitionのリスト
   * @throws SQLException SQL 実行時に例外が発生した場合
   */
  public List<SummarySignalDefinition> selectAllByPriority(String dataBaseName)
      throws SQLException {
    List<SummarySignalDefinition> result = new ArrayList<SummarySignalDefinition>();

    Connection conn = null;
    Statement stmt = null;
    ResultSet rs = null;
    String summarySignal;
    try {
      conn = getConnection(dataBaseName, false);
      stmt = conn.createStatement();
      String sql = "select * from " + SUMMARY_SIGNAL_DEFINITION + " ORDER BY PRIORITY_NO DESC";
      rs = stmt.executeQuery(sql);
      while (rs.next() == true) {
        List<String> summarySignalList = new ArrayList<String>();
        // CHECKSTYLE:OFF
        SummarySignalDefinition summarySignalInfo = new SummarySignalDefinition();
        summarySignalInfo.summarySignalId = rs.getLong(1);
        summarySignalInfo.summarySignalName = rs.getString(2);
        summarySignal = rs.getString(3);
        String[] temp = null;
        temp = summarySignal.split(",");
        for (int index = 0; index < temp.length; index++) {
          summarySignalList.add(temp[index]);
        }
        summarySignalInfo.signalList = summarySignalList;
        summarySignalInfo.summarySignalType = rs.getInt(4);
        summarySignalInfo.priority = rs.getInt(5);
        result.add(summarySignalInfo);
      }
    } finally {
      SQLUtil.closeResultSet(rs);
      SQLUtil.closeStatement(stmt);
      SQLUtil.closeConnection(conn);
    }

    return result;
  }