1. 程式人生 > 其它 >flowable如何適配國產資料庫達夢

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。