修改了message配置

This commit is contained in:
root 2025-06-15 10:46:52 +08:00
parent 069b9d07af
commit f8e3b1495a
3 changed files with 47 additions and 151 deletions

View File

@ -1,14 +1,9 @@
package com.stdproject.config; package com.stdproject.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource; import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ResourceBundleMessageSource; import org.springframework.context.support.ResourceBundleMessageSource;
import org.springframework.stereotype.Component;
import jakarta.annotation.PostConstruct;
import java.lang.reflect.Field;
/** /**
* 国际化配置类 * 国际化配置类
@ -27,29 +22,4 @@ public class MessageSourceConfig {
return messageSource; return messageSource;
} }
@Component
public static class TranslatorInitializer {
@Autowired
private MessageSource messageSource;
@PostConstruct
public void initTranslator() {
try {
Class<?> translatorClass = Class.forName("io.gisbi.i18n.Translator");
Field messageSourceField = translatorClass.getDeclaredField("messageSource");
messageSourceField.setAccessible(true);
messageSourceField.set(null, messageSource);
System.out.println("Translator.messageSource initialized successfully");
} catch (Exception e) {
System.err.println("Failed to initialize Translator.messageSource: " + e.getMessage());
// 如果Translator类不存在创建一个简单的替代实现
createFallbackTranslator();
}
}
private void createFallbackTranslator() {
System.out.println("Creating fallback translator implementation");
}
} }
}

View File

@ -2,6 +2,7 @@ package com.stdproject.service.provider;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jcraft.jsch.Session; import com.jcraft.jsch.Session;
import com.stdproject.common.BusinessException;
import com.stdproject.controller.EngineRequest; import com.stdproject.controller.EngineRequest;
import com.stdproject.entity.CoreDatasource; import com.stdproject.entity.CoreDatasource;
import com.stdproject.entity.CoreDriver; import com.stdproject.entity.CoreDriver;
@ -11,7 +12,6 @@ import com.stdproject.service.type.*;
import com.stdproject.utils.EncryptUtils; import com.stdproject.utils.EncryptUtils;
import com.stdproject.utils.FieldUtils; import com.stdproject.utils.FieldUtils;
import io.gisbi.constant.SQLConstants; import io.gisbi.constant.SQLConstants;
import io.gisbi.exception.DEException;
import io.gisbi.extensions.datasource.dto.*; import io.gisbi.extensions.datasource.dto.*;
import io.gisbi.extensions.datasource.provider.DriverShim; import io.gisbi.extensions.datasource.provider.DriverShim;
import io.gisbi.extensions.datasource.provider.ExtendedJdbcClassLoader; import io.gisbi.extensions.datasource.provider.ExtendedJdbcClassLoader;
@ -98,7 +98,7 @@ public class CalciteProvider extends Provider {
schemas.add(resultSet.getString(1)); schemas.add(resultSet.getString(1));
} }
} catch (Exception e) { } catch (Exception e) {
DEException.throwException(e.getMessage()); BusinessException.throwException(e.getMessage());
} }
return schemas; return schemas;
} }
@ -111,7 +111,7 @@ public class CalciteProvider extends Provider {
DatasourceConfiguration configuration = JsonUtil.parseObject(datasourceRequest.getDatasource().getConfiguration(), Pg.class); DatasourceConfiguration configuration = JsonUtil.parseObject(datasourceRequest.getDatasource().getConfiguration(), Pg.class);
List<String> schemas = getSchema(datasourceRequest); List<String> schemas = getSchema(datasourceRequest);
if (CollectionUtils.isEmpty(schemas) || !schemas.contains(configuration.getSchema())) { if (CollectionUtils.isEmpty(schemas) || !schemas.contains(configuration.getSchema())) {
DEException.throwException("无效的 schema"); BusinessException.throwException("无效的 schema");
} }
break; break;
default: default:
@ -148,13 +148,13 @@ public class CalciteProvider extends Provider {
} }
} }
} catch (Exception e) { } catch (Exception e) {
DEException.throwException(e.getMessage()); BusinessException.throwException(e.getMessage());
} }
return tables; return tables;
} }
@Override @Override
public Map<String, Object> fetchResultField(DatasourceRequest datasourceRequest) throws DEException { public Map<String, Object> fetchResultField(DatasourceRequest datasourceRequest) throws BusinessException {
// 不跨数据源 // 不跨数据源
if (datasourceRequest.getDsList().size() == 1) { if (datasourceRequest.getDsList().size() == 1) {
return jdbcFetchResultField(datasourceRequest); return jdbcFetchResultField(datasourceRequest);
@ -190,7 +190,7 @@ public class CalciteProvider extends Provider {
} else { } else {
msg = e.getMessage(); msg = e.getMessage();
} }
DEException.throwException(Translator.get("i18n_fetch_error") + msg); BusinessException.throwException(Translator.get("i18n_fetch_error") + msg);
} finally { } finally {
try { try {
if (resultSet != null) resultSet.close(); if (resultSet != null) resultSet.close();
@ -205,7 +205,7 @@ public class CalciteProvider extends Provider {
} }
@Override @Override
public String transSqlDialect(String sql, Map<Long, DatasourceSchemaDTO> dsMap) throws DEException { public String transSqlDialect(String sql, Map<Long, DatasourceSchemaDTO> dsMap) throws BusinessException {
DatasourceSchemaDTO value = dsMap.entrySet().iterator().next().getValue(); DatasourceSchemaDTO value = dsMap.entrySet().iterator().next().getValue();
try (Connection connection = getConnectionFromPool(value.getId());) { try (Connection connection = getConnectionFromPool(value.getId());) {
// 获取数据库version // 获取数据库version
@ -216,7 +216,7 @@ public class CalciteProvider extends Provider {
SqlNode sqlNode = parser.parseStmt(); SqlNode sqlNode = parser.parseStmt();
return sqlNode.toSqlString(getDialect(value)).toString(); return sqlNode.toSqlString(getDialect(value)).toString();
} catch (Exception e) { } catch (Exception e) {
DEException.throwException(e.getMessage()); BusinessException.throwException(e.getMessage());
} }
return null; return null;
} }
@ -242,7 +242,7 @@ public class CalciteProvider extends Provider {
} }
@Override @Override
public List<TableField> fetchTableField(DatasourceRequest datasourceRequest) throws DEException { public List<TableField> fetchTableField(DatasourceRequest datasourceRequest) throws BusinessException {
List<TableField> datasetTableFields = new ArrayList<>(); List<TableField> datasetTableFields = new ArrayList<>();
DatasourceSchemaDTO datasourceSchemaDTO = datasourceRequest.getDsList().entrySet().iterator().next().getValue(); DatasourceSchemaDTO datasourceSchemaDTO = datasourceRequest.getDsList().entrySet().iterator().next().getValue();
datasourceRequest.setDatasource(datasourceSchemaDTO); datasourceRequest.setDatasource(datasourceSchemaDTO);
@ -259,7 +259,7 @@ public class CalciteProvider extends Provider {
resultSet = statement.executeQuery(datasourceRequest.getQuery()); resultSet = statement.executeQuery(datasourceRequest.getQuery());
datasetTableFields.addAll(getField(resultSet, datasourceRequest)); datasetTableFields.addAll(getField(resultSet, datasourceRequest));
} catch (Exception e) { } catch (Exception e) {
DEException.throwException(e.getMessage()); BusinessException.throwException(e.getMessage());
} finally { } finally {
if (resultSet != null) { if (resultSet != null) {
try { try {
@ -296,7 +296,7 @@ public class CalciteProvider extends Provider {
} }
} }
} catch (Exception e) { } catch (Exception e) {
DEException.throwException(e.getMessage()); BusinessException.throwException(e.getMessage());
} finally { } finally {
if (resultSet != null) { if (resultSet != null) {
try { try {
@ -386,7 +386,7 @@ public class CalciteProvider extends Provider {
conn = driverClass.connect(configuration.getJdbc(), props); conn = driverClass.connect(configuration.getJdbc(), props);
} catch (Exception e) { } catch (Exception e) {
DEException.throwException(e.getMessage()); BusinessException.throwException(e.getMessage());
} }
connectionObj.setConnection(conn); connectionObj.setConnection(conn);
return connectionObj; return connectionObj;
@ -412,7 +412,7 @@ public class CalciteProvider extends Provider {
return drivers; return drivers;
} }
public Map<String, Object> jdbcFetchResultField(DatasourceRequest datasourceRequest) throws DEException { public Map<String, Object> jdbcFetchResultField(DatasourceRequest datasourceRequest) throws BusinessException {
DatasourceSchemaDTO value = datasourceRequest.getDsList().entrySet().iterator().next().getValue(); DatasourceSchemaDTO value = datasourceRequest.getDsList().entrySet().iterator().next().getValue();
datasourceRequest.setDatasource(value); datasourceRequest.setDatasource(value);
@ -442,9 +442,9 @@ public class CalciteProvider extends Provider {
fieldList = getField(resultSet, datasourceRequest); fieldList = getField(resultSet, datasourceRequest);
dataList = getData(resultSet, datasourceRequest); dataList = getData(resultSet, datasourceRequest);
} catch (SQLException e) { } catch (SQLException e) {
DEException.throwException("SQL ERROR: " + e.getMessage()); BusinessException.throwException("SQL ERROR: " + e.getMessage());
} catch (Exception e) { } catch (Exception e) {
DEException.throwException("Datasource connection exception: " + e.getMessage()); BusinessException.throwException("Datasource connection exception: " + e.getMessage());
} finally { } finally {
if (resultSet != null) { if (resultSet != null) {
try { try {
@ -461,7 +461,7 @@ public class CalciteProvider extends Provider {
} }
@Override @Override
public void exec(DatasourceRequest datasourceRequest) throws DEException { public void exec(DatasourceRequest datasourceRequest) throws BusinessException {
DatasourceSchemaDTO value = datasourceRequest.getDsList().entrySet().iterator().next().getValue(); DatasourceSchemaDTO value = datasourceRequest.getDsList().entrySet().iterator().next().getValue();
datasourceRequest.setDatasource(value); datasourceRequest.setDatasource(value);
DatasourceConfiguration datasourceConfiguration = JsonUtil.parseObject(datasourceRequest.getDatasource().getConfiguration(), DatasourceConfiguration.class); DatasourceConfiguration datasourceConfiguration = JsonUtil.parseObject(datasourceRequest.getDatasource().getConfiguration(), DatasourceConfiguration.class);
@ -483,9 +483,9 @@ public class CalciteProvider extends Provider {
} }
} catch (SQLException e) { } catch (SQLException e) {
DEException.throwException("SQL ERROR: " + e.getMessage()); BusinessException.throwException("SQL ERROR: " + e.getMessage());
} catch (Exception e) { } catch (Exception e) {
DEException.throwException("Datasource connection exception: " + e.getMessage()); BusinessException.throwException("Datasource connection exception: " + e.getMessage());
} finally { } finally {
if (resultSet != null) { if (resultSet != null) {
try { try {
@ -498,7 +498,7 @@ public class CalciteProvider extends Provider {
} }
@Override @Override
public int executeUpdate(DatasourceRequest datasourceRequest) throws DEException { public int executeUpdate(DatasourceRequest datasourceRequest) throws BusinessException {
DatasourceSchemaDTO value = datasourceRequest.getDsList().entrySet().iterator().next().getValue(); DatasourceSchemaDTO value = datasourceRequest.getDsList().entrySet().iterator().next().getValue();
datasourceRequest.setDatasource(value); datasourceRequest.setDatasource(value);
DatasourceConfiguration datasourceConfiguration = JsonUtil.parseObject(datasourceRequest.getDatasource().getConfiguration(), DatasourceConfiguration.class); DatasourceConfiguration datasourceConfiguration = JsonUtil.parseObject(datasourceRequest.getDatasource().getConfiguration(), DatasourceConfiguration.class);
@ -521,9 +521,9 @@ public class CalciteProvider extends Provider {
} }
} catch (SQLException e) { } catch (SQLException e) {
DEException.throwException("SQL ERROR: " + e.getMessage()); BusinessException.throwException("SQL ERROR: " + e.getMessage());
} catch (Exception e) { } catch (Exception e) {
DEException.throwException("Datasource connection exception: " + e.getMessage()); BusinessException.throwException("Datasource connection exception: " + e.getMessage());
} finally { } finally {
if (resultSet != null) { if (resultSet != null) {
try { try {
@ -757,7 +757,7 @@ public class CalciteProvider extends Provider {
Class.forName("org.apache.calcite.jdbc.Driver"); Class.forName("org.apache.calcite.jdbc.Driver");
connection = DriverManager.getConnection("jdbc:calcite:", info); connection = DriverManager.getConnection("jdbc:calcite:", info);
} catch (Exception e) { } catch (Exception e) {
DEException.throwException(e.getMessage()); BusinessException.throwException(e.getMessage());
} }
return connection; return connection;
} }
@ -997,7 +997,7 @@ public class CalciteProvider extends Provider {
list.add(row); list.add(row);
} }
} catch (Exception e) { } catch (Exception e) {
DEException.throwException(e.getMessage()); BusinessException.throwException(e.getMessage());
} }
return list; return list;
} }
@ -1045,21 +1045,21 @@ public class CalciteProvider extends Provider {
case oracle: case oracle:
configuration = JsonUtil.parseObject(datasourceRequest.getDatasource().getConfiguration(), Oracle.class); configuration = JsonUtil.parseObject(datasourceRequest.getDatasource().getConfiguration(), Oracle.class);
if (StringUtils.isEmpty(configuration.getSchema())) { if (StringUtils.isEmpty(configuration.getSchema())) {
DEException.throwException(Translator.get("i18n_schema_is_empty")); BusinessException.throwException(Translator.get("i18n_schema_is_empty"));
} }
sql = String.format("SELECT a.COLUMN_NAME , a.DATA_TYPE , b.COMMENTS ,0 FROM all_tab_columns a LEFT JOIN all_col_comments b ON a.owner = b.owner AND a.table_name = b.table_name AND a.column_name = b.column_name WHERE a.owner = '%s' AND a.table_name = '%s' ORDER BY a.table_name, a.column_id", configuration.getSchema(), datasourceRequest.getTable()); sql = String.format("SELECT a.COLUMN_NAME , a.DATA_TYPE , b.COMMENTS ,0 FROM all_tab_columns a LEFT JOIN all_col_comments b ON a.owner = b.owner AND a.table_name = b.table_name AND a.column_name = b.column_name WHERE a.owner = '%s' AND a.table_name = '%s' ORDER BY a.table_name, a.column_id", configuration.getSchema(), datasourceRequest.getTable());
break; break;
case db2: case db2:
configuration = JsonUtil.parseObject(datasourceRequest.getDatasource().getConfiguration(), Db2.class); configuration = JsonUtil.parseObject(datasourceRequest.getDatasource().getConfiguration(), Db2.class);
if (StringUtils.isEmpty(configuration.getSchema())) { if (StringUtils.isEmpty(configuration.getSchema())) {
DEException.throwException(Translator.get("i18n_schema_is_empty")); BusinessException.throwException(Translator.get("i18n_schema_is_empty"));
} }
sql = String.format("SELECT COLNAME , TYPENAME , REMARKS FROM SYSCAT.COLUMNS WHERE TABSCHEMA = '%s' AND TABNAME = '%s' ", configuration.getSchema(), datasourceRequest.getTable()); sql = String.format("SELECT COLNAME , TYPENAME , REMARKS FROM SYSCAT.COLUMNS WHERE TABSCHEMA = '%s' AND TABNAME = '%s' ", configuration.getSchema(), datasourceRequest.getTable());
break; break;
case sqlServer: case sqlServer:
configuration = JsonUtil.parseObject(datasourceRequest.getDatasource().getConfiguration(), Sqlserver.class); configuration = JsonUtil.parseObject(datasourceRequest.getDatasource().getConfiguration(), Sqlserver.class);
if (StringUtils.isEmpty(configuration.getSchema())) { if (StringUtils.isEmpty(configuration.getSchema())) {
DEException.throwException(Translator.get("i18n_schema_is_empty")); BusinessException.throwException(Translator.get("i18n_schema_is_empty"));
} }
sql = String.format("SELECT \n" + " c.name ,t.name ,ep.value, 0 \n" + "FROM \n" + " sys.columns AS c\n" + "LEFT JOIN sys.extended_properties AS ep ON c.object_id = ep.major_id AND c.column_id = ep.minor_id\n" + "LEFT JOIN sys.types AS t ON c.user_type_id = t.user_type_id\n" + "LEFT JOIN sys.objects AS o ON c.object_id = o.object_id\n" + "WHERE o.name = '%s'", datasourceRequest.getTable()); sql = String.format("SELECT \n" + " c.name ,t.name ,ep.value, 0 \n" + "FROM \n" + " sys.columns AS c\n" + "LEFT JOIN sys.extended_properties AS ep ON c.object_id = ep.major_id AND c.column_id = ep.minor_id\n" + "LEFT JOIN sys.types AS t ON c.user_type_id = t.user_type_id\n" + "LEFT JOIN sys.objects AS o ON c.object_id = o.object_id\n" + "WHERE o.name = '%s'", datasourceRequest.getTable());
@ -1067,7 +1067,7 @@ public class CalciteProvider extends Provider {
case pg: case pg:
configuration = JsonUtil.parseObject(datasourceRequest.getDatasource().getConfiguration(), Pg.class); configuration = JsonUtil.parseObject(datasourceRequest.getDatasource().getConfiguration(), Pg.class);
if (StringUtils.isEmpty(configuration.getSchema())) { if (StringUtils.isEmpty(configuration.getSchema())) {
DEException.throwException(Translator.get("i18n_schema_is_empty")); BusinessException.throwException(Translator.get("i18n_schema_is_empty"));
} }
sql = String.format("SELECT\n" + sql = String.format("SELECT\n" +
" a.attname AS ColumnName,\n" + " a.attname AS ColumnName,\n" +
@ -1122,7 +1122,7 @@ public class CalciteProvider extends Provider {
return sql; return sql;
} }
private List<String> getTablesSql(DatasourceRequest datasourceRequest) throws DEException { private List<String> getTablesSql(DatasourceRequest datasourceRequest) throws BusinessException {
List<String> tableSqls = new ArrayList<>(); List<String> tableSqls = new ArrayList<>();
DatasourceConfiguration.DatasourceType datasourceType = DatasourceConfiguration.DatasourceType.valueOf(datasourceRequest.getDatasource().getType()); DatasourceConfiguration.DatasourceType datasourceType = DatasourceConfiguration.DatasourceType.valueOf(datasourceRequest.getDatasource().getType());
DatasourceConfiguration configuration = null; DatasourceConfiguration configuration = null;
@ -1167,7 +1167,7 @@ public class CalciteProvider extends Provider {
case oracle: case oracle:
configuration = JsonUtil.parseObject(datasourceRequest.getDatasource().getConfiguration(), Oracle.class); configuration = JsonUtil.parseObject(datasourceRequest.getDatasource().getConfiguration(), Oracle.class);
if (StringUtils.isEmpty(configuration.getSchema())) { if (StringUtils.isEmpty(configuration.getSchema())) {
DEException.throwException(Translator.get("i18n_schema_is_empty")); BusinessException.throwException(Translator.get("i18n_schema_is_empty"));
} }
tableSqls.add("select table_name, comments, owner from all_tab_comments where owner='" + configuration.getSchema() + "' AND table_type = 'TABLE'"); tableSqls.add("select table_name, comments, owner from all_tab_comments where owner='" + configuration.getSchema() + "' AND table_type = 'TABLE'");
tableSqls.add("select table_name, comments, owner from all_tab_comments where owner='" + configuration.getSchema() + "' AND table_type = 'VIEW'"); tableSqls.add("select table_name, comments, owner from all_tab_comments where owner='" + configuration.getSchema() + "' AND table_type = 'VIEW'");
@ -1175,14 +1175,14 @@ public class CalciteProvider extends Provider {
case db2: case db2:
configuration = JsonUtil.parseObject(datasourceRequest.getDatasource().getConfiguration(), Db2.class); configuration = JsonUtil.parseObject(datasourceRequest.getDatasource().getConfiguration(), Db2.class);
if (StringUtils.isEmpty(configuration.getSchema())) { if (StringUtils.isEmpty(configuration.getSchema())) {
DEException.throwException(Translator.get("i18n_schema_is_empty")); BusinessException.throwException(Translator.get("i18n_schema_is_empty"));
} }
tableSqls.add("select TABNAME, REMARKS from syscat.tables WHERE TABSCHEMA ='DE_SCHEMA' AND \"TYPE\" = 'T'".replace("DE_SCHEMA", configuration.getSchema())); tableSqls.add("select TABNAME, REMARKS from syscat.tables WHERE TABSCHEMA ='DE_SCHEMA' AND \"TYPE\" = 'T'".replace("DE_SCHEMA", configuration.getSchema()));
break; break;
case sqlServer: case sqlServer:
configuration = JsonUtil.parseObject(datasourceRequest.getDatasource().getConfiguration(), Sqlserver.class); configuration = JsonUtil.parseObject(datasourceRequest.getDatasource().getConfiguration(), Sqlserver.class);
if (StringUtils.isEmpty(configuration.getSchema())) { if (StringUtils.isEmpty(configuration.getSchema())) {
DEException.throwException(Translator.get("i18n_schema_is_empty")); BusinessException.throwException(Translator.get("i18n_schema_is_empty"));
} }
tableSqls.add("SELECT \n" + " t.name AS TableName, \n" + " ep.value AS TableDescription \n" + "FROM \n" + " sys.tables t \n" + "LEFT OUTER JOIN sys.schemas sc ON sc.schema_id =t.schema_id \n" + "LEFT OUTER JOIN \n" + " sys.extended_properties ep ON t.object_id = ep.major_id \n" + " AND ep.minor_id = 0 \n" + " AND ep.class = 1 \n" + " AND ep.name = 'MS_Description'\n" + "where sc.name ='DS_SCHEMA'".replace("DS_SCHEMA", configuration.getSchema())); tableSqls.add("SELECT \n" + " t.name AS TableName, \n" + " ep.value AS TableDescription \n" + "FROM \n" + " sys.tables t \n" + "LEFT OUTER JOIN sys.schemas sc ON sc.schema_id =t.schema_id \n" + "LEFT OUTER JOIN \n" + " sys.extended_properties ep ON t.object_id = ep.major_id \n" + " AND ep.minor_id = 0 \n" + " AND ep.class = 1 \n" + " AND ep.name = 'MS_Description'\n" + "where sc.name ='DS_SCHEMA'".replace("DS_SCHEMA", configuration.getSchema()));
tableSqls.add("SELECT \n" + " t.name AS TableName, \n" + " ep.value AS TableDescription \n" + "FROM \n" + " sys.views t \n" + "LEFT OUTER JOIN sys.schemas sc ON sc.schema_id =t.schema_id \n" + "LEFT OUTER JOIN \n" + " sys.extended_properties ep ON t.object_id = ep.major_id \n" + " AND ep.minor_id = 0 \n" + " AND ep.class = 1 \n" + " AND ep.name = 'MS_Description'\n" + "where sc.name ='DS_SCHEMA'".replace("DS_SCHEMA", configuration.getSchema())); tableSqls.add("SELECT \n" + " t.name AS TableName, \n" + " ep.value AS TableDescription \n" + "FROM \n" + " sys.views t \n" + "LEFT OUTER JOIN sys.schemas sc ON sc.schema_id =t.schema_id \n" + "LEFT OUTER JOIN \n" + " sys.extended_properties ep ON t.object_id = ep.major_id \n" + " AND ep.minor_id = 0 \n" + " AND ep.class = 1 \n" + " AND ep.name = 'MS_Description'\n" + "where sc.name ='DS_SCHEMA'".replace("DS_SCHEMA", configuration.getSchema()));
@ -1190,7 +1190,7 @@ public class CalciteProvider extends Provider {
case pg: case pg:
configuration = JsonUtil.parseObject(datasourceRequest.getDatasource().getConfiguration(), Pg.class); configuration = JsonUtil.parseObject(datasourceRequest.getDatasource().getConfiguration(), Pg.class);
if (StringUtils.isEmpty(configuration.getSchema())) { if (StringUtils.isEmpty(configuration.getSchema())) {
DEException.throwException(Translator.get("i18n_schema_is_empty")); BusinessException.throwException(Translator.get("i18n_schema_is_empty"));
} }
tableSqls.add("SELECT \n" + " relname AS TableName, \n" + " obj_description(relfilenode::regclass, 'pg_class') AS TableDescription \n" + "FROM \n" + " pg_class \n" + "WHERE \n" + " relkind in ('r','p', 'f') \n" + " AND relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = 'SCHEMA') ".replace("SCHEMA", configuration.getSchema())); tableSqls.add("SELECT \n" + " relname AS TableName, \n" + " obj_description(relfilenode::regclass, 'pg_class') AS TableDescription \n" + "FROM \n" + " pg_class \n" + "WHERE \n" + " relkind in ('r','p', 'f') \n" + " AND relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = 'SCHEMA') ".replace("SCHEMA", configuration.getSchema()));
break; break;
@ -1224,7 +1224,7 @@ public class CalciteProvider extends Provider {
} }
private String getSchemaSql(DatasourceDTO datasource) throws DEException { private String getSchemaSql(DatasourceDTO datasource) throws BusinessException {
DatasourceConfiguration.DatasourceType datasourceType = DatasourceConfiguration.DatasourceType.valueOf(datasource.getType()); DatasourceConfiguration.DatasourceType datasourceType = DatasourceConfiguration.DatasourceType.valueOf(datasource.getType());
switch (datasourceType) { switch (datasourceType) {
case oracle: case oracle:
@ -1245,14 +1245,14 @@ public class CalciteProvider extends Provider {
public Statement getStatement(Connection connection, int queryTimeout) { public Statement getStatement(Connection connection, int queryTimeout) {
if (connection == null) { if (connection == null) {
DEException.throwException("Failed to get connection!"); BusinessException.throwException("Failed to get connection!");
} }
Statement stat = null; Statement stat = null;
try { try {
stat = connection.createStatement(); stat = connection.createStatement();
stat.setQueryTimeout(queryTimeout); stat.setQueryTimeout(queryTimeout);
} catch (Exception e) { } catch (Exception e) {
DEException.throwException(e.getMessage()); BusinessException.throwException(e.getMessage());
} }
return stat; return stat;
} }
@ -1267,7 +1267,7 @@ public class CalciteProvider extends Provider {
stat = connection.prepareStatement(sql); stat = connection.prepareStatement(sql);
stat.setQueryTimeout(queryTimeout); stat.setQueryTimeout(queryTimeout);
} catch (Exception e) { } catch (Exception e) {
DEException.throwException(e.getMessage()); BusinessException.throwException(e.getMessage());
} }
return stat; return stat;
} else { } else {
@ -1281,7 +1281,7 @@ public class CalciteProvider extends Provider {
protected ExtendedJdbcClassLoader getCustomJdbcClassLoader(CoreDriver coreDriver) { protected ExtendedJdbcClassLoader getCustomJdbcClassLoader(CoreDriver coreDriver) {
if (coreDriver == null) { if (coreDriver == null) {
DEException.throwException("Can not found custom Driver"); BusinessException.throwException("Can not found custom Driver");
} }
ExtendedJdbcClassLoader customJdbcClassLoader = customJdbcClassLoaders.get(coreDriver.getId()); ExtendedJdbcClassLoader customJdbcClassLoader = customJdbcClassLoaders.get(coreDriver.getId());
if (customJdbcClassLoader == null) { if (customJdbcClassLoader == null) {
@ -1323,7 +1323,7 @@ public class CalciteProvider extends Provider {
customJdbcClassLoaders.put(coreDriver.getId(), customJdbcClassLoader); customJdbcClassLoaders.put(coreDriver.getId(), customJdbcClassLoader);
return customJdbcClassLoader; return customJdbcClassLoader;
} catch (Exception e) { } catch (Exception e) {
DEException.throwException(e.getMessage()); BusinessException.throwException(e.getMessage());
} }
return null; return null;
} }
@ -1357,7 +1357,7 @@ public class CalciteProvider extends Provider {
} }
public void update(DatasourceDTO datasourceDTO) throws DEException { public void update(DatasourceDTO datasourceDTO) throws BusinessException {
DatasourceSchemaDTO datasourceSchemaDTO = new DatasourceSchemaDTO(); DatasourceSchemaDTO datasourceSchemaDTO = new DatasourceSchemaDTO();
BeanUtils.copyBean(datasourceSchemaDTO, datasourceDTO); BeanUtils.copyBean(datasourceSchemaDTO, datasourceDTO);
datasourceSchemaDTO.setSchemaAlias(String.format(SQLConstants.SCHEMA, datasourceSchemaDTO.getId())); datasourceSchemaDTO.setSchemaAlias(String.format(SQLConstants.SCHEMA, datasourceSchemaDTO.getId()));
@ -1367,11 +1367,11 @@ public class CalciteProvider extends Provider {
CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class); CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class);
SchemaPlus rootSchema = buildSchema(datasourceRequest, calciteConnection); SchemaPlus rootSchema = buildSchema(datasourceRequest, calciteConnection);
} catch (Exception e) { } catch (Exception e) {
DEException.throwException(e.getMessage()); BusinessException.throwException(e.getMessage());
} }
} }
public void updateDsPoolAfterCheckStatus(DatasourceDTO datasourceDTO) throws DEException { public void updateDsPoolAfterCheckStatus(DatasourceDTO datasourceDTO) throws BusinessException {
DatasourceSchemaDTO datasourceSchemaDTO = new DatasourceSchemaDTO(); DatasourceSchemaDTO datasourceSchemaDTO = new DatasourceSchemaDTO();
BeanUtils.copyBean(datasourceSchemaDTO, datasourceDTO); BeanUtils.copyBean(datasourceSchemaDTO, datasourceDTO);
datasourceSchemaDTO.setSchemaAlias(String.format(SQLConstants.SCHEMA, datasourceSchemaDTO.getId())); datasourceSchemaDTO.setSchemaAlias(String.format(SQLConstants.SCHEMA, datasourceSchemaDTO.getId()));
@ -1391,11 +1391,11 @@ public class CalciteProvider extends Provider {
startSshSession(configuration, null, datasourceDTO.getId()); startSshSession(configuration, null, datasourceDTO.getId());
} }
} catch (Exception e) { } catch (Exception e) {
DEException.throwException(e.getMessage()); BusinessException.throwException(e.getMessage());
} }
} }
public void delete(CoreDatasource datasource) throws DEException { public void delete(CoreDatasource datasource) throws BusinessException {
DatasourceSchemaDTO datasourceSchemaDTO = new DatasourceSchemaDTO(); DatasourceSchemaDTO datasourceSchemaDTO = new DatasourceSchemaDTO();
BeanUtils.copyBean(datasourceSchemaDTO, datasource); BeanUtils.copyBean(datasourceSchemaDTO, datasource);
datasourceSchemaDTO.setSchemaAlias(String.format(SQLConstants.SCHEMA, datasourceSchemaDTO.getId())); datasourceSchemaDTO.setSchemaAlias(String.format(SQLConstants.SCHEMA, datasourceSchemaDTO.getId()));
@ -1409,7 +1409,7 @@ public class CalciteProvider extends Provider {
rootSchema.removeSubSchema(datasourceSchemaDTO.getSchemaAlias()); rootSchema.removeSubSchema(datasourceSchemaDTO.getSchemaAlias());
} }
} catch (Exception e) { } catch (Exception e) {
DEException.throwException(e.getMessage()); BusinessException.throwException(e.getMessage());
} }
Provider.getLPorts().remove(datasource.getId()); Provider.getLPorts().remove(datasource.getId());
if (Provider.getSessions().get(datasource.getId()) != null) { if (Provider.getSessions().get(datasource.getId()) != null) {
@ -1435,13 +1435,13 @@ public class CalciteProvider extends Provider {
CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class); CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class);
SchemaPlus rootSchema = calciteConnection.getRootSchema(); SchemaPlus rootSchema = calciteConnection.getRootSchema();
if (rootSchema.getSubSchema(String.format(SQLConstants.SCHEMA, dsId)) == null) { if (rootSchema.getSubSchema(String.format(SQLConstants.SCHEMA, dsId)) == null) {
DEException.throwException(Translator.get("i18n_check_datasource_connection")); BusinessException.throwException(Translator.get("i18n_check_datasource_connection"));
} }
JdbcSchema jdbcSchema = rootSchema.getSubSchema(String.format(SQLConstants.SCHEMA, dsId)).unwrap(JdbcSchema.class); JdbcSchema jdbcSchema = rootSchema.getSubSchema(String.format(SQLConstants.SCHEMA, dsId)).unwrap(JdbcSchema.class);
BasicDataSource basicDataSource = (BasicDataSource) jdbcSchema.getDataSource(); BasicDataSource basicDataSource = (BasicDataSource) jdbcSchema.getDataSource();
return basicDataSource.getConnection(); return basicDataSource.getConnection();
} catch (Exception e) { } catch (Exception e) {
DEException.throwException(Translator.get("i18n_invalid_connection") + e.getMessage()); BusinessException.throwException(Translator.get("i18n_invalid_connection") + e.getMessage());
} }
return null; return null;
} }

View File

@ -1,74 +0,0 @@
package io.gisbi.i18n;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import java.util.Locale;
/**
* 简单的国际化翻译器实现
* 替代缺失的外部依赖
*/
public class Translator {
public static MessageSource messageSource;
/**
* 获取国际化消息
* @param key 消息键
* @return 国际化消息
*/
public static String get(String key) {
if (messageSource == null) {
// 如果messageSource为null返回默认消息
return getDefaultMessage(key);
}
try {
Locale locale = LocaleContextHolder.getLocale();
return messageSource.getMessage(key, null, locale);
} catch (Exception e) {
// 如果获取消息失败返回默认消息
return getDefaultMessage(key);
}
}
/**
* 获取带参数的国际化消息
* @param key 消息键
* @param args 参数
* @return 国际化消息
*/
public static String get(String key, Object... args) {
if (messageSource == null) {
return getDefaultMessage(key);
}
try {
Locale locale = LocaleContextHolder.getLocale();
return messageSource.getMessage(key, args, locale);
} catch (Exception e) {
return getDefaultMessage(key);
}
}
/**
* 获取默认消息
* @param key 消息键
* @return 默认消息
*/
private static String getDefaultMessage(String key) {
switch (key) {
case "i18n_fetch_error":
return "数据获取错误: ";
case "i18n_schema_is_empty":
return "数据库模式为空";
case "i18n_check_datasource_connection":
return "请检查数据源连接";
case "i18n_invalid_connection":
return "无效的数据库连接: ";
default:
return key; // 如果没有找到对应的消息返回键本身
}
}
}