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

com.zhuang.data.handler.DbExecuteHandlerFactory Maven / Gradle / Ivy

There is a newer version: 1.1.2
Show newest version
package com.zhuang.data.handler;

import com.zhuang.data.config.MyDataProperties;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by zhuang on 3/23/2018.
 */
public class DbExecuteHandlerFactory {

    private static List dbExecutionHandlers;

    static {
        dbExecutionHandlers = new ArrayList<>();
        loadFromConfig();
    }

    public static List getDbExecuteHandlers() {
        return dbExecutionHandlers;
    }

    public static void addDbExecutionHandler(DbExecutionHandler dbExecutionHandler) {
        dbExecutionHandlers.add(dbExecutionHandler);
    }

    private static void loadFromConfig() {
        MyDataProperties myDataProperties = MyDataProperties.getInstance();
        List dbExecutionHandlers = myDataProperties.getDbExecutionHandlers();
        for (String item : dbExecutionHandlers) {
            try {
                Class clazz = Class.forName(item);
                boolean isDbExecutionHandlerClass = Arrays.stream(clazz.getInterfaces()).anyMatch(c -> c == DbExecutionHandler.class);
                if (isDbExecutionHandlerClass) {
                    DbExecuteHandlerFactory.addDbExecutionHandler((DbExecutionHandler) clazz.getConstructor().newInstance());
                }
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy