修复用户下其他 schema 包含同名 flowable 表无法启动 bpm 服务的错误
This commit is contained in:
@@ -77,8 +77,13 @@ public class DbSqlSessionFactory implements SessionFactory {
|
|||||||
// 当前系统适配 dm,如果存在 schema 为空的情况,从 connection 获取
|
// 当前系统适配 dm,如果存在 schema 为空的情况,从 connection 获取
|
||||||
try {
|
try {
|
||||||
if (getDatabaseSchema() == null || getDatabaseSchema().length() == 0){
|
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());
|
setDatabaseSchema(dbSqlSession.getSqlSession().getConnection().getSchema());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
dbSqlSession.getSqlSession().getConnection().getSchema();
|
dbSqlSession.getSqlSession().getConnection().getSchema();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
@@ -351,4 +356,39 @@ public class DbSqlSessionFactory implements SessionFactory {
|
|||||||
public void setUsePrefixId(boolean usePrefixId) {
|
public void setUsePrefixId(boolean usePrefixId) {
|
||||||
this.usePrefixId = 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user