编辑
2023-07-17
环境部署
00

目录

前言
一、引入达梦数据库驱动包
二、配置达梦数据源
三、修改camunda代码,支持达梦数据库
1. 修改ProcessEngineConfigurationImpl类的代码
2. 修改DbSqlSessionFactory类代码,并在static代码块增加对达梦数据库的适配:
3. 如果改造源码不方便,则可以在自己的Spring项目中针对该两处源码做重写:

前言

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

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

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

dm.jdbc.driver.DmDriver

jdbc

system

${project.basedir}/src/main/resources/lib/Dm7JdbcDriver18.jar

二、配置达梦数据源

url: jdbc:dm://127.0.0.1:5236

username: oa

password: 12345678aA

driver-class-name: dm.jdbc.driver.DmDriver

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

1. 修改ProcessEngineConfigurationImpl类的代码

java
protected static Properties getDefaultDatabaseTypeMappings() { Properties databaseTypeMappings = new Properties(); databaseTypeMappings.setProperty("H2", "h2"); databaseTypeMappings.setProperty(MY_SQL_PRODUCT_NAME, "mysql"); databaseTypeMappings.setProperty(MARIA_DB_PRODUCT_NAME, "mariadb"); databaseTypeMappings.setProperty("Oracle", "oracle"); databaseTypeMappings.setProperty("PostgreSQL", "postgres"); databaseTypeMappings.setProperty("Microsoft SQL Server", "mssql"); databaseTypeMappings.setProperty("DB2", "db2"); databaseTypeMappings.setProperty("DB2", "db2"); databaseTypeMappings.setProperty("DB2/NT", "db2"); databaseTypeMappings.setProperty("DB2/NT64", "db2"); databaseTypeMappings.setProperty("DB2 UDP", "db2"); databaseTypeMappings.setProperty("DB2/LINUX", "db2"); databaseTypeMappings.setProperty("DB2/LINUX390", "db2"); databaseTypeMappings.setProperty("DB2/LINUXX8664", "db2"); databaseTypeMappings.setProperty("DB2/LINUXZ64", "db2"); databaseTypeMappings.setProperty("DB2/400 SQL", "db2"); databaseTypeMappings.setProperty("DB2/6000", "db2"); databaseTypeMappings.setProperty("DB2 UDB iSeries", "db2"); databaseTypeMappings.setProperty("DB2/AIX64", "db2"); databaseTypeMappings.setProperty("DB2/HPUX", "db2"); databaseTypeMappings.setProperty("DB2/HP64", "db2"); databaseTypeMappings.setProperty("DB2/SUN", "db2"); databaseTypeMappings.setProperty("DB2/SUN64", "db2"); databaseTypeMappings.setProperty("DB2/PTX", "db2"); databaseTypeMappings.setProperty("DB2/2", "db2"); // 适配达梦数据库 databaseTypeMappings.setProperty("DM DBMS", "dm"); return databaseTypeMappings; }

2. 修改DbSqlSessionFactory类代码,并在static代码块增加对达梦数据库的适配:

java
public class DbSqlSessionFactory implements SessionFactory { public static final String MSSQL = "mssql"; public static final String DB2 = "db2"; public static final String ORACLE = "oracle"; public static final String H2 = "h2"; public static final String MYSQL = "mysql"; public static final String POSTGRES = "postgres"; public static final String MARIADB = "mariadb"; // 适配达梦数据库 public static final String DMDBMS = "dm"; // 适配达梦数据库 public static final String[] SUPPORTED_DATABASES = {DMDBMS, MSSQL, DB2, ORACLE, H2, MYSQL, POSTGRES, MARIADB};

static块

java
databaseSpecificLimitBeforeStatements.put(DMDBMS, "select * from ( select a.*, ROWNUM rnum from ("); optimizeDatabaseSpecificLimitBeforeWithoutOffsetStatements.put(DMDBMS, "select * from ( select a.*, ROWNUM rnum from ("); databaseSpecificLimitAfterStatements.put(DMDBMS, " ) a where ROWNUM < #{lastRow}) where rnum >= #{firstRow}"); optimizeDatabaseSpecificLimitAfterWithoutOffsetStatements.put(DMDBMS, " ) a where ROWNUM <= #{maxResults})"); databaseSpecificLimitBeforeWithoutOffsetStatements.put(DMDBMS, ""); databaseSpecificLimitAfterWithoutOffsetStatements.put(DMDBMS, "AND ROWNUM <= #{maxResults}"); databaseSpecificInnerLimitAfterStatements.put(DMDBMS, databaseSpecificLimitAfterStatements.get(DMDBMS)); databaseSpecificLimitBetweenStatements.put(DMDBMS, ""); databaseSpecificLimitBetweenFilterStatements.put(DMDBMS, ""); databaseSpecificLimitBetweenAcquisitionStatements.put(DMDBMS, ""); databaseSpecificOrderByStatements.put(DMDBMS, defaultOrderBy); databaseSpecificLimitBeforeNativeQueryStatements.put(DMDBMS, ""); databaseSpecificDistinct.put(DMDBMS, "distinct"); databaseSpecificNumericCast.put(DMDBMS, ""); databaseSpecificCountDistinctBeforeStart.put(DMDBMS, defaultDistinctCountBeforeStart); databaseSpecificCountDistinctBeforeEnd.put(DMDBMS, defaultDistinctCountBeforeEnd); databaseSpecificCountDistinctAfterEnd.put(DMDBMS, defaultDistinctCountAfterEnd); databaseSpecificEscapeChar.put(DMDBMS, defaultEscapeChar); databaseSpecificDummyTable.put(DMDBMS, "FROM DUAL"); databaseSpecificBitAnd1.put(DMDBMS, "BITAND("); databaseSpecificBitAnd2.put(DMDBMS, ","); databaseSpecificBitAnd3.put(DMDBMS, ")"); databaseSpecificDatepart1.put(DMDBMS, "to_number(to_char("); databaseSpecificDatepart2.put(DMDBMS, ","); databaseSpecificDatepart3.put(DMDBMS, "))"); databaseSpecificTrueConstant.put(DMDBMS, "1"); databaseSpecificFalseConstant.put(DMDBMS, "0"); databaseSpecificIfNull.put(DMDBMS, "NVL"); databaseSpecificDaysComparator.put(DMDBMS, "${date} <= #{currentTimestamp} - ${days}"); databaseSpecificCollationForCaseSensitivity.put(DMDBMS, ""); addDatabaseSpecificStatement(DMDBMS, "selectHistoricProcessInstanceDurationReport", "selectHistoricProcessInstanceDurationReport_oracle"); addDatabaseSpecificStatement(DMDBMS, "selectHistoricTaskInstanceDurationReport", "selectHistoricTaskInstanceDurationReport_oracle"); addDatabaseSpecificStatement(DMDBMS, "selectHistoricTaskInstanceCountByTaskNameReport", "selectHistoricTaskInstanceCountByTaskNameReport_oracle"); addDatabaseSpecificStatement(DMDBMS, "selectFilterByQueryCriteria", "selectFilterByQueryCriteria_oracleDb2"); addDatabaseSpecificStatement(DMDBMS, "selectHistoricProcessInstanceIdsForCleanup", "selectHistoricProcessInstanceIdsForCleanup_oracle"); addDatabaseSpecificStatement(DMDBMS, "selectHistoricDecisionInstanceIdsForCleanup", "selectHistoricDecisionInstanceIdsForCleanup_oracle"); addDatabaseSpecificStatement(DMDBMS, "selectHistoricCaseInstanceIdsForCleanup", "selectHistoricCaseInstanceIdsForCleanup_oracle"); addDatabaseSpecificStatement(DMDBMS, "selectHistoricBatchIdsForCleanup", "selectHistoricBatchIdsForCleanup_oracle"); addDatabaseSpecificStatement(DMDBMS, "deleteAttachmentsByRemovalTime", "deleteAttachmentsByRemovalTime_oracle"); addDatabaseSpecificStatement(DMDBMS, "deleteCommentsByRemovalTime", "deleteCommentsByRemovalTime_oracle"); addDatabaseSpecificStatement(DMDBMS, "deleteHistoricActivityInstancesByRemovalTime", "deleteHistoricActivityInstancesByRemovalTime_oracle"); addDatabaseSpecificStatement(DMDBMS, "deleteHistoricDecisionInputInstancesByRemovalTime", "deleteHistoricDecisionInputInstancesByRemovalTime_oracle"); addDatabaseSpecificStatement(DMDBMS, "deleteHistoricDecisionInstancesByRemovalTime", "deleteHistoricDecisionInstancesByRemovalTime_oracle"); addDatabaseSpecificStatement(DMDBMS, "deleteHistoricDecisionOutputInstancesByRemovalTime", "deleteHistoricDecisionOutputInstancesByRemovalTime_oracle"); addDatabaseSpecificStatement(DMDBMS, "deleteHistoricDetailsByRemovalTime", "deleteHistoricDetailsByRemovalTime_oracle"); addDatabaseSpecificStatement(DMDBMS, "deleteExternalTaskLogByRemovalTime", "deleteExternalTaskLogByRemovalTime_oracle"); addDatabaseSpecificStatement(DMDBMS, "deleteHistoricIdentityLinkLogByRemovalTime", "deleteHistoricIdentityLinkLogByRemovalTime_oracle"); addDatabaseSpecificStatement(DMDBMS, "deleteHistoricIncidentsByRemovalTime", "deleteHistoricIncidentsByRemovalTime_oracle"); addDatabaseSpecificStatement(DMDBMS, "deleteJobLogByRemovalTime", "deleteJobLogByRemovalTime_oracle"); addDatabaseSpecificStatement(DMDBMS, "deleteHistoricProcessInstancesByRemovalTime", "deleteHistoricProcessInstancesByRemovalTime_oracle"); addDatabaseSpecificStatement(DMDBMS, "deleteHistoricTaskInstancesByRemovalTime", "deleteHistoricTaskInstancesByRemovalTime_oracle"); addDatabaseSpecificStatement(DMDBMS, "deleteHistoricVariableInstancesByRemovalTime", "deleteHistoricVariableInstancesByRemovalTime_oracle"); addDatabaseSpecificStatement(DMDBMS, "deleteUserOperationLogByRemovalTime", "deleteUserOperationLogByRemovalTime_oracle"); addDatabaseSpecificStatement(DMDBMS, "deleteByteArraysByRemovalTime", "deleteByteArraysByRemovalTime_oracle"); addDatabaseSpecificStatement(DMDBMS, "deleteHistoricBatchesByRemovalTime", "deleteHistoricBatchesByRemovalTime_oracle"); constants = new HashMap<String, String>(); constants.put("constant.event", "cast('event' as nvarchar2(255))"); constants.put("constant.op_message", "NEW_VALUE_ || '_|_' || PROPERTY_"); constants.put("constant_for_update", "for update"); constants.put("constant.datepart.quarter", "'Q'"); constants.put("constant.datepart.month", "'MM'"); constants.put("constant.datepart.minute", "'MI'"); constants.put("constant.null.startTime", "null START_TIME_"); constants.put("constant.varchar.cast", "'${key}'"); constants.put("constant.integer.cast", "NULL"); constants.put("constant.null.reporter", "NULL AS REPORTER_"); dbSpecificConstants.put(DMDBMS, constants);

3. 如果改造源码不方便,则可以在自己的Spring项目中针对该两处源码做重写:

如果对你有用的话,可以打赏哦
打赏
ali pay
wechat pay

本文作者:Golovin

本文链接:

版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!