package com.qiaoba.common.database.interceptors;

import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor;
import com.qiaoba.common.base.context.BaseContext;
import com.qiaoba.common.database.handlers.schema.SchemaHandlerFactory;
import org.apache.ibatis.executor.statement.StatementHandler;
import org.springframework.beans.factory.annotation.Value;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Objects;

/**
 * SchemaInterceptor
 *
 * @author ailanyin
 * @version 1.0
 * @since 2023-04-25 22:48:43
 */
public class SchemaInterceptor implements InnerInterceptor {



    @Override
    public void beforePrepare(StatementHandler sh, Connection conn, Integer transactionTimeout) {

        if (Objects.nonNull(BaseContext.isSchemaMode()) && BaseContext.isSchemaMode()) {
            SchemaHandlerFactory.getHandler(BaseContext.getDatabaseType()).setSchema(conn);
        }
        InnerInterceptor.super.beforePrepare(sh, conn, transactionTimeout);
    }

}
