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

com.xiaoleilu.hutool.db.ds.pooled.DbSetting Maven / Gradle / Ivy

There is a newer version: 3.3.2
Show newest version
package com.xiaoleilu.hutool.db.ds.pooled;

import com.xiaoleilu.hutool.db.DbUtil;
import com.xiaoleilu.hutool.setting.Setting;

/**
 * 数据库配置文件类
 * @author Looly
 *
 */
public class DbSetting {
	/** 默认的数据库连接配置文件路径 */
	public final static String DEFAULT_DB_CONFIG_PATH = "config/db.setting";
	
	private Setting setting;
	
	/**
	 * 构造
	 */
	public DbSetting() {
		this(null);
	}
	
	/**
	 * 构造
	 * @param setting 数据库配置
	 */
	public DbSetting(Setting setting) {
		if(null == setting) {
			this.setting = new Setting(DEFAULT_DB_CONFIG_PATH);
		}else{
			this.setting = setting;
		}
	}
	
	/**
	 * 获得数据库连接信息
	 * @param group 分组
	 * @return 分组
	 */
	public DbConfig getDbConfig(String group){
		DbConfig config = new DbConfig();
		
		//基本信息
		final String jdbcUrl = setting.getByGroup("url", group);
		config.setDriver(setting.getStr("driver", group, DbUtil.identifyDriver(jdbcUrl)));
		config.setUrl(jdbcUrl);
		config.setUser(setting.getStr("user", group));
		config.setPass(setting.getStr("pass", group));
		
		//连接池相关信息
		config.setInitialSize(setting.getInt("initialSize", group, 0));
		config.setMinIdle(setting.getInt("minIdle", group, 0));
		config.setMaxActive(setting.getInt("maxActive", group, 8));
		config.setMaxWait(setting.getLong("maxWait", group, 6000L));
		
		return config;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy