package com.jay.monitor.data.client.filter;

import com.alibaba.druid.filter.FilterAdapter;
import com.alibaba.druid.filter.FilterChain;
import com.alibaba.druid.proxy.jdbc.ResultSetProxy;
import com.alibaba.druid.stat.JdbcSqlStat;
import com.jay.monitor.data.client.MonitorDataClient;
import com.jay.monitor.data.client.config.props.MonitorProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.sql.SQLException;

/**
 * Cat监控相关SQL执行情况
 *
 * @author ： liukx
 * @time ： 2020/8/24 - 15:39
 */
@Component
public class DruidMonitorFilter extends FilterAdapter {

    @Autowired
    private MonitorDataClient client;

    private MonitorProperties monitorProperties;

    @Override
    public void resultSet_beforeFirst(FilterChain chain, ResultSetProxy resultSet) throws SQLException {
        super.resultSet_beforeFirst(chain, resultSet);
    }

    @Override
    public boolean resultSet_isClosed(FilterChain chain, ResultSetProxy resultSet) throws SQLException {
        return super.resultSet_isClosed(chain, resultSet);
    }

    @Override
    public void resultSet_close(FilterChain chain, ResultSetProxy resultSet) throws SQLException {

        JdbcSqlStat sqlStat = resultSet.getSqlStat();
        String sqlContent = "";

//        if (resultSet.getStatement() instanceof PreparedStatement) {
//            Statement statement = resultSet.getStatement();
//            sqlContent = statement.asSql();
//        }

        String sql = sqlStat.getSql();

        chain.resultSet_close(resultSet);
    }
}
