Activiti5.22.0扩展支持达国产数据库,以GBase据库为例
Activiti5.22.0扩展支持达GBase据库
前言
目前国内部分公司做的项目要求去ioe使用国产的替代方案。数据从异构数据库中迁移到GBase,应用中使用Activiti工作流在替换了数据库驱动后启动过程报错如下:
nested exception is org.activiti.engine.ActivitiException: couldn’t deduct database type from database product name ‘Gbase 8s Server’
原因是:activiti5.22.0内置的数据库类型不支持GBase数据库。
解决方案
将activiti-engine-5.22.0相关源码拷贝到工程src下,保持包路径不变,并做相应修改以支持达梦数据库。
源码地址:https://github.com/Activiti/Activiti/tree/activiti-5.22.0/modules/activiti-engine
具体如下:
1.新建与源文件一模一样的类,包路径也要与源文件一样
,新建org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl的源码内容全部复制过来,然后增加成员变量
此时会报错,因为缺少依赖,然后去github把他的pom文件拷贝过来,放到本项目下面。
https://github.com/Activiti/Activiti/tree/activiti-5.22.0/modules/activiti-engine
在刚刚拷贝的org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl,增加成员变量
public static final String DATABASE_TYPE_GBASE = "gbase";
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(“GBase 8s Server”, DATABASE_TYPE_GBASE);
databaseTypeMappings.setProperty(“H2”, DATABASE_TYPE_H2);
3. 在新建org.activiti.engine.impl.db.DbSqlSessionFactory,把源文件内容拷贝过来,然后修改initBulkInsertEnabledMap(String databaseType)
if (“oracle”.equals(databaseType) || “gbase”.equals(databaseType)) {
bulkInsertableMap.put(EventLogEntryEntity.class, Boolean.FALSE); }
4.在org.activiti.engine.impl.db.DbSqlSessionFactory,修改static{}
// gbase
databaseSpecificLimitBeforeStatements.put("gbase ", “”);
databaseSpecificLimitAfterStatements.put("gbase ", “LIMIT #{maxResults}
OFFSET #{firstResult}”);
databaseSpecificLimitBetweenStatements.put("gbase ", “”);
databaseOuterJoinLimitBetweenStatements.put("gbase ", “”);
databaseSpecificOrderByStatements.put("gbase ", 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_GBASE.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_GBASE.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;
}
}
6.右击项目,选择构建模块
7. 构建成功就会在target目录下面生成class文件,然后去jar包里面替换即可。
更多推荐
所有评论(0)