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