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

fun.langel.cql.invoke.AbstractInvoker Maven / Gradle / Ivy

The newest version!
package fun.langel.cql.invoke;

import fun.langel.cql.bind.Target;
import fun.langel.cql.datasource.Connection;
import fun.langel.cql.datasource.DataSource;
import fun.langel.cql.datasource.PreparedSession;
import fun.langel.cql.datasource.Session;
import fun.langel.cql.exception.DataSourceException;
import fun.langel.cql.parameter.Parameter;
import fun.langel.cql.util.Pair;

import java.util.List;


/**
 * @author [email protected](GuHan)
 * @since 2021/10/20 2:51 下午
 **/
public abstract class AbstractInvoker implements Invoker {

    private final Target target;

    private final String sql;

    private DataSource dataSource;

    private final Pair> parameterized;

    public AbstractInvoker(final Target target,
                           final DataSource dataSource,
                           final String sql,
                           final Pair> parameterized) {
        this.target = target;
        this.dataSource = dataSource;
        this.sql = sql;
        this.parameterized = parameterized;
    }

    public Target target() {
        return this.target;
    }

    public String sql() {
        return this.sql;
    }

    public DataSource getDataSource() {
        return this.dataSource;
    }

    public Connection getConnection() {
        return getDataSource() == null ? null : dataSource.getConnection();
    }

    public Session getSession() {
        Session session = getConnection() == null ? null : getConnection().getSession();
        if (session == null) {
            throw new DataSourceException("Dont find any matched datasource.");
        }
        if (session instanceof PreparedSession) {
            ((PreparedSession) session).setParameters(parameterized().right());
        }
        return session;
    }

    public Pair> parameterized() {
        return this.parameterized;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy