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

org.nutz.boot.starter.jdbc.DynaDataSource Maven / Gradle / Ivy

There is a newer version: 2.5.1.v20220215
Show newest version
package org.nutz.boot.starter.jdbc;

import java.io.Closeable;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.Iterator;
import java.util.logging.Logger;

import javax.sql.DataSource;

/**
 * 动态数据源
 * @author wendal([email protected])
 *
 */
public class DynaDataSource implements DataSource, Closeable {
    
    protected Iterator it;

    public DynaDataSource(Iterator it) {
        this.it = it;
    }

    /**
     * 通过迭代器获取下一个连接池,然后获取数据库连接
     */
    public Connection getConnection() throws SQLException {
        return it.next().getConnection();
    }
    
    //------------------------------------------------------------
    // 其他方法是多余的

    public PrintWriter getLogWriter() throws SQLException {
        return it.next().getLogWriter();
    }

    public void setLogWriter(PrintWriter out) throws SQLException {
    }

    public void setLoginTimeout(int seconds) throws SQLException {
    }

    public int getLoginTimeout() throws SQLException {
        return 0;
    }

    public Logger getParentLogger() throws SQLFeatureNotSupportedException {
        return null;
    }

    public  T unwrap(Class iface) throws SQLException {
        return null;
    }

    public boolean isWrapperFor(Class iface) throws SQLException {
        return false;
    }

    public Connection getConnection(String username, String password) throws SQLException {
        return it.next().getConnection(username, password);
    }

    @Override
    public void close() throws IOException {
        if (it instanceof Closeable) {
            ((Closeable) it).close();
        }
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy