use of com.pamirs.attach.plugin.common.datasource.normal.NormalConnection in project LinkAgent by shulieTech.
the class TomcatJdbcMediatorDataSource method getConnection.
@Override
public Connection getConnection() throws SQLException {
if (Pradar.isClusterTest()) {
try {
init();
TomcatJdbcConstants.dbConnectionKey = dbConnectionKey;
TomcatJdbcConstants.dbType = dbType;
TomcatJdbcConstants.useTable = useTable;
if (useTable) {
// 影子表
if (dataSourceBusiness == null) {
throw new PressureMeasureError("Business dataSource is null.");
}
return new NormalConnection(dataSourceBusiness, dataSourceBusiness.getConnection(), dbConnectionKey, url, username, dbType, getMidType());
} else {
// 影子库
if (dataSourcePerformanceTest == null) {
throw new PressureMeasureError("Performance dataSource is null.");
}
return new PressureConnection(dataSourceBusiness, dataSourcePerformanceTest.getConnection(), dataSourcePerformanceTest.getUrl(), dataSourcePerformanceTest.getUsername(), dbConnectionKey, dbType);
}
} catch (Throwable e) {
ErrorReporter.Error error = ErrorReporter.buildError().setErrorType(ErrorTypeEnum.DataSource).setErrorCode("datasource-0001").setMessage("数据源获取链接失败!" + ((Pradar.isClusterTest() ? "(压测流量)" : "") + ", url=" + (dataSourceBusiness == null ? null : dataSourceBusiness.getUrl()) + ", username=" + (dataSourceBusiness == null ? null : dataSourceBusiness.getUsername()))).setDetail("get connection failed by dbMediatorDataSource, url=" + (dataSourceBusiness == null ? null : dataSourceBusiness.getUrl()) + ", username=" + (dataSourceBusiness == null ? null : dataSourceBusiness.getUsername()) + "message: " + e.getMessage() + "\r\n" + printStackTrace(e));
// error.closePradar(ConfigNames.SHADOW_DATABASE_CONFIGS);
error.report();
throw new PressureMeasureError("get connection failed by dbMediatorDataSource. url=" + (dataSourceBusiness == null ? null : dataSourceBusiness.getUrl()) + ", username=" + (dataSourceBusiness == null ? null : dataSourceBusiness.getUsername()), e);
}
} else {
String dbType = JdbcUtils.getDbType(dataSourceBusiness.getUrl(), JdbcUtils.getDriverClassName(dataSourceBusiness.getUrl()));
return new BizConnection(dataSourceBusiness.getConnection(), dataSourceBusiness.getUrl(), dataSourceBusiness.getUsername(), dbType);
}
}
use of com.pamirs.attach.plugin.common.datasource.normal.NormalConnection in project LinkAgent by shulieTech.
the class TomcatJdbcMediatorDataSource method getConnection.
@Override
public Connection getConnection(String username, String password) throws SQLException {
if (Pradar.isClusterTest()) {
try {
init();
TomcatJdbcConstants.dbConnectionKey = dbConnectionKey;
TomcatJdbcConstants.dbType = dbType;
TomcatJdbcConstants.useTable = useTable;
if (useTable) {
// 影子表
if (dataSourceBusiness == null) {
throw new PressureMeasureError("Business dataSource is null.");
}
return new NormalConnection(dataSourceBusiness, dataSourceBusiness.getConnection(username, password), dbConnectionKey, url, username, dbType, "other");
} else {
// 影子库
if (dataSourcePerformanceTest == null) {
throw new PressureMeasureError("Performance dataSource is null.");
}
return new PressureConnection(dataSourceBusiness, dataSourcePerformanceTest.getConnection(username, password), url, username, dbConnectionKey, dbType);
}
} catch (Throwable e) {
ErrorReporter.Error error = ErrorReporter.buildError().setErrorType(ErrorTypeEnum.DataSource).setErrorCode("datasource-0001").setMessage("数据源获取链接失败!" + (Pradar.isClusterTest() ? "(压测流量)" : "")).setDetail("get connection failed by dbMediatorDataSource, message: " + e.getMessage() + "\r\n" + printStackTrace(e));
// error.closePradar(ConfigNames.SHADOW_DATABASE_CONFIGS);
error.report();
throw new PressureMeasureError("tomcat jdbc get connection failed by dbMediatorDataSource");
}
} else {
String dbType = JdbcUtils.getDbType(dataSourceBusiness.getUrl(), JdbcUtils.getDriverClassName(dataSourceBusiness.getUrl()));
return new BizConnection(dataSourceBusiness.getConnection(username, password), dataSourceBusiness.getUrl(), dataSourceBusiness.getUsername(), dbType);
}
}
Aggregations