package com.zm.order.tool.server.sharding;

import org.apache.shardingsphere.api.hint.HintManager;


/**
 * @author chuchengyi
 */
public class OrderHintManager {

    /**
     * 功能：初始化化hint - 针对指定分库和分表的方式
     *
     * @param table         表名前缀
     * @param databaseIndex 库索引
     * @param tableIndex    表索引
     * @return 返回分库的manager
     */
    public static HintManager initScanHint(String table, int databaseIndex, int tableIndex) {
        HintManager hintManager = HintManager.getInstance();
        String baseIndex = HintTableExpression.genExpression(databaseIndex);
        String shareIndex = HintTableExpression.genExpression(tableIndex);
        hintManager.addDatabaseShardingValue(table, baseIndex);
        hintManager.addTableShardingValue(table, shareIndex);
        return hintManager;
    }


    /**
     * 功能：关闭HINT
     *
     * @param hintManager
     */
    public static void closeHint(HintManager hintManager) {
        if (hintManager != null) {
            hintManager.close();
        }
    }

}
