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);
}
Aggregations