【小笔记】Activiti扩展数据库支持类型

场景

项目需要使用GaussDB,Activiti默认支持的数据库中不包含GaussDB,需要对其进行扩展。

分析

在其源码org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.getDefaultDatabaseTypeMappings()中,写明了支持的数据库的类型:

h2、hsql、mysql、oracle、postgres、mssql、db2

并在初始化时进行了初始化:

protected static Properties databaseTypeMappings = getDefaultDatabaseTypeMappings();

public void initDatabaseType() {
	...
	省略内容
	...
}

如果获取到的数据库类型不在支持列表中,则会抛错:

connection = this.dataSource.getConnection();
            DatabaseMetaData databaseMetaData = connection.getMetaData();
            String databaseProductName = databaseMetaData.getDatabaseProductName();
this.databaseType = databaseTypeMappings.getProperty(databaseProductName);
            if (this.databaseType == null) {
                throw new ActivitiException("couldn't deduct database type from database product name '" + databaseProductName + "'");
            }

查看它的实现类,发现有个Spring实现的:

在这里插入图片描述

所以继承这个SpringProcesEnineConfiguration,重写一下initDatabaseType(),将其注入为Bean,即可进行扩展。

实现

重写initDatabaseType()

public class SpringProcessEngineConfigurationWithGauss extends SpringProcessEngineConfiguration {
    private static Logger log = LoggerFactory.getLogger(SpringProcessEngineConfigurationWithGauss.class);

    private static Properties databaseTypeMappings = getDefaultDatabaseTypeMappings();

    public static Properties getDefaultDatabaseTypeMappings() {
        Properties databaseTypeMappings = new Properties();
        ...
        省略其他
		...
        databaseTypeMappings.setProperty("Zenith", "Zenith");
        return databaseTypeMappings;
    }

    @Override
    public void initDatabaseType() {
        Connection connection = null;

        try {
            connection = this.dataSource.getConnection();
            DatabaseMetaData databaseMetaData = connection.getMetaData();
            String databaseProductName = databaseMetaData.getDatabaseProductName();
            log.debug("database product name: '{}'", databaseProductName);
            this.databaseType = databaseTypeMappings.getProperty(databaseProductName);
            if (this.databaseType == null) {
                throw new ActivitiException("couldn't deduct database type from database product name '" + databaseProductName + "'");
            }

            log.debug("using database type: {}", this.databaseType);
            if ("mssql".equals(this.databaseType)) {
                this.maxNrOfStatementsInBulkInsert = this.DEFAULT_MAX_NR_OF_STATEMENTS_BULK_INSERT_SQL_SERVER;
            }
        } catch (SQLException var12) {
            log.error("Exception while initializing Database connection", var12);
        } finally {
            try {
                if (connection != null) {
                    connection.close();
                }
            } catch (SQLException var11) {
                log.error("Exception while closing the Database connection", var11);
            }

        }
    }
}

将其注入:

@Bean
    public SpringProcessEngineConfigurationWithGauss processEngineConfiguration() {
        SpringProcessEngineConfigurationWithGauss configuration = new SpringProcessEngineConfigurationWithGauss();
        ...
        省略其他配置
		...
        return configuration;

    }

其次需要在activiti的包里新增一个文件:

org\activiti\db\properties\下新增Zenith.properties配置文件,主要作用是为不同数据库配置分页语法,GuassDB是支持类似Mysql的分页的,所以直接使用Mysql的即可。内容如下:

limitAfter=LIMIT #{maxResults} OFFSET #{firstResult}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

勇敢牛牛_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值