package org.hzero.mybatis.helper;

/**
 * fileName: BatchSqlHelper
 * description:
 * history:
 *
 * @author 张建元 jianyuan.zhang@hand-china.com
 * @version 1.0.0
 * @since 2025/1/2 13:39
 */
public class BatchSqlHelper {
    private static final ThreadLocal<Integer> BATCH_SIZE = new ThreadLocal();
    private static final ThreadLocal<Boolean> BATCH_ENABLE = ThreadLocal.withInitial(() -> false);

    public BatchSqlHelper() {
    }

    public static void close() {
        BATCH_ENABLE.set(false);
    }

    public static void open() {
        BATCH_ENABLE.set(true);
    }

    public static boolean isOpen() {
        Boolean flag = (Boolean) BATCH_ENABLE.get();
        return Boolean.TRUE.equals(flag);
    }

    public static void size(int size) {
        BATCH_SIZE.set(size);
    }

    public static Integer getSize() {
        return (Integer) BATCH_SIZE.get();
    }

    public static void clear() {
        BATCH_ENABLE.remove();
        BATCH_SIZE.remove();
    }
}
