Merge branch 'dev' into test

# Conflicts:
#	zt-module-bpm/zt-module-bpm-server/src/main/java/com/alibaba/druid/pool/DruidPooledStatement.java
#	zt-module-bpm/zt-module-bpm-server/src/main/java/com/zt/plat/module/bpm/framework/rpc/config/RpcConfiguration.java
#	zt-module-bpm/zt-module-bpm-server/src/main/java/liquibase/datatype/core/BooleanType.java
#	zt-module-bpm/zt-module-bpm-server/src/main/java/org/flowable/common/engine/impl/AbstractEngineConfiguration.java
This commit is contained in:
chenbowen
2026-02-03 10:37:34 +08:00
8 changed files with 5443 additions and 0 deletions

View File

@@ -60,6 +60,18 @@
<artifactId>zt-module-qms-api</artifactId>
<version>${business.qms.version}</version>
</dependency>
<dependency>
<groupId>com.zt.plat</groupId>
<artifactId>zt-module-qms-api</artifactId>
<version>${revision}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.zt.plat</groupId>
<artifactId>zt-module-product-api</artifactId>
<version>${revision}</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>

View File

@@ -0,0 +1,781 @@
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//
package com.alibaba.druid.pool;
import com.alibaba.cloud.commons.lang.StringUtils;
import com.alibaba.druid.VERSION;
import com.alibaba.druid.support.logging.Log;
import com.alibaba.druid.support.logging.LogFactory;
import com.alibaba.druid.util.JdbcUtils;
import com.alibaba.druid.util.MySqlUtils;
import java.net.SocketTimeoutException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
public class DruidPooledStatement extends PoolableWrapper implements Statement {
private static final Log LOG = LogFactory.getLog(DruidPooledStatement.class);
private final Statement stmt;
protected DruidPooledConnection conn;
protected List<ResultSet> resultSetTrace;
protected boolean closed;
protected int fetchRowPeak = -1;
protected int exceptionCount;
public DruidPooledStatement(DruidPooledConnection conn, Statement stmt) {
super(stmt);
this.conn = conn;
this.stmt = stmt;
}
protected void addResultSetTrace(ResultSet resultSet) {
if (this.resultSetTrace == null) {
this.resultSetTrace = new ArrayList(1);
} else if (this.resultSetTrace.size() > 0) {
int lastIndex = this.resultSetTrace.size() - 1;
ResultSet lastResultSet = (ResultSet)this.resultSetTrace.get(lastIndex);
try {
if (lastResultSet.isClosed()) {
this.resultSetTrace.set(lastIndex, resultSet);
return;
}
} catch (SQLException var5) {
}
}
this.resultSetTrace.add(resultSet);
}
protected void recordFetchRowCount(int fetchRowCount) {
if (this.fetchRowPeak < fetchRowCount) {
this.fetchRowPeak = fetchRowCount;
}
}
public int getFetchRowPeak() {
return this.fetchRowPeak;
}
protected SQLException checkException(Throwable error) throws SQLException {
String sql = null;
if (this instanceof DruidPooledPreparedStatement) {
sql = ((DruidPooledPreparedStatement)this).getSql();
}
this.handleSocketTimeout(error);
++this.exceptionCount;
return this.conn.handleException(error, sql);
}
protected SQLException checkException(Throwable error, String sql) throws SQLException {
this.handleSocketTimeout(error);
++this.exceptionCount;
return this.conn.handleException(error, sql);
}
protected void handleSocketTimeout(Throwable error) throws SQLException {
if (this.conn != null && this.conn.transactionInfo == null && this.conn.holder != null) {
DruidDataSource dataSource = null;
DruidConnectionHolder holder = this.conn.holder;
if (holder.dataSource instanceof DruidDataSource) {
dataSource = (DruidDataSource)holder.dataSource;
}
if (dataSource != null) {
if (dataSource.killWhenSocketReadTimeout) {
SQLException sqlException = null;
if (error instanceof SQLException) {
sqlException = (SQLException)error;
}
if (sqlException != null) {
Throwable cause = error.getCause();
boolean socketReadTimeout = cause instanceof SocketTimeoutException && "Read timed out".equals(cause.getMessage());
if (socketReadTimeout) {
if (JdbcUtils.isMysqlDbType(dataSource.dbTypeName)) {
String killQuery = MySqlUtils.buildKillQuerySql(this.conn.getConnection(), (SQLException)error);
if (killQuery != null) {
DruidPooledConnection killQueryConn = null;
Statement killQueryStmt = null;
try {
killQueryConn = dataSource.getConnection(1000L);
if (killQueryConn != null) {
killQueryStmt = killQueryConn.createStatement();
killQueryStmt.execute(killQuery);
if (LOG.isDebugEnabled()) {
LOG.debug(killQuery + " success.");
}
return;
}
} catch (Exception ex) {
LOG.warn(killQuery + " error.", ex);
return;
} finally {
JdbcUtils.close(killQueryStmt);
JdbcUtils.close(killQueryConn);
}
}
}
}
}
}
}
}
}
public DruidPooledConnection getPoolableConnection() {
return this.conn;
}
public Statement getStatement() {
return this.stmt;
}
protected void checkOpen() throws SQLException {
if (this.closed) {
Throwable disableError = null;
if (this.conn != null) {
disableError = this.conn.getDisableError();
}
if (disableError != null) {
throw new SQLException("statement is closed", disableError);
} else {
throw new SQLException("statement is closed");
}
}
}
protected void clearResultSet() {
if (this.resultSetTrace != null) {
for(ResultSet rs : this.resultSetTrace) {
try {
if (!rs.isClosed()) {
rs.close();
}
} catch (SQLException ex) {
LOG.error("clearResultSet error", ex);
}
}
this.resultSetTrace.clear();
}
}
public void incrementExecuteCount() {
DruidPooledConnection conn = this.getPoolableConnection();
if (conn != null) {
DruidConnectionHolder holder = conn.getConnectionHolder();
if (holder != null) {
DruidAbstractDataSource dataSource = holder.getDataSource();
if (dataSource != null) {
dataSource.incrementExecuteCount();
}
}
}
}
public void incrementExecuteBatchCount() {
DruidPooledConnection conn = this.getPoolableConnection();
if (conn != null) {
DruidConnectionHolder holder = conn.getConnectionHolder();
if (holder != null) {
if (holder.getDataSource() != null) {
DruidAbstractDataSource dataSource = holder.getDataSource();
if (dataSource != null) {
dataSource.incrementExecuteBatchCount();
}
}
}
}
}
public void incrementExecuteUpdateCount() {
DruidPooledConnection conn = this.getPoolableConnection();
if (conn != null) {
DruidConnectionHolder holder = conn.getConnectionHolder();
if (holder != null) {
DruidAbstractDataSource dataSource = holder.getDataSource();
if (dataSource != null) {
dataSource.incrementExecuteUpdateCount();
}
}
}
}
public void incrementExecuteQueryCount() {
DruidPooledConnection conn = this.conn;
if (conn != null) {
DruidConnectionHolder holder = conn.holder;
if (holder != null) {
DruidAbstractDataSource dataSource = holder.dataSource;
if (dataSource != null) {
++dataSource.executeQueryCount;
}
}
}
}
protected void transactionRecord(String sql) throws SQLException {
this.conn.transactionRecord(sql);
}
public final ResultSet executeQuery(String sql) throws SQLException {
this.checkOpen();
this.incrementExecuteQueryCount();
this.transactionRecord(sql);
this.conn.beforeExecute();
ResultSet var3;
try {
ResultSet rs = this.stmt.executeQuery(sql);
if (rs != null) {
DruidPooledResultSet poolableResultSet = new DruidPooledResultSet(this, rs);
this.addResultSetTrace(poolableResultSet);
DruidPooledResultSet var4 = poolableResultSet;
return var4;
}
var3 = rs;
} catch (Throwable t) {
this.errorCheck(t);
throw this.checkException(t, sql);
} finally {
this.conn.afterExecute();
}
return var3;
}
public final int executeUpdate(String sql) throws SQLException {
this.checkOpen();
this.incrementExecuteUpdateCount();
this.transactionRecord(sql);
this.conn.beforeExecute();
int var2;
try {
var2 = this.stmt.executeUpdate(sql);
} catch (Throwable t) {
this.errorCheck(t);
throw this.checkException(t, sql);
} finally {
this.conn.afterExecute();
}
return var2;
}
protected final void errorCheck(Throwable t) {
String errorClassName = t.getClass().getName();
if (errorClassName.endsWith(".CommunicationsException") && this.conn.holder != null && this.conn.holder.dataSource.testWhileIdle) {
DruidConnectionHolder holder = this.conn.holder;
DruidAbstractDataSource dataSource = holder.dataSource;
long currentTimeMillis = System.currentTimeMillis();
long lastActiveTimeMillis = holder.lastActiveTimeMillis;
if (lastActiveTimeMillis < holder.lastKeepTimeMillis) {
lastActiveTimeMillis = holder.lastKeepTimeMillis;
}
long idleMillis = currentTimeMillis - lastActiveTimeMillis;
long lastValidIdleMillis = currentTimeMillis - holder.lastActiveTimeMillis;
String errorMsg = "CommunicationsException, druid version " + VERSION.getVersionNumber() + ", jdbcUrl : " + dataSource.jdbcUrl + ", testWhileIdle " + dataSource.testWhileIdle + ", idle millis " + idleMillis + ", minIdle " + dataSource.minIdle + ", poolingCount " + dataSource.getPoolingCount() + ", timeBetweenEvictionRunsMillis " + dataSource.timeBetweenEvictionRunsMillis + ", lastValidIdleMillis " + lastValidIdleMillis + ", driver " + dataSource.driver.getClass().getName();
if (dataSource.exceptionSorter != null) {
errorMsg = errorMsg + ", exceptionSorter " + dataSource.exceptionSorter.getClass().getName();
}
LOG.error(errorMsg);
}
}
public final int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
this.checkOpen();
this.incrementExecuteUpdateCount();
this.transactionRecord(sql);
this.conn.beforeExecute();
int var3;
try {
var3 = this.stmt.executeUpdate(sql, autoGeneratedKeys);
} catch (Throwable t) {
this.errorCheck(t);
throw this.checkException(t, sql);
} finally {
this.conn.afterExecute();
}
return var3;
}
public final int executeUpdate(String sql, int[] columnIndexes) throws SQLException {
this.checkOpen();
this.incrementExecuteUpdateCount();
this.transactionRecord(sql);
this.conn.beforeExecute();
int var3;
try {
var3 = this.stmt.executeUpdate(sql, columnIndexes);
} catch (Throwable t) {
this.errorCheck(t);
throw this.checkException(t, sql);
} finally {
this.conn.afterExecute();
}
return var3;
}
public final int executeUpdate(String sql, String[] columnNames) throws SQLException {
this.checkOpen();
this.incrementExecuteUpdateCount();
this.transactionRecord(sql);
this.conn.beforeExecute();
int var3;
try {
var3 = this.stmt.executeUpdate(sql, columnNames);
} catch (Throwable t) {
this.errorCheck(t);
throw this.checkException(t, sql);
} finally {
this.conn.afterExecute();
}
return var3;
}
public final boolean execute(String sql, int autoGeneratedKeys) throws SQLException {
this.checkOpen();
this.incrementExecuteCount();
this.transactionRecord(sql);
this.conn.beforeExecute();
boolean var3;
try {
var3 = this.stmt.execute(sql, autoGeneratedKeys);
} catch (Throwable t) {
this.errorCheck(t);
throw this.checkException(t, sql);
} finally {
this.conn.afterExecute();
}
return var3;
}
public final boolean execute(String sql, int[] columnIndexes) throws SQLException {
this.checkOpen();
this.incrementExecuteCount();
this.transactionRecord(sql);
this.conn.beforeExecute();
boolean var3;
try {
var3 = this.stmt.execute(sql, columnIndexes);
} catch (Throwable t) {
this.errorCheck(t);
throw this.checkException(t, sql);
} finally {
this.conn.afterExecute();
}
return var3;
}
public final boolean execute(String sql, String[] columnNames) throws SQLException {
this.checkOpen();
this.incrementExecuteCount();
this.transactionRecord(sql);
this.conn.beforeExecute();
boolean var3;
try {
var3 = this.stmt.execute(sql, columnNames);
} catch (Throwable t) {
this.errorCheck(t);
throw this.checkException(t, sql);
} finally {
this.conn.afterExecute();
}
return var3;
}
public int getMaxFieldSize() throws SQLException {
this.checkOpen();
try {
return this.stmt.getMaxFieldSize();
} catch (Throwable t) {
throw this.checkException(t);
}
}
public void close() throws SQLException {
if (!this.closed) {
this.clearResultSet();
if (this.stmt != null) {
this.stmt.close();
}
this.closed = true;
DruidConnectionHolder connHolder = this.conn.getConnectionHolder();
if (connHolder != null) {
connHolder.removeTrace(this);
}
}
}
public void setMaxFieldSize(int max) throws SQLException {
this.checkOpen();
try {
this.stmt.setMaxFieldSize(max);
} catch (Throwable t) {
throw this.checkException(t);
}
}
public final int getMaxRows() throws SQLException {
this.checkOpen();
try {
return this.stmt.getMaxRows();
} catch (Throwable t) {
throw this.checkException(t);
}
}
public void setMaxRows(int max) throws SQLException {
this.checkOpen();
try {
this.stmt.setMaxRows(max);
} catch (Throwable t) {
throw this.checkException(t);
}
}
public final void setEscapeProcessing(boolean enable) throws SQLException {
this.checkOpen();
try {
this.stmt.setEscapeProcessing(enable);
} catch (Throwable t) {
throw this.checkException(t);
}
}
public final int getQueryTimeout() throws SQLException {
this.checkOpen();
try {
return this.stmt.getQueryTimeout();
} catch (Throwable t) {
throw this.checkException(t);
}
}
public void setQueryTimeout(int seconds) throws SQLException {
this.checkOpen();
try {
this.stmt.setQueryTimeout(seconds);
} catch (Throwable t) {
throw this.checkException(t);
}
}
public final void cancel() throws SQLException {
this.checkOpen();
try {
this.stmt.cancel();
} catch (Throwable t) {
throw this.checkException(t);
}
}
public final SQLWarning getWarnings() throws SQLException {
this.checkOpen();
try {
return this.stmt.getWarnings();
} catch (Throwable t) {
throw this.checkException(t);
}
}
public final void clearWarnings() throws SQLException {
this.checkOpen();
try {
this.stmt.clearWarnings();
} catch (Throwable t) {
throw this.checkException(t);
}
}
public final void setCursorName(String name) throws SQLException {
this.checkOpen();
try {
this.stmt.setCursorName(name);
} catch (Throwable t) {
throw this.checkException(t);
}
}
@Override
public final boolean execute(String sql) throws SQLException {
checkOpen();
incrementExecuteCount();
transactionRecord(sql);
try {
if (StringUtils.isNotEmpty(sql)){
sql = sql.replace("TRUE", "1");
sql = sql.replace("FALSE", "0");
}
return stmt.execute(sql);
} catch (Throwable t) {
errorCheck(t);
throw checkException(t, sql);
}
}
public final ResultSet getResultSet() throws SQLException {
this.checkOpen();
try {
ResultSet rs = this.stmt.getResultSet();
if (rs == null) {
return null;
} else {
DruidPooledResultSet poolableResultSet = new DruidPooledResultSet(this, rs);
this.addResultSetTrace(poolableResultSet);
return poolableResultSet;
}
} catch (Throwable t) {
throw this.checkException(t);
}
}
public final int getUpdateCount() throws SQLException {
this.checkOpen();
try {
return this.stmt.getUpdateCount();
} catch (Throwable t) {
throw this.checkException(t);
}
}
public final boolean getMoreResults() throws SQLException {
this.checkOpen();
try {
boolean moreResults = this.stmt.getMoreResults();
if (this.resultSetTrace != null && this.resultSetTrace.size() > 0) {
ResultSet lastResultSet = (ResultSet)this.resultSetTrace.get(this.resultSetTrace.size() - 1);
if (lastResultSet instanceof DruidPooledResultSet) {
DruidPooledResultSet pooledResultSet = (DruidPooledResultSet)lastResultSet;
pooledResultSet.closed = true;
}
}
return moreResults;
} catch (Throwable t) {
throw this.checkException(t);
}
}
public void setFetchDirection(int direction) throws SQLException {
this.checkOpen();
try {
this.stmt.setFetchDirection(direction);
} catch (Throwable t) {
throw this.checkException(t);
}
}
public final int getFetchDirection() throws SQLException {
this.checkOpen();
try {
return this.stmt.getFetchDirection();
} catch (Throwable t) {
throw this.checkException(t);
}
}
public void setFetchSize(int rows) throws SQLException {
this.checkOpen();
try {
this.stmt.setFetchSize(rows);
} catch (Throwable t) {
throw this.checkException(t);
}
}
public final int getFetchSize() throws SQLException {
this.checkOpen();
try {
return this.stmt.getFetchSize();
} catch (Throwable t) {
throw this.checkException(t);
}
}
public final int getResultSetConcurrency() throws SQLException {
this.checkOpen();
try {
return this.stmt.getResultSetConcurrency();
} catch (Throwable t) {
throw this.checkException(t);
}
}
public final int getResultSetType() throws SQLException {
this.checkOpen();
try {
return this.stmt.getResultSetType();
} catch (Throwable t) {
throw this.checkException(t);
}
}
public final void addBatch(String sql) throws SQLException {
this.checkOpen();
this.transactionRecord(sql);
try {
this.stmt.addBatch(sql);
} catch (Throwable t) {
throw this.checkException(t, sql);
}
}
public final void clearBatch() throws SQLException {
if (!this.closed) {
try {
this.stmt.clearBatch();
} catch (Throwable t) {
throw this.checkException(t);
}
}
}
public int[] executeBatch() throws SQLException {
this.checkOpen();
this.incrementExecuteBatchCount();
this.conn.beforeExecute();
int[] var1;
try {
var1 = this.stmt.executeBatch();
} catch (Throwable t) {
this.errorCheck(t);
throw this.checkException(t);
} finally {
this.conn.afterExecute();
}
return var1;
}
public final Connection getConnection() throws SQLException {
this.checkOpen();
return this.conn;
}
public final boolean getMoreResults(int current) throws SQLException {
this.checkOpen();
try {
boolean results = this.stmt.getMoreResults(current);
if (this.resultSetTrace != null && this.resultSetTrace.size() > 0) {
ResultSet lastResultSet = (ResultSet)this.resultSetTrace.get(this.resultSetTrace.size() - 1);
if (lastResultSet instanceof DruidPooledResultSet) {
DruidPooledResultSet pooledResultSet = (DruidPooledResultSet)lastResultSet;
pooledResultSet.closed = true;
}
}
return results;
} catch (Throwable t) {
throw this.checkException(t);
}
}
public final ResultSet getGeneratedKeys() throws SQLException {
this.checkOpen();
try {
ResultSet rs = this.stmt.getGeneratedKeys();
DruidPooledResultSet poolableResultSet = new DruidPooledResultSet(this, rs);
this.addResultSetTrace(poolableResultSet);
return poolableResultSet;
} catch (Throwable t) {
throw this.checkException(t);
}
}
public final int getResultSetHoldability() throws SQLException {
this.checkOpen();
try {
return this.stmt.getResultSetHoldability();
} catch (Throwable t) {
throw this.checkException(t);
}
}
public final boolean isClosed() throws SQLException {
return this.closed;
}
public final void setPoolable(boolean poolable) throws SQLException {
if (!poolable) {
throw new SQLException("not support");
}
}
public final boolean isPoolable() throws SQLException {
return false;
}
public String toString() {
return this.stmt.toString();
}
public void closeOnCompletion() throws SQLException {
this.stmt.closeOnCompletion();
}
public boolean isCloseOnCompletion() throws SQLException {
return this.stmt.isCloseOnCompletion();
}
}

View File

@@ -0,0 +1,24 @@
package com.zt.plat.module.bpm.framework.rpc.config;
import com.zt.plat.module.capital.api.splyAmountRequest.AmountRequestApi;
import com.zt.plat.module.capital.api.splyAmtCrdtAppl.AmountCreditApplyApi;
import com.zt.plat.module.product.api.MesProcessRoutApi;
import com.zt.plat.module.product.api.plan.MesCompanyPlanApi;
import com.zt.plat.module.product.api.plan.MesFactoryPlanApi;
import com.zt.plat.module.qms.api.task.QmsApi;
import com.zt.plat.module.system.api.dept.DeptApi;
import com.zt.plat.module.system.api.dept.PostApi;
import com.zt.plat.module.system.api.dict.DictDataApi;
import com.zt.plat.module.system.api.permission.PermissionApi;
import com.zt.plat.module.system.api.permission.RoleApi;
import com.zt.plat.module.system.api.sms.SmsSendApi;
import com.zt.plat.module.system.api.user.AdminUserApi;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Configuration;
@Configuration(value = "bpmRpcConfiguration", proxyBeanMethods = false)
@EnableFeignClients(clients = {RoleApi.class, DeptApi.class, PostApi.class, AdminUserApi.class, SmsSendApi.class, DictDataApi.class,
PermissionApi.class, AmountCreditApplyApi.class, MesCompanyPlanApi.class, MesFactoryPlanApi.class, MesProcessRoutApi.class,
QmsApi.class, AmountRequestApi.class})
public class RpcConfiguration {
}

View File

@@ -0,0 +1,149 @@
package liquibase.datatype.core;
import liquibase.change.core.LoadDataChange;
import liquibase.database.Database;
import liquibase.database.core.*;
import liquibase.datatype.DataTypeInfo;
import liquibase.datatype.DatabaseDataType;
import liquibase.datatype.LiquibaseDataType;
import liquibase.exception.UnexpectedLiquibaseException;
import liquibase.statement.DatabaseFunction;
import liquibase.util.StringUtil;
import java.util.Locale;
import java.util.regex.Pattern;
@DataTypeInfo(name = "boolean", aliases = {"java.sql.Types.BOOLEAN", "java.lang.Boolean", "bit", "bool"}, minParameters = 0, maxParameters = 0, priority = LiquibaseDataType.PRIORITY_DEFAULT)
public class BooleanType extends LiquibaseDataType {
@Override
public DatabaseDataType toDatabaseDataType(Database database) {
String originalDefinition = StringUtil.trimToEmpty(getRawDefinition());
// if ((database instanceof Firebird3Database)) {
// return new DatabaseDataType("BOOLEAN");
// }
if ((database instanceof AbstractDb2Database) || (database instanceof FirebirdDatabase)) {
return new DatabaseDataType("SMALLINT");
} else if (database instanceof MSSQLDatabase) {
return new DatabaseDataType(database.escapeDataTypeName("bit"));
} else if (database instanceof MySQLDatabase) {
if (originalDefinition.toLowerCase(Locale.US).startsWith("bit")) {
return new DatabaseDataType("BIT", getParameters());
}
return new DatabaseDataType("BIT", 1);
} else if (database instanceof OracleDatabase) {
return new DatabaseDataType("NUMBER", 1);
} else if ((database instanceof SybaseASADatabase) || (database instanceof SybaseDatabase)) {
return new DatabaseDataType("BIT");
} else if (database instanceof DerbyDatabase) {
if (((DerbyDatabase) database).supportsBooleanDataType()) {
return new DatabaseDataType("BOOLEAN");
} else {
return new DatabaseDataType("SMALLINT");
}
} else if (database.getClass().isAssignableFrom(DB2Database.class)) {
if (((DB2Database) database).supportsBooleanDataType())
return new DatabaseDataType("BOOLEAN");
else
return new DatabaseDataType("SMALLINT");
} else if (database instanceof HsqlDatabase) {
return new DatabaseDataType("BOOLEAN");
} else if (database instanceof PostgresDatabase) {
if (originalDefinition.toLowerCase(Locale.US).startsWith("bit")) {
return new DatabaseDataType("BIT", getParameters());
}
} else if(database instanceof DmDatabase) {
return new DatabaseDataType("bit");
}
return super.toDatabaseDataType(database);
}
@Override
public String objectToSql(Object value, Database database) {
if ((value == null) || "null".equals(value.toString().toLowerCase(Locale.US))) {
return null;
}
String returnValue;
if (value instanceof String) {
value = ((String) value).replaceAll("'", "");
if ("true".equals(((String) value).toLowerCase(Locale.US)) || "1".equals(value) || "b'1'".equals(((String) value).toLowerCase(Locale.US)) || "t".equals(((String) value).toLowerCase(Locale.US)) || ((String) value).toLowerCase(Locale.US).equals(this.getTrueBooleanValue(database).toLowerCase(Locale.US))) {
returnValue = this.getTrueBooleanValue(database);
} else if ("false".equals(((String) value).toLowerCase(Locale.US)) || "0".equals(value) || "b'0'".equals(
((String) value).toLowerCase(Locale.US)) || "f".equals(((String) value).toLowerCase(Locale.US)) || ((String) value).toLowerCase(Locale.US).equals(this.getFalseBooleanValue(database).toLowerCase(Locale.US))) {
returnValue = this.getFalseBooleanValue(database);
} else {
throw new UnexpectedLiquibaseException("Unknown boolean value: " + value);
}
} else if (value instanceof Long) {
if (Long.valueOf(1).equals(value)) {
returnValue = this.getTrueBooleanValue(database);
} else {
returnValue = this.getFalseBooleanValue(database);
}
} else if (value instanceof Number) {
if (value.equals(1) || "1".equals(value.toString()) || "1.0".equals(value.toString())) {
returnValue = this.getTrueBooleanValue(database);
} else {
returnValue = this.getFalseBooleanValue(database);
}
} else if (value instanceof DatabaseFunction) {
return value.toString();
} else if (value instanceof Boolean) {
if (((Boolean) value)) {
returnValue = this.getTrueBooleanValue(database);
} else {
returnValue = this.getFalseBooleanValue(database);
}
} else {
throw new UnexpectedLiquibaseException("Cannot convert type " + value.getClass() + " to a boolean value");
}
return returnValue;
}
protected boolean isNumericBoolean(Database database) {
if (database instanceof DerbyDatabase) {
return !((DerbyDatabase) database).supportsBooleanDataType();
} else if (database.getClass().isAssignableFrom(DB2Database.class)) {
return !((DB2Database) database).supportsBooleanDataType();
}
return (database instanceof Db2zDatabase) || (database instanceof DB2Database) || (database instanceof FirebirdDatabase) || (database instanceof
MSSQLDatabase) || (database instanceof MySQLDatabase) || (database instanceof OracleDatabase) ||
(database instanceof SQLiteDatabase) || (database instanceof SybaseASADatabase) || (database instanceof
SybaseDatabase) || (database instanceof DmDatabase);
}
/**
* The database-specific value to use for "false" "boolean" columns.
*/
public String getFalseBooleanValue(Database database) {
if (isNumericBoolean(database)) {
return "0";
}
if (database instanceof InformixDatabase) {
return "'f'";
}
return "FALSE";
}
/**
* The database-specific value to use for "true" "boolean" columns.
*/
public String getTrueBooleanValue(Database database) {
if (isNumericBoolean(database)) {
return "1";
}
if (database instanceof InformixDatabase) {
return "'t'";
}
return "TRUE";
}
@Override
public LoadDataChange.LOAD_DATA_TYPE getLoadTypeName() {
return LoadDataChange.LOAD_DATA_TYPE.BOOLEAN;
}
}

