flowable如何适配国产数据库达梦

 

前言

flowable6.4.1流程引擎官方支持的数据库有:MySQL、hsql、Oracle、DB2 、postgres、SQL Server、H2。对于其他类型的数据库如何支持,尤其是国产数据库的支持,下面以达梦数据库为例进行介绍。对于其他国产数据库如人大金仓、神州通用等也是同样的修改方法,只是需要注意一下对应数据库的方言即可。

一、引入达梦数据库驱动包

在maven工程的Resources目录下建lib目录,放入达梦数据库驱动包Dm7JdbcDriver17.jar,并配置maven为本地引用

dm.jdbc.driver.DmDriver
jdbc
system
${project.basedir}/src/main/resources/lib/Dm7JdbcDriver17.jar

二、配置达梦数据源

url: jdbc:dm://127.0.0.1:5236
username: oa
password: 12345678aA
driver-class-name: dm.jdbc.driver.DmDriver

三、修改flowable代码,支持达梦数据库

1. 修改ProcessEngineConfigurationImpl类的代码

修改org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl类的getDefaultDatabaseTypeMappings方法。

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";
    public static final String DATABASE_TYPE_POSTGRES = "postgres";
    public static final String DATABASE_TYPE_MSSQL = "mssql";
    public static final String DATABASE_TYPE_DB2 = "db2";
 	public static final String DATABASE_TYPE_DM = "dm"; //达梦
 
    protected static Properties getDefaultDatabaseTypeMappings() {
   
        Properties databaseTypeMappings = new Properties();
        databaseTypeMappings.setProperty("H2", DATABASE_TYPE_H2);
        databaseTypeMappings.setProperty("HSQL Database Engine", DATABASE_TYPE_HSQL);
        databaseTypeMappings.setProperty("MySQL", DATABASE_TYPE_MYSQL);
        databaseTypeMappings.setProperty("Oracle", DATABASE_TYPE_ORACLE);
        databaseTypeMappings.setProperty("PostgreSQL", DATABASE_TYPE_POSTGRES);
        databaseTypeMappings.setProperty("Microsoft SQL Server", DATABASE_TYPE_MSSQL);
        databaseTypeMappings.setProperty(DATABASE_TYPE_DB2, DATABASE_TYPE_DB2);
        databaseTypeMappings.setProperty("DB2", DATABASE_TYPE_DB2);
        databaseTypeMappings.setProperty("DB2/NT", DATABASE_TYPE_DB2);
        databaseTypeMappings.setProperty("DB2/NT64", DATABASE_TYPE_DB2);
        databaseTypeMappings.setProperty("DB2 UDP", DATABASE_TYPE_DB2);
        databaseTypeMappings.setProperty("DB2/LINUX", DATABASE_TYPE_DB2);
        databaseTypeMappings.setProperty("DB2/LINUX390", DATABASE_TYPE_DB2);
        databaseTypeMappings.setProperty("DB2/LINUXX8664", DATABASE_TYPE_DB2);
        databaseTypeMappings.setProperty("DB2/LINUXZ64", DATABASE_TYPE_DB2);
        databaseTypeMappings.setProperty("DB2/LINUXPPC64", DATABASE_TYPE_DB2);
        databaseTypeMappings.setProperty("DB2/LINUXPPC64LE", DATABASE_TYPE_DB2);
        databaseTypeMappings.setProperty("DB2/400 SQL", DATABASE_TYPE_DB2);
        databaseTypeMappings.setProperty("DB2/6000", DATABASE_TYPE_DB2);
        databaseTypeMappings.setProperty("DB2 UDB iSeries", DATABASE_TYPE_DB2);
        databaseTypeMappings.setProperty("DB2/AIX64", DATABASE_TYPE_DB2);
        databaseTypeMappings.setProperty("DB2/HPUX", DATABASE_TYPE_DB2);
        databaseTypeMappings.setProperty("DB2/HP64", DATABASE_TYPE_DB2);
        databaseTypeMappings.setProperty("DB2/SUN", DATABASE_TYPE_DB2);
        databaseTypeMappings.setProperty("DB2/SUN64", DATABASE_TYPE_DB2);
        databaseTypeMappings.setProperty("DB2/PTX", DATABASE_TYPE_DB2);
        databaseTypeMappings.setProperty("DB2/2", DATABASE_TYPE_DB2);
        databaseTypeMappings.setProperty("DB2 UDB AS400", DATABASE_TYPE_DB2);
        databaseTypeMappings.setProperty("DM DBMS", DATABASE_TYPE_DM); //达梦
        
        return databaseTypeMappings;
    }

2. 修改DbSqlSessionFactory类代码

org.activiti.engine.impl.db.DbSqlSessionFactory类里增加对达梦数据库的语法解析,在static方法里增加:

