一、 修改jdbc连接达梦数据库
1.修改pom文件引入达梦驱动包和方言包(可在达梦安装目录中找到)
2.修改连接jdbc相关配置文件(此处略)
二、修改activiti-engine-6.0.0.jar中源码
1.上面设置完成后尝试启动项目,报错信息如下:
Caused by: org.activiti.engine.ActivitiException: couldn't deduct database type from database product name 'DM DBMS'
2.activiti并不认识国产数据库,需要修改文件:
在项目中创建org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl文件(这边路径必须一致,打包时会覆盖源文件),拷贝源代码后,添加DATABASE_TYPE_DM(我的在920行添加):
public static final String DATABASE_TYPE_DM = "dm"; // 适配达梦数据库,追加成员变量
修改getDefaultDatabaseTypeMappings方法,添加DM DBMS。
databaseTypeMappings.setProperty("DM DBMS", DATABASE_TYPE_DM); // 适配达梦数据库
3.修改org.activiti.engine.impl.db.DbSqlSessionFactory文件,拷贝源代码后,修改initBulkInsertEnabledMap方法。
protected void initBulkInsertEnabledMap(String databaseType) {
bulkInsertableMap = new HashMap();
Iterator var2 = EntityDependencyOrder.INSERT_ORDER.iterator();
while(var2.hasNext()) {
Class<? extends Entity> clazz = (Class)var2.next();
bulkInsertableMap.put(clazz, Boolean.TRUE);
}
// 适配达梦数据库
if ("oracle".equals(databaseType) || "dm".equals(databaseType)) {
bulkInsertableMap.put(EventLogEntryEntityImpl.class, Boolean.FALSE);
}
}
4.修改org.activiti.engine.impl.AbstractQuery 类的 addOrder方法。
protected void addOrder(String column, String sortOrder, NullHandlingOnOrder nullHandlingOnOrder) {
if (orderBy == null) {
orderBy = "";
} else {
orderBy = orderBy + ", ";
}
String defaultOrderByClause = column + " " + sortOrder;
if (nullHandlingOnOrder != null) {
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;
}
}
} else {
orderBy = orderBy + defaultOrderByClause;
}
}
5.将以上修改的文件进行编译,将编译后的class文件替换activiti-engine-6.0.0.jar中相应class文件。
三、添加dm.properties,可复制oracle.properties一份,改成dm.properties。
将项目编译后重新运行即可。