All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.yomahub.liteflow.parser.sql.read.SqlReadFactory Maven / Gradle / Ivy

package com.yomahub.liteflow.parser.sql.read;

import com.yomahub.liteflow.parser.constant.ReadType;
import com.yomahub.liteflow.parser.sql.polling.SqlReadPollTask;
import com.yomahub.liteflow.parser.sql.polling.impl.ChainReadPollTask;
import com.yomahub.liteflow.parser.sql.polling.impl.ScriptReadPollTask;
import com.yomahub.liteflow.parser.sql.read.impl.ChainRead;
import com.yomahub.liteflow.parser.sql.read.impl.ScriptRead;
import com.yomahub.liteflow.parser.sql.vo.SQLParserVO;

import java.util.HashMap;
import java.util.Map;

/**
 * sql 读取工厂类
 *
 * @author tangkc
 * @author houxinyu
 * @since 2.11.1
 */
public class SqlReadFactory {
    private static final Map> READ_MAP = new HashMap<>();
    private static final Map> POLL_TASK_MAP = new HashMap<>();

    public static void registerRead(SQLParserVO config) {
        READ_MAP.put(ReadType.CHAIN, new ChainRead(config));
        READ_MAP.put(ReadType.SCRIPT, new ScriptRead(config));
    }

    public static void registerSqlReadPollTask(ReadType readType) {
        SqlRead sqlRead = getSqlRead(readType);
        if (ReadType.CHAIN.equals(readType)) {
            POLL_TASK_MAP.put(ReadType.CHAIN, new ChainReadPollTask((ChainRead)sqlRead));
        } else if (ReadType.SCRIPT.equals(readType)) {
            POLL_TASK_MAP.put(ReadType.SCRIPT, new ScriptReadPollTask((ScriptRead)sqlRead));
        }
    }

    @SuppressWarnings("unchecked")
    public static  SqlRead getSqlRead(ReadType readType) {
        return (SqlRead)READ_MAP.get(readType);
    }

    @SuppressWarnings("unchecked")
    public static  SqlReadPollTask getSqlReadPollTask(ReadType readType) {
        return (SqlReadPollTask)POLL_TASK_MAP.get(readType);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy