Search in sources :

Example 1 with AtomikosNormalConnection

use of com.pamirs.attach.plugin.atomikos.connection.AtomikosNormalConnection in project LinkAgent by shulieTech.

the class AtomikosDataSourceBeanMediaDataSource method getConnection.

@Override
public Connection getConnection() throws SQLException {
    if (Pradar.isClusterTest()) {
        try {
            init();
            if (useTable) {
                // 影子表
                if (dataSourceBusiness == null) {
                    throw new PressureMeasureError("[atomikos] Business dataSource is null.");
                }
                Connection connection = dataSourceBusiness.getConnection();
                return new AtomikosNormalConnection(dataSourceBusiness, connection, dbConnectionKey, url, username, dbType);
            } else {
                if (dataSourcePerformanceTest == null) {
                    throw new PressureMeasureError("[atomikos] pressure dataSource is null.");
                }
                return new AtomikosPressureConnection(dataSourcePerformanceTest, dataSourcePerformanceTest.getConnection(), getUrl(dataSourcePerformanceTest), getUsername(dataSourcePerformanceTest), dbConnectionKey, dbType);
            }
        } catch (Throwable e) {
            ErrorReporter.Error error = ErrorReporter.buildError().setErrorType(ErrorTypeEnum.DataSource).setErrorCode("datasource-0001").setMessage("数据源获取链接失败!" + (Pradar.isClusterTest() ? "(压测流量)" : "")).setDetail("[atomikos] get connection failed by dbMediatorDataSource, message: " + e.getMessage() + "\r\n" + printStackTrace(e));
            // error.closePradar(ConfigNames.SHADOW_DATABASE_CONFIGS);
            logger.error("ATOMIKOS: pressure test flow get connection fail.", e);
            error.report();
            throw new PressureMeasureError("pressure test flow get connection fail " + e.getMessage());
        }
    } else {
        final String url = getUrl(dataSourceBusiness);
        final String username = getUsername(dataSourceBusiness);
        String dbType = JdbcUtils.getDbType(url, JdbcUtils.getDriverClassName(url));
        return new AtomikosBizConnection(dataSourceBusiness.getConnection(), url, username, dbType);
    }
}
Also used : AtomikosBizConnection(com.pamirs.attach.plugin.atomikos.connection.AtomikosBizConnection) PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError) AtomikosNormalConnection(com.pamirs.attach.plugin.atomikos.connection.AtomikosNormalConnection) Connection(java.sql.Connection) AtomikosBizConnection(com.pamirs.attach.plugin.atomikos.connection.AtomikosBizConnection) AtomikosPressureConnection(com.pamirs.attach.plugin.atomikos.connection.AtomikosPressureConnection) AtomikosPressureConnection(com.pamirs.attach.plugin.atomikos.connection.AtomikosPressureConnection) PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError) AtomikosNormalConnection(com.pamirs.attach.plugin.atomikos.connection.AtomikosNormalConnection)

Example 2 with AtomikosNormalConnection

use of com.pamirs.attach.plugin.atomikos.connection.AtomikosNormalConnection in project LinkAgent by shulieTech.

the class AtomikosDataSourceBeanMediaDataSource method getConnection.

@Override
public Connection getConnection(String username, String password) throws SQLException {
    if (Pradar.isClusterTest()) {
        try {
            init();
            if (useTable) {
                // 影子表
                if (dataSourceBusiness == null) {
                    throw new RuntimeException("[atomikos] Business dataSource is null.");
                }
                Connection connection = dataSourceBusiness.getConnection(username, password);
                return new AtomikosNormalConnection(dataSourceBusiness, connection, dbConnectionKey, url, username, dbType);
            } else {
                if (dataSourcePerformanceTest == null) {
                    throw new RuntimeException("[atomikos] pressure dataSource is null.");
                }
                return new AtomikosPressureConnection(dataSourcePerformanceTest, dataSourcePerformanceTest.getConnection(username, password), getUrl(dataSourcePerformanceTest), getUsername(dataSourcePerformanceTest), dbConnectionKey, dbType);
            }
        } catch (Throwable e) {
            ErrorReporter.Error error = ErrorReporter.buildError().setErrorType(ErrorTypeEnum.DataSource).setErrorCode("datasource-0001").setMessage("数据源获取链接失败!" + ((Pradar.isClusterTest() ? "(压测流量)" : "") + ", url=" + (dataSourceBusiness == null ? null : getUrl(dataSourceBusiness)) + ", username=" + (dataSourceBusiness == null ? null : getUsername(dataSourceBusiness)))).setDetail("get connection failed by dbMediatorDataSource, url=" + (dataSourceBusiness == null ? null : getUrl(dataSourceBusiness)) + ", username=" + (dataSourceBusiness == null ? null : getUsername(dataSourceBusiness)) + "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 : getUrl(dataSourceBusiness)) + ", username=" + (dataSourceBusiness == null ? null : getUsername(dataSourceBusiness)), e);
        }
    } else {
        final String url = getUrl(dataSourceBusiness);
        String dbType = JdbcUtils.getDbType(url, JdbcUtils.getDriverClassName(url));
        return new AtomikosBizConnection(dataSourceBusiness.getConnection(username, password), url, getUsername(dataSourceBusiness), dbType);
    }
}
Also used : AtomikosBizConnection(com.pamirs.attach.plugin.atomikos.connection.AtomikosBizConnection) PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError) AtomikosNormalConnection(com.pamirs.attach.plugin.atomikos.connection.AtomikosNormalConnection) Connection(java.sql.Connection) AtomikosBizConnection(com.pamirs.attach.plugin.atomikos.connection.AtomikosBizConnection) AtomikosPressureConnection(com.pamirs.attach.plugin.atomikos.connection.AtomikosPressureConnection) AtomikosPressureConnection(com.pamirs.attach.plugin.atomikos.connection.AtomikosPressureConnection) PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError) AtomikosNormalConnection(com.pamirs.attach.plugin.atomikos.connection.AtomikosNormalConnection)

Aggregations

AtomikosBizConnection (com.pamirs.attach.plugin.atomikos.connection.AtomikosBizConnection)2 AtomikosNormalConnection (com.pamirs.attach.plugin.atomikos.connection.AtomikosNormalConnection)2 AtomikosPressureConnection (com.pamirs.attach.plugin.atomikos.connection.AtomikosPressureConnection)2 PressureMeasureError (com.pamirs.pradar.exception.PressureMeasureError)2 Connection (java.sql.Connection)2