当前位置: 首页 > 工具软件 > Oscar > 使用案例 >

Activiti6.0扩展支持OSCAR神通数据库

文心思
2023-12-01

前言

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

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

原因是:activiti6.0.0内置的数据库类型不支持神通数据库.

解决方案

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

具体如下:

  1. 在org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl,增加成员变量
public static final String DATABASE_TYPE_OSCAR = "oscar";
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";
  1. 在org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl,修改getDefaultDatabaseTypeMappings()
protected static Properties getDefaultDatabaseTypeMappings() {
    Properties databaseTypeMappings = new Properties();
    databaseTypeMappings.setProperty("OSCAR ", DATABASE_TYPE_OSCAR );
    databaseTypeMappings.setProperty("H2", DATABASE_TYPE_H2);

  1. 在org.activiti.engine.impl.db.DbSqlSessionFactory,修改initBulkInsertEnabledMap(String databaseType)
if ("oracle".equals(databaseType) || "oscar".equals(databaseType)) {
    bulkInsertableMap.put(EventLogEntryEntity.class, Boolean.FALSE);
}
  1. 在org.activiti.db.properties路径下新建 oscar.properties
limitBefore=
limitAfter=LIMIT #{maxResults} OFFSET #{firstResult}
  1. 在 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_OSCAR.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_OSCAR.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-6.0.0.jar启动即可。

亲测好用!

记录始于生活,有帮助就点个赞吧!

 类似资料: