懒羊羊
2023-08-30 71e81ed1d12e4d69f53c8ad9e066650ad4186293
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package cn.stylefeng.guns.base.db.factory;
 
import cn.stylefeng.roses.core.config.properties.DruidProperties;
import com.atomikos.jdbc.AtomikosDataSourceBean;
import com.atomikos.jdbc.AtomikosSQLException;
 
import java.util.Properties;
 
/**
 * AtomikosDataSourceBean数据源工厂
 *
 * @author fengshuonan
 * @Date 2019/11/19 18:22
 */
public class AtomikosFactory {
 
    public static AtomikosDataSourceBean create(String dataSourceName, DruidProperties druidProperties) {
        AtomikosDataSourceBean atomikosDataSourceBean = new AtomikosDataSourceBean();
        atomikosDataSourceBean.setXaDataSourceClassName("com.alibaba.druid.pool.xa.DruidXADataSource");
        atomikosDataSourceBean.setUniqueResourceName(dataSourceName);
        atomikosDataSourceBean.setMaxPoolSize(100);
        atomikosDataSourceBean.setBorrowConnectionTimeout(60);
        atomikosDataSourceBean.setMinPoolSize(0);
 
        Properties properties = druidProperties.createProperties();
        atomikosDataSourceBean.setXaProperties(properties);
 
        try {
            atomikosDataSourceBean.init();
        } catch (AtomikosSQLException e) {
            e.printStackTrace();
        }
 
        return atomikosDataSourceBean;
    }
 
}