Search in sources :

Example 1 with SeataMode

use of com.baomidou.dynamic.datasource.enums.SeataMode in project dynamic-datasource-spring-boot-starter by baomidou.

the class AbstractDataSourceCreator method wrapDataSource.

private DataSource wrapDataSource(DataSource dataSource, DataSourceProperty dataSourceProperty) {
    String name = dataSourceProperty.getPoolName();
    DataSource targetDataSource = dataSource;
    Boolean enabledP6spy = properties.getP6spy() && dataSourceProperty.getP6spy();
    if (enabledP6spy) {
        targetDataSource = new P6DataSource(dataSource);
        log.debug("dynamic-datasource [{}] wrap p6spy plugin", name);
    }
    Boolean enabledSeata = properties.getSeata() && dataSourceProperty.getSeata();
    SeataMode seataMode = properties.getSeataMode();
    if (enabledSeata) {
        if (SeataMode.XA == seataMode) {
            targetDataSource = new DataSourceProxyXA(targetDataSource);
        } else {
            targetDataSource = new DataSourceProxy(targetDataSource);
        }
        log.debug("dynamic-datasource [{}] wrap seata plugin transaction mode ", name);
    }
    return new ItemDataSource(name, dataSource, targetDataSource, enabledP6spy, enabledSeata, seataMode);
}
Also used : P6DataSource(com.p6spy.engine.spy.P6DataSource) DataSourceProxyXA(io.seata.rm.datasource.xa.DataSourceProxyXA) DataSourceProxy(io.seata.rm.datasource.DataSourceProxy) ItemDataSource(com.baomidou.dynamic.datasource.ds.ItemDataSource) ItemDataSource(com.baomidou.dynamic.datasource.ds.ItemDataSource) P6DataSource(com.p6spy.engine.spy.P6DataSource) DataSource(javax.sql.DataSource) SeataMode(com.baomidou.dynamic.datasource.enums.SeataMode)

Aggregations

ItemDataSource (com.baomidou.dynamic.datasource.ds.ItemDataSource)1 SeataMode (com.baomidou.dynamic.datasource.enums.SeataMode)1 P6DataSource (com.p6spy.engine.spy.P6DataSource)1 DataSourceProxy (io.seata.rm.datasource.DataSourceProxy)1 DataSourceProxyXA (io.seata.rm.datasource.xa.DataSourceProxyXA)1 DataSource (javax.sql.DataSource)1