package com.navercorp.pinpoint.web.dao.hbase;

import com.navercorp.pinpoint.common.server.bo.SpanBo;
import com.navercorp.pinpoint.common.util.TransactionId;
import com.navercorp.pinpoint.web.dao.TraceDao;
import org.apache.commons.collections.CollectionUtils;

import java.util.List;

/**
 * @author Woonduk Kang(emeroad)
 */
public class HbaseTraceCompatibilityDao implements TraceDao {

    private final TraceDao master;
    private final TraceDao slave;

    public HbaseTraceCompatibilityDao(TraceDao master, TraceDao slave) {
        if (master == null) {
            throw new NullPointerException("master must not be null");
        }
        if (slave == null) {
            throw new NullPointerException("slave must not be null");
        }

        this.master = master;
        this.slave = slave;
    }

    @Override
    public List<SpanBo> selectSpan(TransactionId transactionId) {
        List<SpanBo> spanBos = this.master.selectSpan(transactionId);
        if (CollectionUtils.isNotEmpty(spanBos)) {
            return spanBos;
        }

        return slave.selectSpan(transactionId);
    }


    @Override
    public List<List<SpanBo>> selectSpans(List<TransactionId> transactionIdList) {
        List<List<SpanBo>> spanBos = this.master.selectSpans(transactionIdList);
        if (CollectionUtils.isNotEmpty(spanBos)) {
            return spanBos;
        }

        return slave.selectSpans(transactionIdList);
    }

    @Override
    public List<List<SpanBo>> selectAllSpans(List<TransactionId> transactionIdList) {
        List<List<SpanBo>> spanBos = this.master.selectAllSpans(transactionIdList);
        if (CollectionUtils.isNotEmpty(spanBos)) {
            return spanBos;
        }

        return slave.selectAllSpans(transactionIdList);
    }

}

@@ -1346,39 +1346,187 @@
             
-return spanBos;
+for (List%3CSpanBo%3E spanBo : spanBos) %7B%0A                if (CollectionUtils.isNotEmpty(spanBo)) %7B%0A                    return spanBos;%0A                %7D%0A            %7D
 %0A        %7D%0A%0A
@@ -1828,39 +1828,187 @@
             
-return spanBos;
+for (List%3CSpanBo%3E spanBo : spanBos) %7B%0A                if (CollectionUtils.isNotEmpty(spanBo)) %7B%0A                    return spanBos;%0A                %7D%0A            %7D
 %0A        %7D%0A%0A

Fix V1 compatibility issue