转自:https://blog.csdn.net/qq_42505088/article/details/108196487
flowable兼容国产金仓数据库
1、新增jar包的sql脚本
(flowable框架不支持金仓数据库,需要手动插入sql脚本)
需要修改的几个jar包脚本
- 因为金仓数据库语法类似oracle,赋值在org/flowable/db/create中,复制该jar包中的orcale脚本(脚本名称格式:flowable.oracle.create.XXX.sql)为新文件,并修改成文件名为:flowable.数据库类型.create.XXX.sql(如,金仓脚本名称格式:flowable.kingbase.create.XXX.sql),如下图:
注:修改脚本中的*为30,金仓不支持语法
2.把flowable.kingbase.create.XXX.sql按照本来的包名格式的样列复制到flowable的工作目录中去
如图:
2、修改源码
1、修改源码org.flowable.common.engine.impl.AbstractEngineConfiguration
(1)在maven仓库下打开org\flowable\flowable-engine-common\6.4.2,找到flowable-engine-common-6.4.2-sources.jar文件,用解压工具打开。
(2)在jar包中打开org\flowable\common\engine\impl\目录找到AbstractEngineConfiguration.java,在编辑器下根据该java文件的package创建相同的包名,并将其复制到我们自己实现的工程(flowengine)相同包名下,进行修改,插入以下两行
public static final String DATABASE_TYPE_KINGBASE = "kingbase";
public static Properties getDefaultDatabaseTypeMappings() {
databaseTypeMappings.setProperty("KingbaseES", DATABASE_TYPE_KINGBASE);
- 1
- 2
- 3
2、修改源码DatabaseConfiguration.java
(1)在maven仓库下打开org\flowable\flowable-ui-modeler-conf\6.4.2,找到flowable-ui-modeler-conf-6.4.2-sources.jar文件,用压缩包打开。
(2)在jar包中打开org\flowable\ui\modeler\conf目录找到DatabaseConfiguration.java,在编辑器下根据该java文件的package创建相同的包名,并将其复制到我们自己实现的工程(flowengine)相同包名下进行修改。
//添加金仓数据库
public static final String DATABASE_TYPE_KINGBASE = "kingbase";
public static Properties getDefaultDatabaseTypeMappings() {
databaseTypeMappings.setProperty("KingbaseES", DATABASE_TYPE_KINGBASE);
}
//修改liquibase的bean方法
@Bean
public Liquibase liquibase(DataSource dataSource) {
LOGGER.info("Configuring Liquibase");
Liquibase liquibase = null;
try {
DatabaseConnection connection = new JdbcConnection(dataSource.getConnection());
Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(connection);
database.setDatabaseChangeLogTableName(LIQUIBASE_CHANGELOG_PREFIX + database.getDatabaseChangeLogTableName());
database.setDatabaseChangeLogLockTableName(LIQUIBASE_CHANGELOG_PREFIX + database.getDatabaseChangeLogLockTableName());
String defaultSchemaName=env.getProperty("spring.jpa.properties.hibernate.default_schema");
if(defaultSchemaName!=null&&!defaultSchemaName.equals("")){
database.setDefaultSchemaName(defaultSchemaName);
database.setLiquibaseSchemaName(defaultSchemaName);
}
liquibase = new Liquibase("META-INF/liquibase/flowable-modeler-app-db-changelog.xml", new ClassLoaderResourceAccessor(), database);
liquibase.update("flowable");
return liquibase;
} catch (Exception e) {
throw new InternalServerErrorException("Error creating liquibase database", e);
} finally {
closeDatabase(liquibase);
}
}
3、复制修改ProcessEngineConfigurationImpl.java源码
(1)在maven仓库下打开org\flowable\flowable5-engine\6.4.2,找到flowable5-engine-6.4.2-sources.jar文件,用压缩包打开。
(2)在jar包中打开org\activiti\engine\impl\cfg\目录找到ProcessEngineConfigurationImpl.java,在编辑器下根据该java文件的package创建相同的包名,并将其复制到我们自己实现的工程(flowengine)相同包名下进行添加修改。
//添加金仓数据库
public static final String DATABASE_TYPE_KINGBASE = "kingbase";
public static Properties getDefaultDatabaseTypeMappings() {
databaseTypeMappings.setProperty("KingbaseES", DATABASE_TYPE_KINGBASE);
}
4、复制修改DbSqlSessionFactory.java源码
(1)在maven仓库下打开org\flowable\flowable5-engine\6.4.2,找到flowable5-engine-6.4.2-sources.jar文件,用压缩包打开。
(2)在jar包中打开org\activiti\engine\impl\db\目录找到DbSqlSessionFactory.java,在编辑器下根据改java文件的包package创建相同的包名,并将其复制到我们自己实现的工程(flowengine)相同包名下进行修改。
在静态代码中加上
static{
// kingbase
databaseSpecificLimitBeforeStatements.put("kingbase", "select * from ( select a.*, ROWNUM rnum from (");
databaseSpecificLimitAfterStatements.put("kingbase", " ) a where ROWNUM < #{lastRow}) where rnum >= #{firstRow}");
databaseSpecificLimitBetweenStatements.put("kingbase", "");
databaseOuterJoinLimitBetweenStatements.put("kingbase", "");
databaseSpecificOrderByStatements.put("kingbase", defaultOrderBy);
addDatabaseSpecificStatement("kingbase", "selectExclusiveJobsToExecute", "selectExclusiveJobsToExecute_integerBoolean");
addDatabaseSpecificStatement("kingbase", "selectUnlockedTimersByDuedate", "selectUnlockedTimersByDuedate_oracle");
addDatabaseSpecificStatement("kingbase", "insertEventLogEntry", "insertEventLogEntry_oracle");
addDatabaseSpecificStatement("kingbase", "bulkInsertVariableInstance", "bulkInsertVariableInstance_oracle");
addDatabaseSpecificStatement("kingbase", "bulkInsertTask", "bulkInsertTask_oracle");
addDatabaseSpecificStatement("kingbase", "bulkInsertResource", "bulkInsertResource_oracle");
addDatabaseSpecificStatement("kingbase", "bulkInsertProperty", "bulkInsertProperty_oracle");
addDatabaseSpecificStatement("kingbase", "bulkInsertProcessDefinition", "bulkInsertProcessDefinition_oracle");
addDatabaseSpecificStatement("kingbase", "bulkInsertModel", "bulkInsertModel_oracle");
addDatabaseSpecificStatement("kingbase", "bulkInsertTimer", "bulkInsertTimer_oracle");
addDatabaseSpecificStatement("kingbase", "bulkInsertMessage", "bulkInsertMessage_oracle");
addDatabaseSpecificStatement("kingbase", "bulkInsertIdentityLink", "bulkInsertIdentityLink_oracle");
addDatabaseSpecificStatement("kingbase", "bulkInsertHistoricVariableInstance", "bulkInsertHistoricVariableInstance_oracle");
addDatabaseSpecificStatement("kingbase", "bulkInsertHistoricTaskInstance", "bulkInsertHistoricTaskInstance_oracle");
addDatabaseSpecificStatement("kingbase", "bulkInsertHistoricProcessInstance", "bulkInsertHistoricProcessInstance_oracle");
addDatabaseSpecificStatement("kingbase", "bulkInsertHistoricIdentityLink", "bulkInsertHistoricIdentityLink_oracle");
addDatabaseSpecificStatement("kingbase", "bulkInsertHistoricDetailVariableInstanceUpdate", "bulkInsertHistoricDetailVariableInstanceUpdate_oracle");
addDatabaseSpecificStatement("kingbase", "bulkInsertHistoricFormProperty", "bulkInsertHistoricFormProperty_oracle");
addDatabaseSpecificStatement("kingbase", "bulkInsertHistoricActivityInstance", "bulkInsertHistoricActivityInstance_oracle");
addDatabaseSpecificStatement("kingbase", "bulkInsertExecution", "bulkInsertExecution_oracle");
addDatabaseSpecificStatement("kingbase", "bulkInsertMessageEventSubscription", "bulkInsertMessageEventSubscription_oracle");
addDatabaseSpecificStatement("kingbase", "bulkInsertSignalEventSubscription", "bulkInsertSignalEventSubscription_oracle");
addDatabaseSpecificStatement("kingbase", "bulkInsertCompensateEventSubscription", "bulkInsertCompensateEventSubscription_oracle");
addDatabaseSpecificStatement("kingbase", "bulkInsertEventLogEntry", "bulkInsertEventLogEntry_oracle");
addDatabaseSpecificStatement("kingbase", "bulkInsertDeployment", "bulkInsertDeployment_oracle");
addDatabaseSpecificStatement("kingbase", "bulkInsertComment", "bulkInsertComment_oracle");
addDatabaseSpecificStatement("kingbase", "bulkInsertByteArray", "bulkInsertByteArray_oracle");
addDatabaseSpecificStatement("kingbase", "bulkInsertEventLogEntry", "bulkInsertEventLogEntry_oracle");
addDatabaseSpecificStatement("kingbase", "bulkInsertDeployment", "bulkInsertDeployment_oracle");
addDatabaseSpecificStatement("kingbase", "bulkInsertComment", "bulkInsertComment_oracle");
addDatabaseSpecificStatement("kingbase", "bulkInsertAttachment", "bulkInsertAttachment_oracle");
addDatabaseSpecificStatement("kingbase", "bulkInsertJob", "bulkInsertJob_oracle");
addDatabaseSpecificStatement("kingbase", "bulkInsertTimerJob", "bulkInsertTimerJob_oracle");
addDatabaseSpecificStatement("kingbase", "bulkInsertSuspendedJob", "bulkInsertSuspendedJob_oracle");
addDatabaseSpecificStatement("kingbase", "bulkInsertDeadLetterJob", "bulkInsertDeadLetterJob_oracle");
}
3、修改liquibase相关
(1)在maven仓库下打开flowable\flowable-ui-modeler-logic\6.4.2,找到flowable-ui-modeler-logic-6.4.2.jar文件,用压缩包打开。
(2)进入jar包后打开META-INF\liquibase目录,把flowable-modeler-app-db-changelog.xml复制出来并在jar包中删除(必须在jar包中删除,不然会因为检索到两个文件报错)。
(3)在工作流引擎的微服务工程中,在src/main/resources中创建文件夹META-INF/liquibase,然后把flowable-modeler-app-db-changelog.xml复制到自己的工作目录下(已经存在“修改工作流的源码”目录中,使用者只需把目录中的文件复制到自己的工程中即可)
(4)使用金仓数据库时修改flowable-modeler-app-db-changelog.xml文件,把内容改为如下:
(主要是因为金仓不支持liquibase自动生成的创建索引语句)
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
<changeSet id="3" author="flowable">
<addColumn tableName="ACT_DE_MODEL">
<column name="tenant_id" type="varchar(255)" />
</addColumn>
<addColumn tableName="ACT_DE_MODEL_HISTORY">
<column name="tenant_id" type="varchar(255)" />
</addColumn>
</changeSet>
</databaseChangeLog>
(5)在org\flowable\db\create\flowable.kingbase.create.engine.sql脚本文件,加入以下SQL语句:
CREATE TABLE ACT_DE_MODEL (
id VARCHAR(255) NOT NULL,
name VARCHAR(400) NOT NULL,
model_key VARCHAR(400) NOT NULL,
description VARCHAR(4000),
model_comment VARCHAR(4000),
created timestamp,
created_by VARCHAR(255),
last_updated timestamp,
last_updated_by VARCHAR(255),
"version" INT,
model_editor_json CLOB,
thumbnail BLOB,
model_type INT,
CONSTRAINT PK_ACT_DE_MODEL PRIMARY KEY (id));
CREATE TABLE ACT_DE_MODEL_HISTORY (
id VARCHAR(255) NOT NULL,
name VARCHAR(400) NOT NULL,
model_key VARCHAR(400) NOT NULL,
description VARCHAR(4000),
model_comment VARCHAR(4000),
created timestamp,
created_by VARCHAR(255),
last_updated timestamp,
last_updated_by VARCHAR(255),
removal_date timestamp,
"version" INT,
model_editor_json CLOB,
model_id VARCHAR(255) NOT NULL,
model_type INT,
CONSTRAINT PK_ACT_DE_MODEL_HISTORY PRIMARY KEY (id));
CREATE INDEX idx_proc_mod_created ON ACT_DE_MODEL(created_by);
CREATE INDEX idx_proc_mod_history_proc ON ACT_DE_MODEL_HISTORY(model_id);
CREATE TABLE ACT_DE_DATABASECHANGELOGLOCK (
ID INT NOT NULL,
LOCKED BOOL NOT NULL,
LOCKGRANTED TIMESTAMP,
LOCKEDBY VARCHAR(255),
CONSTRAINT PK_ACT_DE_DATABASECHANGELOGLOCK PRIMARY KEY (ID));
CREATE TABLE ACT_DE_DATABASECHANGELOG (
ID VARCHAR(255) NOT NULL, AUTHOR VARCHAR(255) NOT NULL,
FILENAME VARCHAR(255) NOT NULL,
DATEEXECUTED TIMESTAMP NOT NULL,
ORDEREXECUTED INT NOT NULL,
EXECTYPE VARCHAR(10) NOT NULL,
MD5SUM VARCHAR(35),
DESCRIPTION VARCHAR(255),
COMMENTS VARCHAR(255),
TAG VARCHAR(255),
LIQUIBASE VARCHAR(20),
CONTEXTS VARCHAR(255),
LABELS VARCHAR(255),
DEPLOYMENT_ID VARCHAR(10));
4、配置文件
在pom.xml文件中加入金仓的依赖:
<dependency>
<groupId>com.kingbase</groupId>
<artifactId>kingbase8</artifactId>
<version>8.2.0</version>
</dependency>
<dependency>
<groupId>com.kingbase.dialect</groupId>
<artifactId>kingbase8</artifactId>
<version>8.2.0</version>
</dependency>
在application.properties中加入以下配置:
spring.jpa.properties.hibernate.autoReconnect=true
spring.datasource.driver-class-name=com.kingbase8.Driver
//金仓数据库名固定为大写
spring.datasource.url=jdbc:kingbase8://{ip}:{port}/{数据库名}?characterEncoding=utf-8&createDatabaseIfNotExist=true&SSL=false&nullCatalogMeansCurrent=true
spring.datasource.username={用户名}
spring.datasource.password={密码}
//基本语法与oracle类似
spring.jpa.database=oracle
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.Kingbase8Dialect
//金仓模式名固定为public
spring.jpa.properties.hibernate.default_schema=PUBLIC
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.hbm2ddl.auto=update
spring.jpa.properties.hibernate.show_sql=true
标签:VARCHAR,flowable,jar,kingbase,addDatabaseSpecificStatement,111,oracle
From: https://www.cnblogs.com/sensenh/p/17970212