Search in sources :

Example 1 with JDBCDatasource

use of io.mycat.backend.jdbc.JDBCDatasource in project Mycat-Server by MyCATApache.

the class ConfigInitializer method createDataSource.

private PhysicalDatasource[] createDataSource(DataHostConfig conf, String hostName, String dbType, String dbDriver, DBHostConfig[] nodes, boolean isRead) {
    PhysicalDatasource[] dataSources = new PhysicalDatasource[nodes.length];
    if (dbType.equals("mysql") && dbDriver.equals("native")) {
        for (int i = 0; i < nodes.length; i++) {
            //设置最大idle时间,默认为30分钟
            nodes[i].setIdleTimeout(system.getIdleTimeout());
            MySQLDataSource ds = new MySQLDataSource(nodes[i], conf, isRead);
            dataSources[i] = ds;
        }
    } else if (dbDriver.equals("jdbc")) {
        for (int i = 0; i < nodes.length; i++) {
            nodes[i].setIdleTimeout(system.getIdleTimeout());
            JDBCDatasource ds = new JDBCDatasource(nodes[i], conf, isRead);
            dataSources[i] = ds;
        }
    } else if ("postgresql".equalsIgnoreCase(dbType) && dbDriver.equalsIgnoreCase("native")) {
        for (int i = 0; i < nodes.length; i++) {
            nodes[i].setIdleTimeout(system.getIdleTimeout());
            PostgreSQLDataSource ds = new PostgreSQLDataSource(nodes[i], conf, isRead);
            dataSources[i] = ds;
        }
    } else {
        throw new ConfigException("not supported yet !" + hostName);
    }
    return dataSources;
}
Also used : PhysicalDatasource(io.mycat.backend.datasource.PhysicalDatasource) PostgreSQLDataSource(io.mycat.backend.postgresql.PostgreSQLDataSource) MySQLDataSource(io.mycat.backend.mysql.nio.MySQLDataSource) JDBCDatasource(io.mycat.backend.jdbc.JDBCDatasource) ConfigException(io.mycat.config.util.ConfigException)

Example 2 with JDBCDatasource

use of io.mycat.backend.jdbc.JDBCDatasource in project Mycat-Server by MyCATApache.

the class ConfigTest method createDataSource.

private PhysicalDatasource[] createDataSource(DataHostConfig conf, String hostName, String dbType, String dbDriver, DBHostConfig[] nodes, boolean isRead) {
    PhysicalDatasource[] dataSources = new PhysicalDatasource[nodes.length];
    if (dbType.equals("mysql") && dbDriver.equals("native")) {
        for (int i = 0; i < nodes.length; i++) {
            nodes[i].setIdleTimeout(system.getIdleTimeout());
            MySQLDataSource ds = new MySQLDataSource(nodes[i], conf, isRead);
            dataSources[i] = ds;
        }
    } else if (dbDriver.equals("jdbc")) {
        for (int i = 0; i < nodes.length; i++) {
            nodes[i].setIdleTimeout(system.getIdleTimeout());
            JDBCDatasource ds = new JDBCDatasource(nodes[i], conf, isRead);
            dataSources[i] = ds;
        }
    } else {
        throw new ConfigException("not supported yet !" + hostName);
    }
    return dataSources;
}
Also used : PhysicalDatasource(io.mycat.backend.datasource.PhysicalDatasource) MySQLDataSource(io.mycat.backend.mysql.nio.MySQLDataSource) JDBCDatasource(io.mycat.backend.jdbc.JDBCDatasource) ConfigException(io.mycat.config.util.ConfigException)

Aggregations

PhysicalDatasource (io.mycat.backend.datasource.PhysicalDatasource)2 JDBCDatasource (io.mycat.backend.jdbc.JDBCDatasource)2 MySQLDataSource (io.mycat.backend.mysql.nio.MySQLDataSource)2 ConfigException (io.mycat.config.util.ConfigException)2 PostgreSQLDataSource (io.mycat.backend.postgresql.PostgreSQLDataSource)1