add: 新增多数据库支持

This commit is contained in:
wentao 2018-08-04 23:07:53 +08:00
parent cb6355c49a
commit 6fbb76e1f8

View File

@ -5,6 +5,7 @@ import java.util.List;
import javax.sql.DataSource; import javax.sql.DataSource;
import com.alibaba.druid.pool.DruidDataSource;
import org.nutz.boot.annotation.PropDoc; import org.nutz.boot.annotation.PropDoc;
import org.nutz.boot.starter.jdbc.DataSourceStarter; import org.nutz.boot.starter.jdbc.DataSourceStarter;
import org.nutz.dao.SqlManager; import org.nutz.dao.SqlManager;
@ -182,9 +183,29 @@ public class NutDaoStarter {
dao.setRunner(runner); dao.setRunner(runner);
} }
} }
injectManyDao();
return dao; return dao;
} }
private void injectManyDao() {
if(conf.containsKey("jdbc.many.names")) {
String names = conf.get("jdbc.many.names");
for(String name : names.split(",")) {
String prefix_name = "jdbc.many." + name + ".";
DataSource manyDataSource = conf.make(DruidDataSource.class, prefix_name);
NutDao nutDao = new NutDao();
nutDao.setDataSource(manyDataSource);
String slave_prefix = prefix_name + "slave.";
DataSource slaveDataSource = DataSourceStarter.getSlaveDataSource(ioc, conf, slave_prefix);
NutDaoRunner runner = new NutDaoRunner();
runner.setSlaveDataSource(slaveDataSource);
nutDao.setRunner(runner);
ioc.addBean(name+"Dao", nutDao);
}
}
}
/** /**
* 返回值不能是CacheManager,因为要考虑没有加ehcache的情况 * 返回值不能是CacheManager,因为要考虑没有加ehcache的情况
*/ */