Search in sources :

Example 1 with DriverConfig

use of com.pamirs.attach.plugin.neo4j.config.DriverConfig in project LinkAgent by shulieTech.

the class DataSourceWrapUtil method wrap.

public static void wrap(DataSourceMeta<Neo4jSession> neo4jSessionDataSourceMeta) {
    if (DataSourceWrapUtil.pressureDataSources.containsKey(neo4jSessionDataSourceMeta)) {
        return;
    }
    // 生成影子库配置
    // 初始化影子库配置
    DriverConfiguration sourceConfig = Components.driver().getConfiguration();
    Configuration shadowConfig = new Configuration();
    DriverConfiguration configuration = new DriverConfiguration(shadowConfig);
    configuration.setDriverClassName(sourceConfig.getDriverClassName());
    configuration.setConnectionPoolSize(sourceConfig.getConnectionPoolSize());
    configuration.setEncryptionLevel(sourceConfig.getEncryptionLevel());
    configuration.setTrustCertFile(sourceConfig.getTrustCertFile());
    configuration.setTrustStrategy(sourceConfig.getTrustStrategy());
    String key = DbUrlUtils.getKey(neo4jSessionDataSourceMeta.getUrl(), neo4jSessionDataSourceMeta.getUsername());
    ShadowDatabaseConfig shadowDatabaseConfig = GlobalConfig.getInstance().getShadowDatabaseConfig(key);
    if (null == shadowDatabaseConfig) {
        ErrorReporter.buildError().setErrorType(ErrorTypeEnum.DataSource).setErrorCode("datasource-0002").setMessage("没有配置对应的影子表或影子库!").setDetail("业务库配置:::url: " + neo4jSessionDataSourceMeta.getUrl()).closePradar(ConfigNames.SHADOW_DATABASE_CONFIGS).report();
        return;
    }
    configuration.setURI(shadowDatabaseConfig.getShadowUrl());
    configuration.setCredentials(shadowDatabaseConfig.getShadowUsername(), shadowDatabaseConfig.getShadowPassword());
    Driver shadowDriver = DriverService.load(configuration);
    // 生成影子库session
    Neo4jSession sourceSession = neo4jSessionDataSourceMeta.getDataSource();
    Neo4JSessionExt shadowSession = new Neo4JSessionExt(metaDataMap.get(sourceSession), shadowDriver);
    // 放入本地
    DbMediatorDataSource<Neo4jSession> driverConfigurationDbMediatorDataSource = new DriverConfig();
    driverConfigurationDbMediatorDataSource.setDataSourceBusiness(sourceSession);
    driverConfigurationDbMediatorDataSource.setDataSourcePerformanceTest(shadowSession);
    DataSourceWrapUtil.pressureDataSources.put(neo4jSessionDataSourceMeta, driverConfigurationDbMediatorDataSource);
}
Also used : Neo4JSessionExt(com.pamirs.attach.plugin.neo4j.config.Neo4JSessionExt) DriverConfiguration(org.neo4j.ogm.config.DriverConfiguration) Configuration(org.neo4j.ogm.config.Configuration) DriverConfiguration(org.neo4j.ogm.config.DriverConfiguration) Neo4jSession(org.neo4j.ogm.session.Neo4jSession) Driver(org.neo4j.ogm.driver.Driver) DriverConfig(com.pamirs.attach.plugin.neo4j.config.DriverConfig) ShadowDatabaseConfig(com.pamirs.pradar.internal.config.ShadowDatabaseConfig)

Aggregations

DriverConfig (com.pamirs.attach.plugin.neo4j.config.DriverConfig)1 Neo4JSessionExt (com.pamirs.attach.plugin.neo4j.config.Neo4JSessionExt)1 ShadowDatabaseConfig (com.pamirs.pradar.internal.config.ShadowDatabaseConfig)1 Configuration (org.neo4j.ogm.config.Configuration)1 DriverConfiguration (org.neo4j.ogm.config.DriverConfiguration)1 Driver (org.neo4j.ogm.driver.Driver)1 Neo4jSession (org.neo4j.ogm.session.Neo4jSession)1