起因
工作流基本环境的搭建在此就不做过多的赘述了,在达梦的官微也介绍了如何在activiti上如何结合,但是结合的方式过于死板,如果想通过xml来配置使用何种数据库,正好你又看到了这篇文章,那么可能会节省你半天的时间。
注意,这里所有从jar包中copy出来的源码,仍然需要放在一个新建的重复路径下,方便编译的时候覆盖jar中的class文件
首先
org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl这个类,从它的jar包中copy出来,然后在
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";
下面加上要支持的数据库简称,方便在xml中配置datasourceType
public static final String DATABASE_TYPE_DM = "dm";
当然还得继续在getDefaultDatabaseTypeMappings()方法中加上如下这句话:
databaseTypeMappings.setProperty("dm", DATABASE_TYPE_DM);
接着
接下来,这些配好了,如何映射sql文件呢,请看org.activiti.engine.impl.db.DbSqlSessionFactory类中的initBulkInsertEnabledMap(String databaseType)方法,发现下面有
// Only Oracle is making a fuss in one specific case right now
if ("oracle".equals(databaseType)) {
bulkInsertableMap.put(EventLogEntryEntityImpl.class, Boolean.FALSE);
}
这样一句代码,而且还标识是oracle独有的,由于我适配的是达梦,所以在这里修改为
if ("oracle".equals(databaseType) || "dm".equals(databaseType)) {
bulkInsertableMap.put(EventLogEntryEntityImpl.class, Boolean.FALSE);
}
还有
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)) {
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)) {
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;
}
}
修改为
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;
}
}
接下来
接下来需要把sql建表脚本放好,由于我是web项目,放置于resources的org.activiti.db下,按照acitivit-engine包下的结构放置,原因是这句话:
properties.load(getResourceAsStream("org/activiti/db/properties/"+databaseType+".properties"));
找不到会报空指针异常。
如果
如果发生noSuchMethod的异常,要记住把org.activiti.engine.impl.ProcessEngineImpl沾出来一份,重新给它写一下
this.formEngineFormService = processEngineConfiguration.getFormEngineFormService();
这句话,可能会报错,修改为
this.formEngineFormService = (org.activiti.form.api.FormService) processEngineConfiguration.getFormEngineFormService();
至此,拓展完毕,如果有其他国产数据库拓展经验的小伙伴可以给我留言哦,不胜感激。