Mycat 源码阅读之dbDriver支持类型

 

 

永久链接: http://gaojingsong.iteye.com/blog/2345449



 

源码如下:

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());

扫描二维码关注公众号,回复: 303956 查看本文章

                   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;

     }



  

永久链接: http://gaojingsong.iteye.com/blog/2345449

猜你喜欢

转载自gaojingsong.iteye.com/blog/2346188