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

db.sql.api.impl.cmd.executor.BaseExecutor Maven / Gradle / Ivy

There is a newer version: 1.7.6-RC2
Show newest version
package db.sql.api.impl.cmd.executor;

import db.sql.api.Cmd;
import db.sql.api.DbType;
import db.sql.api.impl.cmd.CmdFactory;
import db.sql.api.tookit.CmdUtils;

import java.util.*;
import java.util.function.BiConsumer;


public abstract class BaseExecutor, CMD_FACTORY extends CmdFactory> implements Executor {

    protected final List cmds = new ArrayList<>();

    private final Map, Integer> cmdSorts = new HashMap<>();

    private List selectors;

    private boolean isExecuteSelector = false;

    public BaseExecutor() {
        this.initCmdSorts(cmdSorts);
    }

    private Selector createSelector() {
        if (Objects.isNull(this.selectors)) {
            this.selectors = new ArrayList<>();
        }
        DbSelector dbSelector = new DbSelector();
        this.selectors.add(dbSelector);
        return dbSelector;
    }

    @Override
    public SELF dbAdapt(BiConsumer consumer) {
        SELF self = (SELF) this;
        consumer.accept(self, this.createSelector());
        return (SELF) this;
    }

    @Override
    public void selectorExecute(DbType dbType) {
        if (this.isExecuteSelector) {
            return;
        }
        this.isExecuteSelector = true;
        if (Objects.isNull(this.selectors)) {
            return;
        }
        selectors.stream().forEach(dbSelector -> dbSelector.dbExecute(dbType));
    }

    @Override
    public List cmds() {
        return cmds;
    }

    protected void append(Cmd cmd) {
        cmds.add(cmd);
    }

    @Override
    public Map, Integer> cmdSorts() {
        return cmdSorts;
    }

    abstract void initCmdSorts(Map, Integer> cmdSorts);

    @Override
    public boolean contain(Cmd cmd) {
        return CmdUtils.contain(cmd, this.cmds);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy