use of com.pamirs.pradar.internal.config.ShadowDatabaseConfig in project LinkAgent by shulieTech.
the class TomcatJdbcDatasourceUtils method selectMatchPtDataSourceConfiguration.
private static ShadowDatabaseConfig selectMatchPtDataSourceConfiguration(DataSource source, Map<String, ShadowDatabaseConfig> shadowDbConfigurations) {
DataSource dataSource = source;
String key = DbUrlUtils.getKey(dataSource.getUrl(), dataSource.getUsername());
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 DataSourceWrapUtil method selectMatchPtDataSourceConfiguration.
@SuppressWarnings("unchecked")
private static ShadowDatabaseConfig selectMatchPtDataSourceConfiguration(HikariDataSource source, Map<String, ShadowDatabaseConfig> shadowDbConfigurations) {
HikariDataSource dataSource = source;
String key = DbUrlUtils.getKey(dataSource.getJdbcUrl(), dataSource.getUsername());
ShadowDatabaseConfig shadowDatabaseConfig = shadowDbConfigurations.get(key);
if (shadowDatabaseConfig == null) {
key = DbUrlUtils.getKey(dataSource.getJdbcUrl(), null);
shadowDatabaseConfig = shadowDbConfigurations.get(key);
}
return shadowDatabaseConfig;
}
use of com.pamirs.pradar.internal.config.ShadowDatabaseConfig in project LinkAgent by shulieTech.
the class DataSourceWrapUtil method generate.
public static HikariDataSource generate(HikariDataSource sourceDatasource) {
Map<String, ShadowDatabaseConfig> conf = GlobalConfig.getInstance().getShadowDatasourceConfigs();
if (conf == null) {
return null;
}
ShadowDatabaseConfig ptDataSourceConf = selectMatchPtDataSourceConfiguration(sourceDatasource, conf);
if (ptDataSourceConf == null) {
return null;
}
String url = ptDataSourceConf.getShadowUrl();
String username = ptDataSourceConf.getShadowUsername();
String password = ptDataSourceConf.getShadowPassword();
if (StringUtils.isBlank(url) || StringUtils.isBlank(username) || StringUtils.isBlank(password)) {
return null;
}
String driverClassName = ptDataSourceConf.getShadowDriverClassName();
if (StringUtils.isBlank(driverClassName)) {
driverClassName = sourceDatasource.getDriverClassName();
}
HikariDataSource target = new HikariDataSource();
target.setJdbcUrl(url);
target.setUsername(username);
target.setPassword(password);
target.setDriverClassName(driverClassName);
try {
Integer minIdle = ptDataSourceConf.getIntProperty("minIdle");
if (minIdle != null) {
target.setMinimumIdle(minIdle);
} else {
target.setMinimumIdle(sourceDatasource.getMinimumIdle());
}
Long connectionTimeout = ptDataSourceConf.getLongProperty("connectionTimeout");
if (connectionTimeout != null) {
target.setConnectionTimeout(connectionTimeout);
} else {
target.setConnectionTimeout(sourceDatasource.getConnectionTimeout());
}
Long idleTimeout = ptDataSourceConf.getLongProperty("idleTimeout");
if (idleTimeout != null) {
target.setIdleTimeout(idleTimeout);
} else {
target.setIdleTimeout(sourceDatasource.getIdleTimeout());
}
Long leakDetectionThreshold = ptDataSourceConf.getLongProperty("leakDetectionThreshold");
if (leakDetectionThreshold != null) {
target.setLeakDetectionThreshold(leakDetectionThreshold);
} else {
target.setLeakDetectionThreshold(sourceDatasource.getLeakDetectionThreshold());
}
Long maxLifetime = ptDataSourceConf.getLongProperty("maxLifetime");
if (maxLifetime != null) {
target.setMaxLifetime(maxLifetime);
} else {
target.setMaxLifetime(sourceDatasource.getMaxLifetime());
}
Integer maxActive = ptDataSourceConf.getIntProperty("maxActive");
if (maxActive != null) {
target.setMaximumPoolSize(maxActive);
} else {
target.setMaximumPoolSize(sourceDatasource.getMaximumPoolSize());
}
Long validationTimeout = ptDataSourceConf.getLongProperty("validationTimeout");
if (validationTimeout != null) {
target.setValidationTimeout(validationTimeout);
} else {
target.setValidationTimeout(sourceDatasource.getValidationTimeout());
}
Integer loginTimeout = ptDataSourceConf.getIntProperty("loginTimeout");
if (loginTimeout != null) {
target.setLoginTimeout(loginTimeout);
} else {
target.setLoginTimeout(sourceDatasource.getLoginTimeout());
}
String connectionInitSql = ptDataSourceConf.getProperty("connectionInitSql");
if (connectionInitSql != null) {
target.setConnectionInitSql(connectionInitSql);
} else {
target.setConnectionInitSql(sourceDatasource.getConnectionInitSql());
}
Long maxWait = ptDataSourceConf.getLongProperty("maxWait");
if (maxWait != null) {
target.setConnectionTimeout(maxWait);
} else {
target.setConnectionTimeout(sourceDatasource.getConnectionTimeout());
}
String validationQuery = ptDataSourceConf.getProperty("validationQuery");
if (validationQuery != null) {
target.setConnectionTestQuery(validationQuery);
} else {
target.setConnectionTestQuery(sourceDatasource.getConnectionTestQuery());
}
target.setReadOnly(sourceDatasource.isReadOnly());
} catch (Throwable e) {
logger.warn("", e);
}
return target;
}
use of com.pamirs.pradar.internal.config.ShadowDatabaseConfig in project LinkAgent by shulieTech.
the class SqlParser method resetMappingTables.
private static void resetMappingTables(String key, Map<String, String> mappings) {
if (GlobalConfig.getInstance().containsShadowDatabaseConfig(key)) {
ShadowDatabaseConfig shadowDatabaseConfig = GlobalConfig.getInstance().getShadowDatabaseConfig(key);
shadowDatabaseConfig.setBusinessShadowTables(mappings);
}
if (StringUtils.isNotBlank(key)) {
key = key.substring(0, key.lastIndexOf('|'));
}
if (GlobalConfig.getInstance().containsShadowDatabaseConfig(key)) {
ShadowDatabaseConfig shadowDatabaseConfig = GlobalConfig.getInstance().getShadowDatabaseConfig(key);
shadowDatabaseConfig.setBusinessShadowTables(mappings);
}
}
use of com.pamirs.pradar.internal.config.ShadowDatabaseConfig in project LinkAgent by shulieTech.
the class SqlParser method main.
public static void main(String[] args) throws SQLException {
// String sql = "insert into \"C##PYT_TEST\".M_USER(id,name,age) values(?,?,?)";
// System.out.println(parseAndReplaceSchema(sql, "aaa", "oracle"));
GlobalConfig.getInstance().setShadowDatabaseConfigs(new HashMap<String, ShadowDatabaseConfig>(), false);
ShadowDatabaseConfig shadowDatabaseConfig = new ShadowDatabaseConfig();
shadowDatabaseConfig.setBusinessShadowTables(new ConcurrentHashMap<String, String>());
shadowDatabaseConfig.getBusinessShadowTables().put("user", "pt_user");
shadowDatabaseConfig.getBusinessShadowTables().put("user2", "pt_user2");
GlobalConfig.getInstance().getShadowDatasourceConfigs().put("jdbc:mysql://127.0.0.1:3306/testdb|root", shadowDatabaseConfig);
System.out.println(parseAndReplaceTableNames(" select `testdb`.`user`.`id`, `testdb`.`user`.`name`, `testdb`.`user`.`password`, `testdb`.`user`" + ".`createTime`, `testdb`.`user`.`updateTime` from `testdb`.`user` limit ? ", "jdbc:mysql://127.0.0.1:3306/testdb|root", "mysql", "druid"));
System.out.println(parseAndReplaceTableNames("SELECT r.*, c.org_name, c.org_code, (SELECT org_name FROM t_city WHERE org_code = c.parent_code) " + "provinceName FROM t_route_rule r LEFT JOIN t_city c ON c.sys_tenant_id = 'CLOVER_T3' AND r" + ".city_uuid = c.uuid WHERE r.sys_tenant_id = 'CLOVER_T3' AND r.status != -1 AND r.uuid = ? AND r" + ".status = ? AND r.rule_name LIKE CONCAT('%', ?, '%') AND r.rule_type = ? AND r.type_time = ? AND r" + ".business_type = ? AND r.car_level = ? AND c.org_code = ? AND r.city_uuid = ? AND r.area_type = ? " + "AND r.city_uuid IN (?) AND content->'$.examineYear' = ? AND r.type_trip = ? AND r.extend_biz_type " + "= ? ORDER BY r.status DESC, r.effective_time DESC, r.version_number DESC, r.update_time DESC", "jdbc:mysql://127.0.0.1:3306/testdb|root", "mysql", "other"));
}
Aggregations