Activiti兼容达梦数据库

1. 自定义类继承SpringProcessEngineConfiguration类,重写initDatabaseType方法。
package com.ydtf.cbda.module.cbdacim.improcess.config;

import org.activiti.engine.ActivitiException;
import org.activiti.spring.SpringProcessEngineConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;

/**
 * @author 自定义activiti的数据库连接
 * @date 2023/9/14 14:31
 */
public class CustomConnectionSpringProcessEngineConfiguration extends SpringProcessEngineConfiguration {
    private static Logger log = LoggerFactory.getLogger(CustomConnectionSpringProcessEngineConfiguration.class);
    @Override
    public void initDatabaseType() {
        Connection connection = null;

        try {
            connection = this.dataSource.getConnection();
            DatabaseMetaData databaseMetaData = connection.getMetaData();
            String databaseProductName = databaseMetaData.getDatabaseProductName();
            log.debug("database product name: '{}'", databaseProductName);
            this.databaseType = databaseTypeMappings.getProperty(databaseProductName);
            if (databaseProductName.contains("DM DBMS")) {
                databaseProductName = "Oracle";
            }
            databaseType = databaseTypeMappings.getProperty(databaseProductName);
            if (this.databaseType == null) {
                throw new ActivitiException("couldn't deduct database type from database product name '" + databaseProductName + "'");
            }

            log.debug("using database type: {}", this.databaseType);
            if ("mssql".equals(this.databaseType)) {
                this.maxNrOfStatementsInBulkInsert = this.DEFAULT_MAX_NR_OF_STATEMENTS_BULK_INSERT_SQL_SERVER;
            }
        } catch (SQLException var12) {
            log.error("Exception while initializing Database connection", var12);
        } finally {
            try {
                if (connection != null) {
                    connection.close();
                }
            } catch (SQLException var11) {
                log.error("Exception while closing the Database connection", var11);
            }

        }

    }
}
2.  修改Activiti启动项配置
package com.ydtf.cbda.module.cbdacim.improcess.config;

import org.activiti.spring.SpringProcessEngineConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.transaction.PlatformTransactionManager;

import javax.sql.DataSource;

/**
 * @author 修改activiti启动配置项
 * @date 2023/9/14 14:38
 */
@Configuration
public class ActivitiConfigguration {
    @Autowired
    private DataSource dataSource;
    @Autowired
    private PlatformTransactionManager transactionManager;

    @Bean
    public SpringProcessEngineConfiguration getProcessEngineConfiguration() {
        SpringProcessEngineConfiguration configuration = new CustomConnectionSpringProcessEngineConfiguration();

        configuration.setDataSource(dataSource);
        configuration.setTransactionManager(transactionManager);
        configuration.setDatabaseSchemaUpdate("true");
        return configuration;
    }

    @Bean
    @Primary
    public TaskExecutor primaryTaskExecutor(){
        return new ThreadPoolTaskExecutor();
    }
}

你可能感兴趣的:(数据库,达梦,Activiti)