Search in sources :

Example 21 with ShadowDatabaseConfig

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;
}
Also used : ShadowDatabaseConfig(com.pamirs.pradar.internal.config.ShadowDatabaseConfig) DataSource(org.apache.tomcat.jdbc.pool.DataSource)

Example 22 with 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;
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource) ShadowDatabaseConfig(com.pamirs.pradar.internal.config.ShadowDatabaseConfig)

Example 23 with 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;
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource) ShadowDatabaseConfig(com.pamirs.pradar.internal.config.ShadowDatabaseConfig)

Example 24 with ShadowDatabaseConfig

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);
    }
}
Also used : ShadowDatabaseConfig(com.pamirs.pradar.internal.config.ShadowDatabaseConfig)

Example 25 with ShadowDatabaseConfig

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"));
}
Also used : ShadowDatabaseConfig(com.pamirs.pradar.internal.config.ShadowDatabaseConfig)

Aggregations

ShadowDatabaseConfig (com.pamirs.pradar.internal.config.ShadowDatabaseConfig)39 PressureMeasureError (com.pamirs.pradar.exception.PressureMeasureError)8 ServerAddress (com.mongodb.ServerAddress)6 Map (java.util.Map)4 MongoNamespace (com.mongodb.MongoNamespace)3 ClusterSettings (com.mongodb.connection.ClusterSettings)3 ErrorReporter (com.pamirs.pradar.pressurement.agent.shared.service.ErrorReporter)3 Properties (java.util.Properties)3 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)2 AtomikosNonXADataSourceBean (com.atomikos.jdbc.nonxa.AtomikosNonXADataSourceBean)2 ComboPooledDataSource (com.mchange.v2.c3p0.ComboPooledDataSource)2 MongoClient (com.mongodb.MongoClient)2 Cluster (com.mongodb.internal.connection.Cluster)2 ShadowDataSourceConfigModifyEvent (com.pamirs.pradar.pressurement.agent.event.impl.ShadowDataSourceConfigModifyEvent)2 HikariDataSource (com.zaxxer.hikari.HikariDataSource)2 SQLException (java.sql.SQLException)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 BasicDataSource (org.apache.commons.dbcp.BasicDataSource)2 BasicDataSource (org.apache.commons.dbcp2.BasicDataSource)2 DataSource (org.apache.tomcat.jdbc.pool.DataSource)2