View File

@@ -0,0 +1,32 @@
package liquibase.datatype.core;
import liquibase.database.Database;
import liquibase.database.core.DmDatabase;
import liquibase.datatype.DataTypeInfo;
import liquibase.datatype.DatabaseDataType;
@DataTypeInfo(
name = "boolean",
aliases = {"java.sql.Types.BOOLEAN", "java.lang.Boolean", "bit", "bool"},
minParameters = 0,
maxParameters = 0,
priority = 2
)
public class DmBooleanType extends BooleanType {
@Override
public boolean supports(Database database) {
if (database instanceof DmDatabase) {
return true;
}
return super.supports(database);
}
@Override
public DatabaseDataType toDatabaseDataType(Database database) {
if (database instanceof DmDatabase) {
return new DatabaseDataType("NUMBER", 1);
}
return super.toDatabaseDataType(database);
}
}

View File

@@ -0,0 +1,394 @@
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.flowable.common.engine.impl.db;
import org.apache.ibatis.session.SqlSessionFactory;
import org.flowable.common.engine.api.FlowableException;
import org.flowable.common.engine.impl.context.Context;
import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.flowable.common.engine.impl.interceptor.Session;
import org.flowable.common.engine.impl.interceptor.SessionFactory;
import org.flowable.common.engine.impl.persistence.cache.EntityCache;
import org.flowable.common.engine.impl.persistence.entity.Entity;
import java.sql.SQLException;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
/**
* @author Tom Baeyens
* @author Joram Barrez
*/
public class DbSqlSessionFactory implements SessionFactory {
protected Map<String, Map<String, String>> databaseSpecificStatements = new HashMap<>();
protected String databaseType;
protected String databaseTablePrefix = "";
protected boolean tablePrefixIsSchema;
protected String databaseCatalog;
protected String databaseSchema;
protected SqlSessionFactory sqlSessionFactory;
protected Map<String, String> statementMappings;
protected Map<Class<?>, String> insertStatements = new ConcurrentHashMap<>();
protected Map<Class<?>, String> updateStatements = new ConcurrentHashMap<>();
protected Map<Class<?>, String> deleteStatements = new ConcurrentHashMap<>();
protected Map<Class<?>, String> selectStatements = new ConcurrentHashMap<>();
protected List<Class<? extends Entity>> insertionOrder = new ArrayList<>();
protected List<Class<? extends Entity>> deletionOrder = new ArrayList<>();
protected boolean isDbHistoryUsed = true;
protected Set<Class<? extends Entity>> bulkInserteableEntityClasses = new HashSet<>();
protected Map<Class<?>, String> bulkInsertStatements = new ConcurrentHashMap<>();
protected int maxNrOfStatementsInBulkInsert = 100;
protected Map<String, Class<?>> logicalNameToClassMapping = new ConcurrentHashMap<>();
protected boolean usePrefixId;
public DbSqlSessionFactory(boolean usePrefixId) {
this.usePrefixId = usePrefixId;
}
@Override
public Class<?> getSessionType() {
return DbSqlSession.class;
}
@Override
public Session openSession(CommandContext commandContext) {
DbSqlSession dbSqlSession = createDbSqlSession();
// 当前系统适配 dm,如果存在 schema 为空的情况,从 connection 获取
try {
if (getDatabaseSchema() == null || getDatabaseSchema().length() == 0){
String schemaFromUrl = extractSchemaFromJdbcUrl(dbSqlSession.getSqlSession().getConnection());
if (schemaFromUrl != null && schemaFromUrl.length() > 0) {
setDatabaseSchema(schemaFromUrl);
} else {
setDatabaseSchema(dbSqlSession.getSqlSession().getConnection().getSchema());
}
}
dbSqlSession.getSqlSession().getConnection().getSchema();
} catch (SQLException e) {
throw new RuntimeException(e);
}
if (getDatabaseSchema() != null && getDatabaseSchema().length() > 0) {
try {
dbSqlSession.getSqlSession().getConnection().setSchema(getDatabaseSchema());
} catch (SQLException e) {
throw new FlowableException("Could not set database schema on connection", e);
}
}
if (getDatabaseCatalog() != null && getDatabaseCatalog().length() > 0) {
try {
dbSqlSession.getSqlSession().getConnection().setCatalog(getDatabaseCatalog());
} catch (SQLException e) {
throw new FlowableException("Could not set database catalog on connection", e);
}
}
if (dbSqlSession.getSqlSession().getConnection() == null) {
throw new FlowableException("Invalid dbSqlSession: no active connection found");
}
return dbSqlSession;
}
protected DbSqlSession createDbSqlSession() {
return new DbSqlSession(this, Context.getCommandContext().getSession(EntityCache.class));
}
// insert, update and delete statements
// /////////////////////////////////////
public String getInsertStatement(Entity object) {
return getStatement(object.getClass(), insertStatements, "insert");
}
public String getInsertStatement(Class<? extends Entity> clazz) {
return getStatement(clazz, insertStatements, "insert");
}
public String getUpdateStatement(Entity object) {
return getStatement(object.getClass(), updateStatements, "update");
}
public String getDeleteStatement(Class<?> entityClass) {
return getStatement(entityClass, deleteStatements, "delete");
}
public String getSelectStatement(Class<?> entityClass) {
return getStatement(entityClass, selectStatements, "select");
}
protected String getStatement(Class<?> entityClass, Map<Class<?>, String> cachedStatements, String prefix) {
String statement = cachedStatements.get(entityClass);
if (statement != null) {
return statement;
}
statement = prefix + entityClass.getSimpleName();
if (statement.endsWith("Impl")) {
statement = statement.substring(0, statement.length() - 10); // removing 'entityImpl'
} else {
statement = statement.substring(0, statement.length() - 6); // removing 'entity'
}
cachedStatements.put(entityClass, statement);
return statement;
}
// db specific mappings
// /////////////////////////////////////////////////////
protected void addDatabaseSpecificStatement(String databaseType, String activitiStatement, String ibatisStatement) {
Map<String, String> specificStatements = databaseSpecificStatements.get(databaseType);
if (specificStatements == null) {
specificStatements = new HashMap<>();
databaseSpecificStatements.put(databaseType, specificStatements);
}
specificStatements.put(activitiStatement, ibatisStatement);
}
public String mapStatement(String statement) {
if (statementMappings == null) {
return statement;
}
String mappedStatement = statementMappings.get(statement);
return (mappedStatement != null ? mappedStatement : statement);
}
// customized getters and setters
// ///////////////////////////////////////////
public void setDatabaseType(String databaseType) {
this.databaseType = databaseType;
this.statementMappings = databaseSpecificStatements.get(databaseType);
}
public boolean isMysql() {
return "mysql".equals(getDatabaseType());
}
public boolean isOracle() {
return "oracle".equals(getDatabaseType());
}
public Boolean isBulkInsertable(Class<? extends Entity> entityClass) {
return bulkInserteableEntityClasses != null && bulkInserteableEntityClasses.contains(entityClass);
}
@SuppressWarnings("rawtypes")
public String getBulkInsertStatement(Class clazz) {
return getStatement(clazz, bulkInsertStatements, "bulkInsert");
}
public Set<Class<? extends Entity>> getBulkInserteableEntityClasses() {
return bulkInserteableEntityClasses;
}
public void setBulkInserteableEntityClasses(Set<Class<? extends Entity>> bulkInserteableEntityClasses) {
this.bulkInserteableEntityClasses = bulkInserteableEntityClasses;
}
public int getMaxNrOfStatementsInBulkInsert() {
return maxNrOfStatementsInBulkInsert;
}
public void setMaxNrOfStatementsInBulkInsert(int maxNrOfStatementsInBulkInsert) {
this.maxNrOfStatementsInBulkInsert = maxNrOfStatementsInBulkInsert;
}
public Map<Class<?>, String> getBulkInsertStatements() {
return bulkInsertStatements;
}
public void setBulkInsertStatements(Map<Class<?>, String> bulkInsertStatements) {
this.bulkInsertStatements = bulkInsertStatements;
}
// getters and setters //////////////////////////////////////////////////////
public SqlSessionFactory getSqlSessionFactory() {
return sqlSessionFactory;
}
public void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory) {
this.sqlSessionFactory = sqlSessionFactory;
}
public String getDatabaseType() {
return databaseType;
}
public Map<String, Map<String, String>> getDatabaseSpecificStatements() {
return databaseSpecificStatements;
}
public void setDatabaseSpecificStatements(Map<String, Map<String, String>> databaseSpecificStatements) {
this.databaseSpecificStatements = databaseSpecificStatements;
}
public Map<String, String> getStatementMappings() {
return statementMappings;
}
public void setStatementMappings(Map<String, String> statementMappings) {
this.statementMappings = statementMappings;
}
public Map<Class<?>, String> getInsertStatements() {
return insertStatements;
}
public void setInsertStatements(Map<Class<?>, String> insertStatements) {
this.insertStatements = insertStatements;
}
public Map<Class<?>, String> getUpdateStatements() {
return updateStatements;
}
public void setUpdateStatements(Map<Class<?>, String> updateStatements) {
this.updateStatements = updateStatements;
}
public Map<Class<?>, String> getDeleteStatements() {
return deleteStatements;
}
public void setDeleteStatements(Map<Class<?>, String> deleteStatements) {
this.deleteStatements = deleteStatements;
}
public Map<Class<?>, String> getSelectStatements() {
return selectStatements;
}
public void setSelectStatements(Map<Class<?>, String> selectStatements) {
this.selectStatements = selectStatements;
}
public boolean isDbHistoryUsed() {
return isDbHistoryUsed;
}
public void setDbHistoryUsed(boolean isDbHistoryUsed) {
this.isDbHistoryUsed = isDbHistoryUsed;
}
public void setDatabaseTablePrefix(String databaseTablePrefix) {
this.databaseTablePrefix = databaseTablePrefix;
}
public String getDatabaseTablePrefix() {
return databaseTablePrefix;
}
public String getDatabaseCatalog() {
return databaseCatalog;
}
public void setDatabaseCatalog(String databaseCatalog) {
this.databaseCatalog = databaseCatalog;
}
public String getDatabaseSchema() {
return databaseSchema;
}
public void setDatabaseSchema(String databaseSchema) {
this.databaseSchema = databaseSchema;
}
public void setTablePrefixIsSchema(boolean tablePrefixIsSchema) {
this.tablePrefixIsSchema = tablePrefixIsSchema;
}
public boolean isTablePrefixIsSchema() {
return tablePrefixIsSchema;
}
public List<Class<? extends Entity>> getInsertionOrder() {
return insertionOrder;
}
public void setInsertionOrder(List<Class<? extends Entity>> insertionOrder) {
this.insertionOrder = insertionOrder;
}
public List<Class<? extends Entity>> getDeletionOrder() {
return deletionOrder;
}
public void setDeletionOrder(List<Class<? extends Entity>> deletionOrder) {
this.deletionOrder = deletionOrder;
}
public void addLogicalEntityClassMapping(String logicalName, Class<?> entityClass) {
logicalNameToClassMapping.put(logicalName, entityClass);
}
public Map<String, Class<?>> getLogicalNameToClassMapping() {
return logicalNameToClassMapping;
}
public void setLogicalNameToClassMapping(Map<String, Class<?>> logicalNameToClassMapping) {
this.logicalNameToClassMapping = logicalNameToClassMapping;
}
public boolean isUsePrefixId() {
return usePrefixId;
}
public void setUsePrefixId(boolean usePrefixId) {
this.usePrefixId = usePrefixId;
}
private String extractSchemaFromJdbcUrl(java.sql.Connection connection) {
if (connection == null) {
return null;
}
try {
String url = connection.getMetaData().getURL();
if (url == null || url.isEmpty()) {
return null;
}
int queryIndex = url.indexOf('?');
if (queryIndex < 0 || queryIndex == url.length() - 1) {
return null;
}
String query = url.substring(queryIndex + 1);
String[] parts = query.split("[&;]");
for (String part : parts) {
int eqIndex = part.indexOf('=');
if (eqIndex <= 0 || eqIndex == part.length() - 1) {
continue;
}
String key = part.substring(0, eqIndex).trim().toLowerCase(Locale.ROOT);
if ("schema".equals(key) || "currentschema".equals(key) || "current_schema".equals(key)) {
String value = part.substring(eqIndex + 1).trim();
if ((value.startsWith("\"") && value.endsWith("\"")) || (value.startsWith("'") && value.endsWith("'"))) {
value = value.substring(1, value.length() - 1);
}
return value;
}
}
} catch (SQLException ignored) {
return null;
}
return null;
}
}