cn.jiangzeyin.database.config.DataSourceConfig Maven / Gradle / Ivy
package cn.jiangzeyin.database.config;
import cn.jiangzeyin.system.SystemDbLog;
import cn.jiangzeyin.system.SystemKey;
import cn.jiangzeyin.util.Assert;
import cn.jiangzeyin.util.PropertiesParser;
import cn.jiangzeyin.util.ResourceUtil;
import com.alibaba.druid.pool.DruidDataSourceFactory;
import com.mysql.jdbc.StringUtils;
import javax.sql.DataSource;
import java.io.IOException;
import java.io.InputStream;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.util.*;
/**
* 数据源配置信息
* Created by jiangzeyin on 2017/1/6.
*/
public final class DataSourceConfig {
private DataSourceConfig() {
}
private static PropertiesParser systemPropertiesParser;
public static void init(String propertyPath) throws Exception {
if (StringUtils.isNullOrEmpty(propertyPath))
throw new IllegalArgumentException("propertyPath is null ");
InputStream inputStream = ResourceUtil.getResource(propertyPath);
systemPropertiesParser = new PropertiesParser(inputStream);
String[] sourceTags = systemPropertiesParser.getStringArrayProperty(ConfigProperties.PROP_SOURCE_TAG);
Assert.notNull(sourceTags, "sourceTag is blank");
if (sourceTags.length < 1) {
throw new IllegalArgumentException("sourceTag is blank");
}
String[] configPaths = systemPropertiesParser.getStringArrayProperty(ConfigProperties.PROP_CONFIG_PATH);
Assert.notNull(configPaths, "configPath is blank");
if (configPaths.length < 1) {
throw new IllegalArgumentException("configPath is blank");
}
dataSource(sourceTags, configPaths);
//
ModifyUser.initModify(systemPropertiesParser.getPropertyGroup(ConfigProperties.PROP_LAST_MODIFY));
//
ModifyUser.initCreate(systemPropertiesParser.getPropertyGroup(ConfigProperties.PROP_CREATE));
}
private static void dataSource(String[] sourceTags, String[] configPaths) throws Exception {
SystemDbLog.getInstance().info("初始化连接数据库");
if (configPaths.length == 1) {
Map concurrentHashMap = initConfigPath(sourceTags, configPaths[0]);
DatabaseContextHolder.init(concurrentHashMap);
} else {
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy