activiti兼容达梦数据库

前言

由于达梦兼容oracle,因此兼容达梦数据库,本质上就是让应用识别到是达梦数据库后,将它当作oracle对待即可,本文中activiti版本为5.X

定义数据库类型枚举

public enum MyDbConfig {
    /**
     * 达梦数据库(兼容oracle)
     */
    DM("dm", "DM DBMS", "oracle");
    /**
     * 数据库类型名称
     */
    private String dbTypeName;
    /**
     * 数据库产品名称
     */
    private String dbProductName;
    /**
     * 兼容数据库类型名称
     */
    private String compatibleDbTypeName;

    public String getDbProductName() {
        return dbProductName;
    }

    public String getDbTypeName() {
        return dbTypeName;
    }

    public String getCompatibleDbTypeName() {
        return compatibleDbTypeName;
    }

    MyDbConfig(String dbTypeName, String dbProductName, String compatibleDbTypeName) {
        this.dbTypeName = dbTypeName;
        this.dbProductName = dbProductName;
        this.compatibleDbTypeName = compatibleDbTypeName;
    }
}

初始化达梦配置类

import org.activiti.engine.impl.db.DbSqlSessionFactory;

import java.util.Properties;

public class InitDmConfig {
    /**
     * 初始化达梦数据库配置(因其声称兼容oracle,故参照oracle的配置来加)
     * 

* org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl#databaseTypeMappings * ProcessEngineConfigurationImpl#getDefaultDatabaseTypeMappings() *

* * @param databaseTypeMappings 数据库类型映射 * @see org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl * @see org.activiti.engine.impl.db.DbSqlSessionFactory */
public static void init(Properties databaseTypeMappings) { MyDbConfig value = MyDbConfig.DM; databaseTypeMappings.setProperty(value.getDbProductName(), value.getDbTypeName()); DbSqlSessionFactory.databaseSpecificLimitBeforeStatements.put(value.getDbTypeName(), DbSqlSessionFactory.databaseSpecificLimitBeforeStatements.get(value.getCompatibleDbTypeName())); DbSqlSessionFactory.databaseSpecificLimitAfterStatements.put(value.getDbTypeName(), DbSqlSessionFactory.databaseSpecificLimitAfterStatements.get(value.getCompatibleDbTypeName())); DbSqlSessionFactory.databaseSpecificLimitBetweenStatements.put(value.getDbTypeName(), DbSqlSessionFactory.databaseSpecificLimitBetweenStatements.get(value.getCompatibleDbTypeName())); DbSqlSessionFactory.databaseSpecificOrderByStatements.put(value.getDbTypeName(), DbSqlSessionFactory.databaseSpecificOrderByStatements.get(value.getCompatibleDbTypeName())); DbSqlSessionFactory.databaseOuterJoinLimitBetweenStatements.put(value.getDbTypeName(), DbSqlSessionFactory.databaseOuterJoinLimitBetweenStatements.get(value.getCompatibleDbTypeName())); } }

注意,上文类的参数databaseTypeMappingsorg.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl#getDefaultDatabaseTypeMappings()的返回值对应,即类ProcessEngineConfigurationImpldatabaseTypeMappings属性,目的就是向该配置中添加达梦相关配置

调用达梦初始化配置类

activiti提供了抽象类ProcessEngineConfigurationImpl来让用户自定义相关配置,并提供了四个实现类JtaProcessEngineConfiguration, SpringProcessEngineConfiguration, StandaloneInMemProcessEngineConfiguration, StandaloneProcessEngineConfiguration,若要执行初始化达梦配置的方法,可重写类ProcessEngineConfigurationImpl中的buildProcessEngine方法,在流程引擎构建时完成,如下

public class MyProcessEngineConfigurationImpl extends SpringProcessEngineConfiguration {
    @Override
    public ProcessEngine buildProcessEngine() {
        // 初始化达梦配置
        InitDmConfig.init(databaseTypeMappings);

        return super.buildProcessEngine();
    }
}

在定义activiti引擎配置类的bean时,指定为我们重写的这个类即可

你可能感兴趣的:(java,java)