前言
目前国内部分公司做的项目要求去ioe使用国产的替代方案。数据从异构数据库中迁移到达梦,应用中使用Activiti工作流在替换了数据库驱动后启动过程报错如下:
nested exception is org.activiti.engine.ActivitiException: couldn't deduct database type from database product name 'DM DBMS'
原因是:activiti5.22.0内置的数据库类型不支持达梦数据库。
解决方案
将activiti-engine-5.22.0相关源码拷贝到工程src下,保持包路径不变,并做相应修改以支持达梦数据库。
具体如下:
1. 在org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl,增加成员变量
public static final String DATABASE_TYPE_DM = "dm";
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";
2. 在org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl,修改getDefaultDatabaseTypeMappings()
protected static Properties getDefaultDatabaseTypeMappings() {
Properties databaseTypeMappings = new Properties();
databaseTypeMappings.setProperty("DM DBMS", DATABASE_TYPE_DM);
databaseTypeMappings.setProperty("H2", DATABASE_TYPE_H2);
3. 在org.activiti.engine.impl.db.DbSqlSessionFactory,修改initBulkInsertEnabledMap(String databaseType)
if ("oracle".equals(databaseType) || "dm".equals(databaseType)) {
bulkInsertableMap.put(EventLogEntryEntity.class, Boolean.FALSE);
}
4. 在org.activiti.engine.impl.db.DbSqlSessionFactory,修改static{}
// dm
databaseSpecificLimitBeforeStatements.put("dm", "");
databaseSpecificLimitAfterStatements.put("dm", "LIMIT #{maxResults} OFFSET #{firstResult}");
databaseSpecificLimitBetweenStatements.put("dm", "");
databaseOuterJoinLimitBetweenStatements.put("dm", "");
databaseSpecificOrderByStatements.put("dm", defaultOrderBy);// h2
databaseSpecificLimitBeforeStatements.put("h2", "");
databaseSpecificLimitAfterStatements.put("h2", "LIMIT #{maxResults} OFFSET #{firstResult}");
databaseSpecificLimitBetweenStatements.put("h2", "");
databaseOuterJoinLimitBetweenStatements.put("h2", "");
databaseSpecificOrderByStatements.put("h2", defaultOrderBy);
5. 在 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_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;
}
}
完成以上修改,重新编译activiti-engine-5.22.0.jar启动即可。
修改后,支持达梦数据库的activiti-engine-5.22.0.jar下载地址:https://pan.baidu.com/s/1xzBbSTAbkfWRpG0-T-LeOg 提取码:9472
来源:oschina
链接:https://my.oschina.net/u/4417309/blog/4504737