// dm
        databaseSpecificLimitBeforeStatements.put("dm", "select * from ( select a.*, ROWNUM rnum from (");
        databaseSpecificLimitAfterStatements.put("dm", " ) a where ROWNUM < #{lastRow}) where rnum >= #{firstRow}");
        databaseSpecificLimitBetweenStatements.put("dm", "");
        databaseOuterJoinLimitBetweenStatements.put("dm", "");
        databaseSpecificOrderByStatements.put("dm", defaultOrderBy);
        addDatabaseSpecificStatement("dm", "selectExclusiveJobsToExecute", "selectExclusiveJobsToExecute_integerBoolean");
        addDatabaseSpecificStatement("dm", "selectUnlockedTimersByDuedate", "selectUnlockedTimersByDuedate_oracle");
        addDatabaseSpecificStatement("dm", "insertEventLogEntry", "insertEventLogEntry_oracle");
        addDatabaseSpecificStatement("dm", "bulkInsertVariableInstance", "bulkInsertVariableInstance_oracle");
        addDatabaseSpecificStatement("dm", "bulkInsertTask", "bulkInsertTask_oracle");
        addDatabaseSpecificStatement("dm", "bulkInsertResource", "bulkInsertResource_oracle");
        addDatabaseSpecificStatement("dm", "bulkInsertProperty", "bulkInsertProperty_oracle");
        addDatabaseSpecificStatement("dm", "bulkInsertProcessDefinition", "bulkInsertProcessDefinition_oracle");
        addDatabaseSpecificStatement("dm", "bulkInsertModel", "bulkInsertModel_oracle");
        addDatabaseSpecificStatement("dm", "bulkInsertTimer", "bulkInsertTimer_oracle");
        addDatabaseSpecificStatement("dm", "bulkInsertMessage", "bulkInsertMessage_oracle");
        addDatabaseSpecificStatement("dm", "bulkInsertIdentityLink", "bulkInsertIdentityLink_oracle");
        addDatabaseSpecificStatement("dm", "bulkInsertHistoricVariableInstance", "bulkInsertHistoricVariableInstance_oracle");
        addDatabaseSpecificStatement("dm", "bulkInsertHistoricTaskInstance", "bulkInsertHistoricTaskInstance_oracle");
        addDatabaseSpecificStatement("dm", "bulkInsertHistoricProcessInstance", "bulkInsertHistoricProcessInstance_oracle");
        addDatabaseSpecificStatement("dm", "bulkInsertHistoricIdentityLink", "bulkInsertHistoricIdentityLink_oracle");
        addDatabaseSpecificStatement("dm", "bulkInsertHistoricDetailVariableInstanceUpdate", "bulkInsertHistoricDetailVariableInstanceUpdate_oracle");
        addDatabaseSpecificStatement("dm", "bulkInsertHistoricFormProperty", "bulkInsertHistoricFormProperty_oracle");
        addDatabaseSpecificStatement("dm", "bulkInsertHistoricActivityInstance", "bulkInsertHistoricActivityInstance_oracle");
        addDatabaseSpecificStatement("dm", "bulkInsertExecution", "bulkInsertExecution_oracle");
        addDatabaseSpecificStatement("dm", "bulkInsertMessageEventSubscription", "bulkInsertMessageEventSubscription_oracle");
        addDatabaseSpecificStatement("dm", "bulkInsertSignalEventSubscription", "bulkInsertSignalEventSubscription_oracle");
        addDatabaseSpecificStatement("dm", "bulkInsertCompensateEventSubscription", "bulkInsertCompensateEventSubscription_oracle");
        addDatabaseSpecificStatement("dm", "bulkInsertEventLogEntry", "bulkInsertEventLogEntry_oracle");
        addDatabaseSpecificStatement("dm", "bulkInsertDeployment", "bulkInsertDeployment_oracle");
        addDatabaseSpecificStatement("dm", "bulkInsertComment", "bulkInsertComment_oracle");
        addDatabaseSpecificStatement("dm", "bulkInsertByteArray", "bulkInsertByteArray_oracle");
        addDatabaseSpecificStatement("dm", "bulkInsertEventLogEntry", "bulkInsertEventLogEntry_oracle");
        addDatabaseSpecificStatement("dm", "bulkInsertDeployment", "bulkInsertDeployment_oracle");
        addDatabaseSpecificStatement("dm", "bulkInsertComment", "bulkInsertComment_oracle");
        addDatabaseSpecificStatement("dm", "bulkInsertAttachment", "bulkInsertAttachment_oracle");
        addDatabaseSpecificStatement("dm", "bulkInsertJob", "bulkInsertJob_oracle");
        addDatabaseSpecificStatement("dm", "bulkInsertTimerJob", "bulkInsertTimerJob_oracle");
        addDatabaseSpecificStatement("dm", "bulkInsertSuspendedJob", "bulkInsertSuspendedJob_oracle");
        addDatabaseSpecificStatement("dm", "bulkInsertDeadLetterJob", "bulkInsertDeadLetterJob_oracle");

四、推荐选型

笔者从事工作流研发多年,用过osworkflow、jbpm、activiti、flowable、camunda等多个开源流程引擎,后来遇到了camunda,经过功能和性能验证测试,最终选择了camunda。

posted @ 2021-06-21 12:55  大龄码农有梦想  阅读(3733)  评论(1编辑  收藏  举报