Activiti5.22.0扩展支持达梦数据库

前言

        目前国内部分公司做的项目要求去ioe使用国产的替代方案。数据从异构数据库中迁移到达梦,应用中使用Activiti工作流在替换了数据库驱动后启动过程报错如下:

nested exception is org.activiti.engine.ActivitiException: couldn't deduct database type from database product name 'DM DBMS'

原因是:activiti5.22.0内置的数据库类型不支持达梦数据库

解决方案

        将activiti-engine-5.22.0相关源码拷贝到工程src下,保持包路径不变,并做相应修改以支持达梦数据库。

具体如下:

 1. 在org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl,增加成员变量

public static final String DATABASE_TYPE_DM = "dm";
public static final String DATABASE_TYPE_H2 = "h2";
public static final String DATABASE_TYPE_HSQL = "hsql";
public static final String DATABASE_TYPE_MYSQL = "mysql";
public static final String DATABASE_TYPE_ORACLE = "oracle";

2. 在org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl,修改getDefaultDatabaseTypeMappings()

protected static Properties getDefaultDatabaseTypeMappings() {
    Properties databaseTypeMappings = new Properties();
    databaseTypeMappings.setProperty("DM DBMS", DATABASE_TYPE_DM);
    databaseTypeMappings.setProperty("H2", DATABASE_TYPE_H2);

3. 在org.activiti.engine.impl.db.DbSqlSessionFactory,修改initBulkInsertEnabledMap(String databaseType)

if ("oracle".equals(databaseType) || "dm".equals(databaseType)) {
    bulkInsertableMap.put(EventLogEntryEntity.class, Boolean.FALSE);
}

4. 在org.activiti.engine.impl.db.DbSqlSessionFactory,修改static{}

// dm
databaseSpecificLimitBeforeStatements.put("dm", "");
databaseSpecificLimitAfterStatements.put("dm", "LIMIT #{maxResults} OFFSET #{firstResult}");
databaseSpecificLimitBetweenStatements.put("dm", "");
databaseOuterJoinLimitBetweenStatements.put("dm", "");
databaseSpecificOrderByStatements.put("dm", defaultOrderBy);

// h2
databaseSpecificLimitBeforeStatements.put("h2", "");
databaseSpecificLimitAfterStatements.put("h2", "LIMIT #{maxResults} OFFSET #{firstResult}");
databaseSpecificLimitBetweenStatements.put("h2", "");
databaseOuterJoinLimitBetweenStatements.put("h2", "");
databaseSpecificOrderByStatements.put("h2", defaultOrderBy);

5. 在 org.activiti.engine.impl.AbstractQuery,修改addOrder(String column, String sortOrder, NullHandlingOnOrder nullHandlingOnOrder)

if (nullHandlingOnOrder.equals(NullHandlingOnOrder.NULLS_FIRST)) {

    if (ProcessEngineConfigurationImpl.DATABASE_TYPE_H2.equals(databaseType) 
            || ProcessEngineConfigurationImpl.DATABASE_TYPE_HSQL.equals(databaseType)
            || ProcessEngineConfigurationImpl.DATABASE_TYPE_POSTGRES.equals(databaseType) 
            || ProcessEngineConfigurationImpl.DATABASE_TYPE_ORACLE.equals(databaseType)
            || ProcessEngineConfigurationImpl.DATABASE_TYPE_DM.equals(databaseType)) {
        orderBy = orderBy + defaultOrderByClause + " NULLS FIRST";
    } else if (ProcessEngineConfigurationImpl.DATABASE_TYPE_MYSQL.equals(databaseType)) {
        orderBy = orderBy + "isnull(" + column + ") desc," + defaultOrderByClause;
    } else if (ProcessEngineConfigurationImpl.DATABASE_TYPE_DB2.equals(databaseType) 
            || ProcessEngineConfigurationImpl.DATABASE_TYPE_MSSQL.equals(databaseType)) {
        orderBy = orderBy + "case when " + column + " is null then 0 else 1 end," + defaultOrderByClause;
    } else {
        orderBy = orderBy + defaultOrderByClause;
    }

} else if (nullHandlingOnOrder.equals(NullHandlingOnOrder.NULLS_LAST)) {

    if (ProcessEngineConfigurationImpl.DATABASE_TYPE_H2.equals(databaseType) 
            || ProcessEngineConfigurationImpl.DATABASE_TYPE_HSQL.equals(databaseType)
            || ProcessEngineConfigurationImpl.DATABASE_TYPE_POSTGRES.equals(databaseType) 
            || ProcessEngineConfigurationImpl.DATABASE_TYPE_ORACLE.equals(databaseType)
            || ProcessEngineConfigurationImpl.DATABASE_TYPE_DM.equals(databaseType)) {
        orderBy = orderBy + column + " " + sortOrder + " NULLS LAST";
    } else if (ProcessEngineConfigurationImpl.DATABASE_TYPE_MYSQL.equals(databaseType)) {
        orderBy = orderBy + "isnull(" + column + ") asc," + defaultOrderByClause;
    } else if (ProcessEngineConfigurationImpl.DATABASE_TYPE_DB2.equals(databaseType) 
            || ProcessEngineConfigurationImpl.DATABASE_TYPE_MSSQL.equals(databaseType)) {
        orderBy = orderBy + "case when " + column + " is null then 1 else 0 end," + defaultOrderByClause;
    } else {
        orderBy = orderBy + defaultOrderByClause;
    }
}

 完成以上修改,重新编译activiti-engine-5.22.0.jar启动即可。

 

maven引入的jar包:

		<dependency>
			<groupId>org.activiti</groupId>
			<artifactId>activiti-spring-boot-starter-basic</artifactId>
			<version>5.22.0</version>
			<exclusions>
			     <exclusion>
			        <groupId>org.mybatis</groupId>
				<artifactId>mybatis</artifactId>
			     </exclusion>
			     <exclusion>
          			<groupId>org.activiti</groupId>
          			<artifactId>activiti-engine</artifactId>
          		     </exclusion>
			</exclusions>
		</dependency>

		<dependency>
			<groupId>org.activiti</groupId>
			<artifactId>activiti-spring-boot-starter-jpa</artifactId>
			<version>5.22.0</version>
		</dependency>
	    <dependency>
               <groupId>org.activiti</groupId>
               <artifactId>activiti-engine</artifactId>
               <version>5.3.0</version>
               <exclusions>
		 <exclusion>
		  <groupId>org.mybatis</groupId>
		  <artifactId>mybatis</artifactId>
	         </exclusion>
	       </exclusions>
            </dependency>

  

修改后,支持达梦数据库的activiti-engine-5.22.0.jar以及涉及到的相关资料,下载地址:https://pan.baidu.com/s/1xzBbSTAbkfWRpG0-T-LeOg   提取码:9472 

链接:https://pan.baidu.com/s/1-IITDKJCOhqY1oUbaiSczQ
提取码:1024

posted @ 2022-06-28 10:45  JLCUI  阅读(1216)  评论(0编辑  收藏  举报