Search in sources :

Example 1 with IntStringStringValue

use of com.navercorp.pinpoint.common.util.IntStringStringValue in project pinpoint by naver.

the class SpanServiceImpl method transitionSqlId.

private void transitionSqlId(final List<SpanAlign> spans) {
    this.transitionAnnotation(spans, new AnnotationReplacementCallback() {

        @Override
        public void replacement(SpanAlign spanAlign, List<AnnotationBo> annotationBoList) {
            AnnotationBo sqlIdAnnotation = findAnnotation(annotationBoList, AnnotationKey.SQL_ID.getCode());
            if (sqlIdAnnotation == null) {
                return;
            }
            if (metaDataFilter != null && metaDataFilter.filter(spanAlign, MetaData.SQL)) {
                AnnotationBo annotationBo = metaDataFilter.createAnnotationBo(spanAlign, MetaData.SQL);
                annotationBoList.add(annotationBo);
                return;
            }
            // value of sqlId's annotation contains multiple values.
            final IntStringStringValue sqlValue = (IntStringStringValue) sqlIdAnnotation.getValue();
            final int sqlId = sqlValue.getIntValue();
            final String sqlParam = sqlValue.getStringValue1();
            final List<SqlMetaDataBo> sqlMetaDataList = sqlMetaDataDao.getSqlMetaData(spanAlign.getAgentId(), spanAlign.getAgentStartTime(), sqlId);
            final int size = sqlMetaDataList.size();
            if (size == 0) {
                AnnotationBo api = new AnnotationBo();
                api.setKey(AnnotationKey.SQL.getCode());
                api.setValue("SQL-ID not found sqlId:" + sqlId);
                annotationBoList.add(api);
            } else if (size == 1) {
                final SqlMetaDataBo sqlMetaDataBo = sqlMetaDataList.get(0);
                if (StringUtils.isEmpty(sqlParam)) {
                    AnnotationBo sqlMeta = new AnnotationBo();
                    sqlMeta.setKey(AnnotationKey.SQL_METADATA.getCode());
                    sqlMeta.setValue(sqlMetaDataBo.getSql());
                    annotationBoList.add(sqlMeta);
                    //                        AnnotationBo checkFail = checkIdentifier(spanAlign, sqlMetaDataBo);
                    //                        if (checkFail != null) {
                    //                            // fail
                    //                            annotationBoList.add(checkFail);
                    //                            return;
                    //                        }
                    AnnotationBo sql = new AnnotationBo();
                    sql.setKey(AnnotationKey.SQL.getCode());
                    sql.setValue(sqlMetaDataBo.getSql().trim());
                    annotationBoList.add(sql);
                } else {
                    logger.debug("sqlMetaDataBo:{}", sqlMetaDataBo);
                    final String outputParams = sqlParam;
                    List<String> parsedOutputParams = outputParameterParser.parseOutputParameter(outputParams);
                    logger.debug("outputPrams:{}, parsedOutputPrams:{}", outputParams, parsedOutputParams);
                    String originalSql = sqlParser.combineOutputParams(sqlMetaDataBo.getSql(), parsedOutputParams);
                    logger.debug("outputPrams{}, originalSql:{}", outputParams, originalSql);
                    AnnotationBo sqlMeta = new AnnotationBo();
                    sqlMeta.setKey(AnnotationKey.SQL_METADATA.getCode());
                    sqlMeta.setValue(sqlMetaDataBo.getSql());
                    annotationBoList.add(sqlMeta);
                    AnnotationBo sql = new AnnotationBo();
                    sql.setKey(AnnotationKey.SQL.getCode());
                    sql.setValue(originalSql.trim());
                    annotationBoList.add(sql);
                }
            } else {
                // TODO need improvement
                AnnotationBo api = new AnnotationBo();
                api.setKey(AnnotationKey.SQL.getCode());
                api.setValue(collisionSqlIdCodeMessage(sqlId, sqlMetaDataList));
                annotationBoList.add(api);
            }
            // add if bindValue exists
            final String bindValue = sqlValue.getStringValue2();
            if (StringUtils.isNotEmpty(bindValue)) {
                AnnotationBo bindValueAnnotation = new AnnotationBo();
                bindValueAnnotation.setKey(AnnotationKey.SQL_BINDVALUE.getCode());
                bindValueAnnotation.setValue(bindValue);
                annotationBoList.add(bindValueAnnotation);
            }
        }
    });
}
Also used : SpanAlign(com.navercorp.pinpoint.web.calltree.span.SpanAlign) AnnotationBo(com.navercorp.pinpoint.common.server.bo.AnnotationBo) IntStringStringValue(com.navercorp.pinpoint.common.util.IntStringStringValue) SqlMetaDataBo(com.navercorp.pinpoint.common.server.bo.SqlMetaDataBo) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

AnnotationBo (com.navercorp.pinpoint.common.server.bo.AnnotationBo)1 SqlMetaDataBo (com.navercorp.pinpoint.common.server.bo.SqlMetaDataBo)1 IntStringStringValue (com.navercorp.pinpoint.common.util.IntStringStringValue)1 SpanAlign (com.navercorp.pinpoint.web.calltree.span.SpanAlign)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1