public long getMetricRecordID(String recordTypeContext,
                                String recordTypeName, String nodeName, String sourceIP,
                                String clusterName, String serviceName, String tagPairs, long recordTimestamp) {
    CallableStatement cstmt = null;
    long result;
    logger.trace(
      "Params: recordTypeContext = " + recordTypeContext
        + ", recordTypeName = " + recordTypeName
        + ", nodeName = " + nodeName
        + ", sourceIP = " + sourceIP
        + ", tagPairs = " + tagPairs
        + ", clusterName = " + clusterName
        + ", serviceName = " + serviceName
        + ", recordTimestamp = " + recordTimestamp
    );
    if (recordTypeContext == null || recordTypeName == null || nodeName == null
      || sourceIP == null || tagPairs == null)
      return -1;

    int colid = 1;
    try {
      if (ensureConnection()) {
        String procedureCall =
          String.format("{call %s(?, ?, ?, ?, ?, ?, ?, ?, ?)}",
            getGetMetricsProcedureName());
        cstmt = conn.prepareCall(procedureCall);
        cstmt.setNString(colid++, recordTypeContext);
        cstmt.setNString(colid++, recordTypeName);
        cstmt.setNString(colid++, nodeName);
        cstmt.setNString(colid++, sourceIP);
        cstmt.setNString(colid++, clusterName);
        cstmt.setNString(colid++, serviceName);
        cstmt.setNString(colid++, tagPairs);
        cstmt.setLong(colid++, recordTimestamp);
        cstmt.registerOutParameter(colid, java.sql.Types.BIGINT);
        cstmt.execute();

        result = cstmt.getLong(colid);
        if (cstmt.wasNull())
          return -1;
        return result;
      }
    } catch (Exception e) {
      if (DEBUG)
        logger.info("Error during getMetricRecordID call sproc: "
          + e.toString());
      flush();
    } finally {
      if (cstmt != null) {
        try {
          cstmt.close();
        } catch (SQLException se) {
          if (DEBUG)
            logger.info("Error during getMetricRecordID close cstmt: "
              + se.toString());
        }
        /*
         * We don't close the connection here because we are likely to be
         * writing
         * metric values next and it is more efficient to share the connection.
         */
      }
    }
    return -1;
  }
This class stores published metrics to the SQL Server database.
contrib/ambari-scom/metrics-sink/src/main/java/org/apache/hadoop/metrics2/sink/SqlSink.java