use of com.pamirs.pradar.internal.config.ShadowDatabaseConfig in project LinkAgent by shulieTech.
the class ShadowDatabaseConfigParser method parse.
public ShadowDatabaseConfig parse(Map<String, Object> map) {
if (map == null || map.isEmpty()) {
return null;
}
int dsType = Integer.valueOf(map.get("dsType") == null ? "-1" : map.get("dsType").toString());
final String shadowTableConfig = StringUtils.trim(toString(map.get("shadowTableConfig")));
Map<String, Object> shadowDbConfig = (Map<String, Object>) map.get("shadowDbConfig");
/**
* 这块判断一下,如果是影子库则需要校验 shadowDbConfig 不为空
* 如果是影子表则需要校验 shadowTableConfig 不为空
*/
if (dsType == 0) {
if (shadowDbConfig == null) {
return null;
}
/**
* 禁用影子库+影子表模式
*/
} else if (dsType == 1) {
if (shadowTableConfig == null) {
return null;
}
} else if (dsType == 2) {
/**
* 影子库中使用影子表
*/
if (shadowDbConfig == null) {
return null;
}
} else {
return null;
}
ShadowDatabaseConfig shadowDatabaseConfig = new ShadowDatabaseConfig();
final String applicationName = StringUtils.trim(toString(map.get("applicationName")));
shadowDatabaseConfig.setApplicationName(applicationName);
shadowDatabaseConfig.setDsType(dsType);
final String url = StringUtils.trim(toString(map.get("url")));
shadowDatabaseConfig.setUrl(url);
if (StringUtils.isNotBlank(shadowTableConfig)) {
String[] arr = StringUtils.split(shadowTableConfig, ',');
if (arr != null && arr.length != 0) {
Map<String, String> businessTables = new ConcurrentHashMap<String, String>();
for (String str : arr) {
if (StringUtils.isNotBlank(str)) {
/**
* 现在配置不支持影子表名的自定义,由系统自动生成,后面如果控制台支持后,修改会非常容易
*/
businessTables.put(StringUtils.trim(str), Pradar.addClusterTestPrefix(StringUtils.trim(str)));
}
}
shadowDatabaseConfig.setBusinessShadowTables(businessTables);
}
}
if (shadowDbConfig == null) {
return shadowDatabaseConfig;
}
Map<String, Object> datasourceMediator = (Map<String, Object>) shadowDbConfig.get("datasourceMediator");
if (datasourceMediator == null) {
return shadowDatabaseConfig;
}
String businessDataSourceName = null, shadowDataSourceName = null;
businessDataSourceName = toString(datasourceMediator.get("dataSourceBusiness"));
shadowDataSourceName = toString(datasourceMediator.get("dataSourcePerformanceTest"));
if (businessDataSourceName == null || shadowDataSourceName == null) {
return shadowDatabaseConfig;
}
List<Map<String, Object>> list = (List<Map<String, Object>>) shadowDbConfig.get("dataSources");
if (list == null || list.isEmpty()) {
return shadowDatabaseConfig;
}
Map<String, Object> businessMap = null, shadowMap = null;
for (Map<String, Object> m : list) {
String id = toString(m.get("id"));
if (StringUtils.equals(id, businessDataSourceName)) {
businessMap = m;
} else if (StringUtils.equals(id, shadowDataSourceName)) {
shadowMap = m;
}
}
if (businessMap == null || shadowMap == null) {
return shadowDatabaseConfig;
}
for (Map.Entry<String, Object> entry : businessMap.entrySet()) {
if (StringUtils.equals(entry.getKey(), "id")) {
continue;
}
if (StringUtils.equals(entry.getKey(), "url")) {
shadowDatabaseConfig.setUrl(toString(entry.getValue()));
} else if (StringUtils.equals(entry.getKey(), "username")) {
shadowDatabaseConfig.setUsername(toString(entry.getValue()));
} else if (StringUtils.equals(entry.getKey(), "schema")) {
shadowDatabaseConfig.setSchema(toString(entry.getValue()));
}
}
Map<String, String> properties = new HashMap<String, String>();
for (Map.Entry<String, Object> entry : shadowMap.entrySet()) {
if (StringUtils.equals(entry.getKey(), "id")) {
continue;
}
if (StringUtils.equals(entry.getKey(), "url")) {
shadowDatabaseConfig.setShadowUrl(toString(entry.getValue()));
if (shadowDatabaseConfig.getShadowUrl().startsWith("mongodb://")) {
String[] s = shadowDatabaseConfig.getShadowUrl().split("/");
shadowDatabaseConfig.setShadowSchema(s[s.length - 1]);
}
} else if (StringUtils.equals(entry.getKey(), "username")) {
shadowDatabaseConfig.setShadowUsername(toString(entry.getValue()));
} else if (StringUtils.equals(entry.getKey(), "password")) {
shadowDatabaseConfig.setShadowPassword(toString(entry.getValue()));
} else if (StringUtils.equals(entry.getKey(), "driverClassName")) {
shadowDatabaseConfig.setShadowDriverClassName(toString(entry.getValue()));
} else if (StringUtils.equals(entry.getKey(), "schema")) {
shadowDatabaseConfig.setShadowSchema(toString(entry.getValue()));
} else if (StringUtils.equals(entry.getKey(), "extra")) {
Map<String, Object> extra = (Map) entry.getValue();
if (extra == null) {
continue;
}
for (Map.Entry<String, Object> inner : extra.entrySet()) {
String str = toString(inner.getValue());
if (StringUtils.isBlank(str)) {
continue;
}
properties.put(inner.getKey(), str);
}
} else {
String str = toString(entry.getValue());
if (StringUtils.isBlank(str)) {
continue;
}
properties.put(entry.getKey(), str);
}
}
shadowDatabaseConfig.setProperties(properties);
String bizschema = shadowDatabaseConfig.getSchema();
String shadowSchema = shadowDatabaseConfig.getShadowSchema();
if (StringUtil.isEmpty(bizschema) && !StringUtil.isEmpty(shadowSchema)) {
shadowDatabaseConfig.setSchema(shadowSchema);
}
return shadowDatabaseConfig;
}
use of com.pamirs.pradar.internal.config.ShadowDatabaseConfig in project LinkAgent by shulieTech.
the class DatabaseUtils method isShadowDatasource.
/**
* 判断是否是影子数据源
*
* @param url
* @param username
* @return
*/
public static boolean isShadowDatasource(String url, String username) {
String key = DbUrlUtils.getKey(url, username);
ShadowDatabaseConfig shadowDatabaseConfig = GlobalConfig.getInstance().getShadowDatabaseConfig(key);
if (shadowDatabaseConfig == null) {
/**
* 解决现在影子表配置没有username的问题,再尝试使用非用户名的判断一次
*/
key = DbUrlUtils.getKey(url, null);
}
shadowDatabaseConfig = GlobalConfig.getInstance().getShadowDatabaseConfig(key);
if (shadowDatabaseConfig == null) {
return false;
}
return shadowDatabaseConfig.isShadowDatabase();
}
use of com.pamirs.pradar.internal.config.ShadowDatabaseConfig in project LinkAgent by shulieTech.
the class AtomikosDataSourceBeanWrapUtil method generate.
public static AtomikosDataSourceBean generate(AtomikosDataSourceBean sourceDatasource) {
Map<String, ShadowDatabaseConfig> conf = GlobalConfig.getInstance().getShadowDatasourceConfigs();
if (conf == null) {
return null;
}
ShadowDatabaseConfig ptDataSourceConf = selectMatchPtDataSourceConfiguration(sourceDatasource, conf);
if (ptDataSourceConf == null) {
return null;
}
String driverClassName = ptDataSourceConf.getShadowDriverClassName();
String url = ptDataSourceConf.getShadowUrl();
String username = ptDataSourceConf.getShadowUsername();
String password = ptDataSourceConf.getShadowPassword();
String xaDataSourceClassName = ptDataSourceConf.getProperty("xaDataSourceClassName");
if (StringUtils.isBlank(driverClassName)) {
driverClassName = getDriverClassName(sourceDatasource);
}
/**
* 如果是 mysql 需要检查一下参数中是否有pinGlobalTxToPhysicalConnection=true
*/
if (JdbcUtils.isMySqlDriver(driverClassName)) {
if (StringUtils.indexOf(url, "pinGlobalTxToPhysicalConnection") == -1) {
if (StringUtils.indexOf(url, '?') != -1) {
url += "&pinGlobalTxToPhysicalConnection=true";
} else {
url += "?pinGlobalTxToPhysicalConnection=true";
}
}
}
if (StringUtils.isBlank(url) || StringUtils.isBlank(username) || StringUtils.isBlank(password)) {
logger.error("ATOMIKOS: url/username/password/xaDataSourceClassName can't not be null,{} {} {} {}", url, username, password);
return null;
}
if (xaDataSourceClassName == null) {
logger.warn("ATOMIKOS: xaDataSourceClassName is empty. use business xaDataSourceClassName:{}", sourceDatasource.getXaDataSourceClassName());
xaDataSourceClassName = sourceDatasource.getXaDataSourceClassName();
}
Class clazz = null;
try {
clazz = Class.forName(xaDataSourceClassName);
} catch (Throwable e) {
logger.warn("ATOMIKOS: can't load class xaDataSourceClassName:{}", sourceDatasource.getXaDataSourceClassName(), e);
return null;
}
AtomikosDataSourceBean target = new AtomikosDataSourceBean();
Properties properties = new Properties();
if (hasField(clazz, "URL")) {
properties.put("URL", url);
} else if (hasField(clazz, "url")) {
properties.put("url", url);
}
if (hasField(clazz, "user")) {
properties.put("user", username);
}
if (hasField(clazz, "username")) {
properties.put("username", username);
} else if (hasField(clazz, "user")) {
properties.put("user", username);
} else if (hasField(clazz, "User")) {
properties.put("User", username);
}
if (hasField(clazz, "password")) {
properties.put("password", password);
}
if (hasField(clazz, "driverClassName")) {
properties.put("driverClassName", driverClassName);
} else if (hasField(clazz, "driverClass")) {
properties.put("driverClass", driverClassName);
} else if (hasField(clazz, "driver")) {
properties.put("driver", driverClassName);
}
if (hasField(clazz, "initialSize")) {
Integer initialSize = ptDataSourceConf.getIntProperty("initialSize", getIntProperty(sourceDatasource, "initialSize", 1));
properties.put("initialSize", initialSize);
}
if (hasField(clazz, "minIdle")) {
Integer minIdle = ptDataSourceConf.getIntProperty("minIdle", getIntProperty(sourceDatasource, "minIdle", 1));
properties.put("minIdle", minIdle);
}
Integer maxActive = ptDataSourceConf.getIntProperty("maxActive");
if (maxActive != null) {
if (hasField(clazz, "maxActive")) {
properties.put("maxActive", maxActive);
}
} else {
if (hasField(clazz, "maxActive")) {
final String maxActive1 = getProperty(sourceDatasource, "maxActive");
if (NumberUtils.isDigits(maxActive1)) {
properties.put("maxActive", Integer.valueOf(maxActive1));
}
}
}
Integer maxWait = ptDataSourceConf.getIntProperty("maxWait");
if (maxWait != null) {
if (hasField(clazz, "maxWait")) {
properties.put("maxWait", maxWait);
}
} else {
if (hasField(clazz, "maxWait")) {
final String maxWait1 = getProperty(sourceDatasource, "maxWait");
if (NumberUtils.isDigits(maxWait1)) {
properties.put("maxWait", Integer.valueOf(maxWait1));
}
}
}
Integer timeBetweenEvictionRunsMillis = ptDataSourceConf.getIntProperty("timeBetweenEvictionRunsMillis");
if (timeBetweenEvictionRunsMillis != null) {
if (hasField(clazz, "timeBetweenEvictionRunsMillis")) {
properties.put("timeBetweenEvictionRunsMillis", timeBetweenEvictionRunsMillis);
}
} else {
if (hasField(clazz, "timeBetweenEvictionRunsMillis")) {
final String timeBetweenEvictionRunsMillis1 = getProperty(sourceDatasource, "timeBetweenEvictionRunsMillis");
if (NumberUtils.isDigits(timeBetweenEvictionRunsMillis1)) {
properties.put("timeBetweenEvictionRunsMillis", Integer.valueOf(timeBetweenEvictionRunsMillis1));
}
}
}
Integer minEvictableIdleTimeMillis = ptDataSourceConf.getIntProperty("minEvictableIdleTimeMillis");
if (minEvictableIdleTimeMillis != null) {
if (hasField(clazz, "minEvictableIdleTimeMillis")) {
properties.put("minEvictableIdleTimeMillis", minEvictableIdleTimeMillis);
}
} else {
if (hasField(clazz, "minEvictableIdleTimeMillis")) {
final String minEvictableIdleTimeMillis1 = getProperty(sourceDatasource, "minEvictableIdleTimeMillis");
if (NumberUtils.isDigits(minEvictableIdleTimeMillis1)) {
properties.put("minEvictableIdleTimeMillis", Integer.valueOf(minEvictableIdleTimeMillis1));
}
}
}
Integer validationQueryTimeout = ptDataSourceConf.getIntProperty("validationQueryTimeout");
if (validationQueryTimeout != null) {
if (hasField(clazz, "validationQueryTimeout")) {
properties.put("validationQueryTimeout", validationQueryTimeout);
}
} else {
if (hasField(clazz, "validationQueryTimeout")) {
final String validationQueryTimeout1 = getProperty(sourceDatasource, "validationQueryTimeout");
if (validationQueryTimeout1 != null) {
properties.put("validationQueryTimeout", validationQueryTimeout1);
}
}
}
String validationQuery = ptDataSourceConf.getProperty("validationQuery");
if (validationQuery != null) {
if (hasField(clazz, "validationQuery")) {
properties.put("validationQuery", validationQuery);
}
} else {
if (hasField(clazz, "validationQuery")) {
final String validationQuery1 = getProperty(sourceDatasource, "validationQuery");
if (validationQuery1 != null) {
properties.put("validationQuery", validationQuery1);
}
}
}
Boolean testWhileIdle = ptDataSourceConf.getBooleanProperty("testWhileIdle");
if (testWhileIdle != null) {
if (hasField(clazz, "testWhileIdle")) {
properties.put("testWhileIdle", testWhileIdle);
}
} else {
if (hasField(clazz, "testWhileIdle")) {
final String testWhileIdle1 = getProperty(sourceDatasource, "testWhileIdle");
if (testWhileIdle1 != null) {
properties.put("testWhileIdle", Boolean.valueOf(testWhileIdle1));
}
}
}
Boolean testOnBorrow = ptDataSourceConf.getBooleanProperty("testOnBorrow");
if (testOnBorrow != null) {
if (hasField(clazz, "testOnBorrow")) {
properties.put("testOnBorrow", testOnBorrow);
}
} else {
if (hasField(clazz, "testOnBorrow")) {
final String testOnBorrow1 = getProperty(sourceDatasource, "testOnBorrow");
if (testOnBorrow1 != null) {
properties.put("testOnBorrow", Boolean.valueOf(testOnBorrow1));
}
}
}
Boolean testOnReturn = ptDataSourceConf.getBooleanProperty("testOnReturn");
if (testOnReturn != null) {
if (hasField(clazz, "testOnReturn")) {
properties.put("testOnReturn", testOnReturn);
}
} else {
if (hasField(clazz, "testOnReturn")) {
final String testOnReturn1 = getProperty(sourceDatasource, "testOnReturn");
if (testOnReturn1 != null) {
properties.put("testOnReturn", Boolean.valueOf(testOnReturn1));
}
}
}
Boolean poolPreparedStatements = ptDataSourceConf.getBooleanProperty("poolPreparedStatements");
if (poolPreparedStatements != null) {
if (hasField(clazz, "poolPreparedStatements")) {
properties.put("poolPreparedStatements", poolPreparedStatements);
}
} else {
if (hasField(clazz, "poolPreparedStatements")) {
final String poolPreparedStatements1 = getProperty(sourceDatasource, "poolPreparedStatements");
if (poolPreparedStatements1 != null) {
properties.put("poolPreparedStatements", Boolean.valueOf(poolPreparedStatements1));
}
}
}
Integer maxPoolPreparedStatementPerConnectionSize = ptDataSourceConf.getIntProperty("maxPoolPreparedStatementPerConnectionSize");
if (maxPoolPreparedStatementPerConnectionSize != null) {
if (hasField(clazz, "maxPoolPreparedStatementPerConnectionSize")) {
properties.put("maxPoolPreparedStatementPerConnectionSize", maxPoolPreparedStatementPerConnectionSize);
}
} else {
if (hasField(clazz, "maxPoolPreparedStatementPerConnectionSize")) {
final String maxPoolPreparedStatementPerConnectionSize1 = getProperty(sourceDatasource, "maxPoolPreparedStatementPerConnectionSize");
if (NumberUtils.isDigits(maxPoolPreparedStatementPerConnectionSize1)) {
properties.put("maxPoolPreparedStatementPerConnectionSize", Integer.valueOf(maxPoolPreparedStatementPerConnectionSize1));
}
}
}
Boolean pinGlobalTxToPhysicalConnection = ptDataSourceConf.getBooleanProperty("pinGlobalTxToPhysicalConnection");
if (pinGlobalTxToPhysicalConnection != null) {
if (hasField(clazz, "pinGlobalTxToPhysicalConnection")) {
properties.put("pinGlobalTxToPhysicalConnection", pinGlobalTxToPhysicalConnection);
}
} else {
if (hasField(clazz, "pinGlobalTxToPhysicalConnection")) {
final String pinGlobalTxToPhysicalConnection1 = getProperty(sourceDatasource, "pinGlobalTxToPhysicalConnection");
if (NumberUtils.isDigits(pinGlobalTxToPhysicalConnection1)) {
properties.put("pinGlobalTxToPhysicalConnection", Integer.valueOf(pinGlobalTxToPhysicalConnection1));
}
}
}
String filters = ptDataSourceConf.getProperty("filters");
if (filters != null) {
if (hasField(clazz, "filters")) {
properties.put("filters", filters);
}
} else {
if (hasField(clazz, "filters")) {
final String filters1 = getProperty(sourceDatasource, "filters");
if (filters1 != null) {
properties.put("filters", filters1);
}
}
}
String connectionProperties = ptDataSourceConf.getProperty("connectionProperties");
if (connectionProperties != null) {
if (hasField(clazz, "connectionProperties")) {
properties.put("connectionProperties", connectionProperties);
}
} else {
if (hasField(clazz, "connectionProperties")) {
final String connectionProperties1 = getProperty(sourceDatasource, "connectionProperties");
if (connectionProperties1 != null) {
properties.put("connectionProperties", connectionProperties1);
}
}
}
target.setXaProperties(properties);
target.setXaDataSourceClassName(xaDataSourceClassName);
Integer minPoolSize = ptDataSourceConf.getIntProperty("minPoolSize");
if (minPoolSize != null) {
target.setMinPoolSize(minPoolSize);
} else {
target.setMinPoolSize(getIntProperty(sourceDatasource, "minPoolSize", 1));
}
Integer maxPoolSize = ptDataSourceConf.getIntProperty("maxPoolSize");
if (maxPoolSize != null) {
target.setMaxPoolSize(maxPoolSize);
} else {
target.setMaxPoolSize(getIntProperty(sourceDatasource, "maxPoolSize", 1));
}
Integer poolSize = ptDataSourceConf.getIntProperty("poolSize");
if (poolSize != null) {
target.setPoolSize(poolSize);
} else {
target.setPoolSize(getIntProperty(sourceDatasource, "poolSize", 1));
}
Integer borrowConnectionTimeout = ptDataSourceConf.getIntProperty("borrowConnectionTimeout");
if (borrowConnectionTimeout != null) {
target.setBorrowConnectionTimeout(borrowConnectionTimeout);
} else {
target.setBorrowConnectionTimeout(getIntProperty(sourceDatasource, "borrowConnectionTimeout", 30));
}
Integer reapTimeout = ptDataSourceConf.getIntProperty("reapTimeout");
if (reapTimeout != null) {
target.setReapTimeout(reapTimeout);
} else {
target.setReapTimeout(getIntProperty(sourceDatasource, "reapTimeout", 0));
}
Integer maintenanceInterval = ptDataSourceConf.getIntProperty("maintenanceInterval");
if (maintenanceInterval != null) {
target.setMaintenanceInterval(maintenanceInterval);
} else {
target.setMaintenanceInterval(getIntProperty(sourceDatasource, "maintenanceInterval", 60));
}
Integer maxIdleTime = ptDataSourceConf.getIntProperty("maxIdleTime");
if (maxIdleTime != null) {
target.setMaxIdleTime(Integer.valueOf(maxIdleTime));
} else {
target.setMaxIdleTime(getIntProperty(sourceDatasource, "maxIdleTime", 60));
}
Integer maxLifetime = ptDataSourceConf.getIntProperty("maxLifetime");
if (maxLifetime != null) {
target.setMaxLifetime(maxLifetime);
} else {
target.setMaxLifetime(getIntProperty(sourceDatasource, "maxLifetime", 0));
}
String testQuery = ptDataSourceConf.getProperty("testQuery");
if (StringUtils.isNotBlank(testQuery)) {
target.setTestQuery(testQuery);
} else {
target.setTestQuery(getProperty(sourceDatasource, "testQuery"));
}
Boolean concurrentConnectionValidation = ptDataSourceConf.getBooleanProperty("concurrentConnectionValidation");
if (concurrentConnectionValidation != null) {
target.setConcurrentConnectionValidation(concurrentConnectionValidation);
} else {
target.setConcurrentConnectionValidation(getBooleanProperty(sourceDatasource, "concurrentConnectionValidation", true));
}
String resourceName = ptDataSourceConf.getProperty("resourceName");
if (StringUtils.isNotBlank(resourceName)) {
target.setUniqueResourceName(resourceName);
} else {
target.setUniqueResourceName(Pradar.addClusterTestSuffixRodLower(Pradar.addClusterTestPrefixRodLower(sourceDatasource.getUniqueResourceName())));
}
Integer defaultIsolationLevel = ptDataSourceConf.getIntProperty("defaultIsolationLevel");
if (defaultIsolationLevel != null) {
target.setDefaultIsolationLevel(defaultIsolationLevel);
} else {
target.setDefaultIsolationLevel(getIntProperty(sourceDatasource, "defaultIsolationLevel", -1));
}
return target;
}
use of com.pamirs.pradar.internal.config.ShadowDatabaseConfig in project LinkAgent by shulieTech.
the class AtomikosNonXADataSourceBeanWrapUtil method selectMatchPtDataSourceConfiguration.
private static ShadowDatabaseConfig selectMatchPtDataSourceConfiguration(AtomikosNonXADataSourceBean source, Map<String, ShadowDatabaseConfig> shadowDbConfigurations) {
AtomikosNonXADataSourceBean dataSource = source;
String key = DbUrlUtils.getKey(dataSource.getUrl(), dataSource.getUser());
ShadowDatabaseConfig shadowDatabaseConfig = shadowDbConfigurations.get(key);
if (shadowDatabaseConfig == null) {
key = DbUrlUtils.getKey(dataSource.getUrl(), null);
shadowDatabaseConfig = shadowDbConfigurations.get(key);
}
return shadowDatabaseConfig;
}
use of com.pamirs.pradar.internal.config.ShadowDatabaseConfig in project LinkAgent by shulieTech.
the class TomcatJdbcDatasourceUtils method generateDatasourceFromConfiguration.
public static DataSource generateDatasourceFromConfiguration(DataSource sourceDatasource, Map<String, ShadowDatabaseConfig> shadowDbConfigurations) {
if (shadowDbConfigurations == null) {
return null;
}
ShadowDatabaseConfig ptDataSourceConf = selectMatchPtDataSourceConfiguration(sourceDatasource, shadowDbConfigurations);
if (ptDataSourceConf == null) {
return null;
}
String url = ptDataSourceConf.getShadowUrl();
String username = ptDataSourceConf.getShadowUsername();
String password = ptDataSourceConf.getShadowPassword();
String initialSize = ptDataSourceConf.getProperty("initialSize");
String minIdle = ptDataSourceConf.getProperty("minIdle");
String maxActive = ptDataSourceConf.getProperty("maxActive");
String maxWait = ptDataSourceConf.getProperty("maxWait");
String timeBetweenEvictionRunsMillis = ptDataSourceConf.getProperty("timeBetweenEvictionRunsMillis");
String minEvictableIdleTimeMillis = ptDataSourceConf.getProperty("minEvictableIdleTimeMillis");
String validationQuery = ptDataSourceConf.getProperty("validationQuery");
String testWhileIdle = ptDataSourceConf.getProperty("testWhileIdle");
String testOnBorrow = ptDataSourceConf.getProperty("testOnBorrow");
String testOnReturn = ptDataSourceConf.getProperty("testOnReturn");
if (StringUtils.isBlank(url) || StringUtils.isBlank(username) || StringUtils.isBlank(password)) {
return null;
}
String driverClassName = ptDataSourceConf.getShadowDriverClassName();
if (StringUtils.isBlank(driverClassName)) {
driverClassName = sourceDatasource.getDriverClassName();
}
DataSource target = new DataSource();
target.setUrl(url);
target.setUsername(username);
target.setPassword(password);
target.setDriverClassName(driverClassName);
try {
if (initialSize != null) {
target.setInitialSize(Integer.parseInt(initialSize));
} else {
target.setInitialSize(sourceDatasource.getInitialSize());
}
if (minIdle != null) {
target.setMinIdle(Integer.parseInt(minIdle));
} else {
target.setMinIdle(sourceDatasource.getMinIdle());
}
if (maxActive != null) {
target.setMaxActive(Integer.parseInt(maxActive));
target.setMaxIdle(Integer.parseInt(maxActive));
} else {
target.setMaxActive(sourceDatasource.getMaxActive());
target.setMaxIdle(sourceDatasource.getMaxIdle());
}
if (maxWait != null) {
target.setMaxWait(Integer.parseInt(maxWait));
} else {
target.setMaxWait(sourceDatasource.getMaxWait());
}
if (timeBetweenEvictionRunsMillis != null) {
target.setTimeBetweenEvictionRunsMillis(Integer.parseInt(timeBetweenEvictionRunsMillis));
} else {
target.setTimeBetweenEvictionRunsMillis(sourceDatasource.getTimeBetweenEvictionRunsMillis());
}
if (minEvictableIdleTimeMillis != null) {
target.setMinEvictableIdleTimeMillis(Integer.parseInt(minEvictableIdleTimeMillis));
} else {
target.setMinEvictableIdleTimeMillis(sourceDatasource.getMinEvictableIdleTimeMillis());
}
if (validationQuery != null) {
target.setValidationQuery(validationQuery);
} else {
target.setValidationQuery(sourceDatasource.getValidationQuery());
}
if (testWhileIdle != null) {
target.setTestWhileIdle(Boolean.parseBoolean(testWhileIdle));
} else {
target.setTestWhileIdle(sourceDatasource.isTestWhileIdle());
}
if (testOnBorrow != null) {
target.setTestOnBorrow(Boolean.parseBoolean(testOnBorrow));
} else {
target.setTestOnBorrow(sourceDatasource.isTestOnBorrow());
}
if (testOnReturn != null) {
target.setTestOnReturn(Boolean.parseBoolean(testOnReturn));
} else {
target.setTestOnReturn(sourceDatasource.isTestOnReturn());
}
} catch (Exception e) {
logger.warn(e.getMessage(), e);
}
return target;
}
Aggregations