mirror of
https://github.com/dataease/dataease.git
synced 2025-02-24 19:42:56 +08:00
feat: Oracle 数据源指定字符集
This commit is contained in:
parent
a5d8d6cbbb
commit
08afbe5e2d
@ -26,6 +26,9 @@ public class ProviderFactory implements ApplicationContextAware {
|
||||
final ConfigurableListableBeanFactory beanFactory = ((ConfigurableApplicationContext) context).getBeanFactory();
|
||||
if(d.isDatasource()){
|
||||
DataSourceType dataSourceType = new DataSourceType(d.getType(), d.getName(), false, d.getExtraParams(), d.getCalculationMode());
|
||||
if(dataSourceType.getType().equalsIgnoreCase("oracle")){
|
||||
dataSourceType.setCharset(d.getCharset());
|
||||
}
|
||||
beanFactory.registerSingleton(d.getType(), dataSourceType);
|
||||
}
|
||||
}
|
||||
|
@ -195,7 +195,7 @@ public class JdbcProvider extends DefaultJdbcProvider {
|
||||
try (Connection connection = getConnectionFromPool(datasourceRequest); Statement stat = connection.createStatement(); ResultSet rs = stat.executeQuery(datasourceRequest.getQuery())) {
|
||||
fieldList = fetchResultField(rs, datasourceRequest);
|
||||
result.put("fieldList", fieldList);
|
||||
dataList = getDataResult(rs);
|
||||
dataList = getDataResult(rs, datasourceRequest);
|
||||
result.put("dataList", dataList);
|
||||
return result;
|
||||
} catch (SQLException e) {
|
||||
@ -206,7 +206,14 @@ public class JdbcProvider extends DefaultJdbcProvider {
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
private List<String[]> getDataResult(ResultSet rs) throws Exception {
|
||||
private List<String[]> getDataResult(ResultSet rs, DatasourceRequest datasourceRequest) throws Exception {
|
||||
String charset = null;
|
||||
if(datasourceRequest != null && datasourceRequest.getDatasource().getType().equalsIgnoreCase("oracle")){
|
||||
JdbcConfiguration JdbcConfiguration = new Gson().fromJson(datasourceRequest.getDatasource().getConfiguration(), JdbcConfiguration.class);
|
||||
if(StringUtils.isNotEmpty(JdbcConfiguration.getCharset()) && !JdbcConfiguration.getCharset().equalsIgnoreCase("Default") ){
|
||||
charset = JdbcConfiguration.getCharset();
|
||||
}
|
||||
}
|
||||
List<String[]> list = new LinkedList<>();
|
||||
ResultSetMetaData metaData = rs.getMetaData();
|
||||
int columnCount = metaData.getColumnCount();
|
||||
@ -224,7 +231,11 @@ public class JdbcProvider extends DefaultJdbcProvider {
|
||||
row[j] = rs.getBoolean(j + 1) ? "1" : "0";
|
||||
break;
|
||||
default:
|
||||
row[j] = rs.getString(j + 1);
|
||||
if(charset != null && StringUtils.isNotEmpty(rs.getString(j + 1))){
|
||||
row[j] = new String(rs.getString(j + 1).getBytes(charset), "UTF-8");
|
||||
}else {
|
||||
row[j] = rs.getString(j + 1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -265,6 +276,23 @@ public class JdbcProvider extends DefaultJdbcProvider {
|
||||
}
|
||||
return fieldList;
|
||||
}
|
||||
@Override
|
||||
public List<String[]> getData(DatasourceRequest dsr) throws Exception {
|
||||
List<String[]> list = new LinkedList<>();
|
||||
try (Connection connection = getConnectionFromPool(dsr); Statement stat = connection.createStatement(); ResultSet rs = stat.executeQuery(dsr.getQuery())) {
|
||||
list = getDataResult(rs, dsr);
|
||||
if (dsr.isPageable() && (dsr.getDatasource().getType().equalsIgnoreCase(DatasourceTypes.sqlServer.name()) || dsr.getDatasource().getType().equalsIgnoreCase(DatasourceTypes.db2.name()))) {
|
||||
Integer realSize = dsr.getPage() * dsr.getPageSize() < list.size() ? dsr.getPage() * dsr.getPageSize() : list.size();
|
||||
list = list.subList((dsr.getPage() - 1) * dsr.getPageSize(), realSize);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
io.dataease.plugins.common.exception.DataEaseException.throwException("SQL ERROR" + e.getMessage());
|
||||
} catch (Exception e) {
|
||||
io.dataease.plugins.common.exception.DataEaseException.throwException("Data source connection exception: " + e.getMessage());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection getConnection(DatasourceRequest datasourceRequest) throws Exception {
|
||||
@ -398,7 +426,12 @@ public class JdbcProvider extends DefaultJdbcProvider {
|
||||
dataSource.setDriverClassName(oracleConfiguration.getDriver());
|
||||
dataSource.setUrl(oracleConfiguration.getJdbc());
|
||||
dataSource.setValidationQuery("select 1 from dual");
|
||||
jdbcConfiguration = oracleConfiguration;
|
||||
if(StringUtils.isNotEmpty(oracleConfiguration.getCharset()) && !oracleConfiguration.getCharset().equalsIgnoreCase("Default")){
|
||||
Properties props = new Properties();
|
||||
props.put("serverEncoding", oracleConfiguration.getCharset());
|
||||
props.put("clientEncoding", "UTF-8");
|
||||
jdbcConfiguration = oracleConfiguration;
|
||||
}
|
||||
break;
|
||||
case pg:
|
||||
PgConfiguration pgConfiguration = new Gson().fromJson(datasourceRequest.getDatasource().getConfiguration(), PgConfiguration.class);
|
||||
|
@ -1350,6 +1350,8 @@ export default {
|
||||
get_schema: 'Get Schema',
|
||||
schema: 'Database Schema',
|
||||
please_choose_schema: 'Please select Schema',
|
||||
charset: 'Charset',
|
||||
please_choose_charset: 'Please select Charset',
|
||||
edit_datasource_msg: 'Modifying the data source information may make the data set under the modified data source unavailable. Confirm the modification?',
|
||||
repeat_datasource_msg: 'Data source information with the same configuration already exists, ',
|
||||
confirm_save: 'Confirm save?',
|
||||
|
@ -1351,6 +1351,8 @@ export default {
|
||||
get_schema: '獲取 Schema',
|
||||
schema: '數據庫 Schema',
|
||||
please_choose_schema: '請選擇數據庫 Schema',
|
||||
charset: '字符集',
|
||||
please_choose_charset: '請選擇數據庫字符集',
|
||||
edit_datasource_msg: '修改數據源信息,可能會導致改數據源下的數據集不可用,確認修改?',
|
||||
repeat_datasource_msg: '已經存在相同配置的數據源信息,',
|
||||
confirm_save: '確認保存?',
|
||||
|
@ -1357,7 +1357,9 @@ export default {
|
||||
oracle_service_name: '服务名',
|
||||
get_schema: '获取 Schema',
|
||||
schema: '数据库 Schema',
|
||||
charset: '字符集',
|
||||
please_choose_schema: '请选择数据库 Schema',
|
||||
please_choose_charset: '请选择数据库字符集',
|
||||
edit_datasource_msg: '修改数据源信息,可能会导致该数据源下的数据集不可用,确认修改?',
|
||||
repeat_datasource_msg: '已经存在相同配置的数据源信息, ',
|
||||
confirm_save: '确认保存?',
|
||||
|
@ -177,6 +177,13 @@
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item v-if="form.type=='oracle'" :label="$t('datasource.charset')">
|
||||
<el-select v-model="form.configuration.charset" filterable :placeholder="$t('datasource.please_choose_charset')"
|
||||
class="select-width">
|
||||
<el-option v-for="item in datasourceType.charset" :key="item" :label="item" :value="item"/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
|
||||
<el-collapse v-if="form.type !=='es' && form.type !== 'api' && form.type !== 'mongo'">
|
||||
<el-collapse-item :title="$t('datasource.priority')" name="1">
|
||||
<el-form-item :label="$t('datasource.initial_pool_size')" prop="configuration.initialPoolSize">
|
||||
@ -203,7 +210,7 @@
|
||||
|
||||
|
||||
import i18n from "@/lang";
|
||||
import {checkApiDatasource} from "@/api/system/datasource";
|
||||
import {checkApiDatasource, getSchema} from "@/api/system/datasource";
|
||||
import ApiHttpRequestForm from '@/views/system/datasource/ApiHttpRequestForm'
|
||||
import LayoutContent from '@/components/business/LayoutContent'
|
||||
|
||||
@ -223,6 +230,7 @@ export default {
|
||||
method: String,
|
||||
request: {},
|
||||
response: {},
|
||||
datasourceType: {},
|
||||
showScript: {
|
||||
type: Boolean,
|
||||
default: true,
|
||||
@ -369,7 +377,20 @@ export default {
|
||||
|
||||
},
|
||||
methods: {
|
||||
|
||||
getSchema() {
|
||||
this.$refs.DsConfig.validate(valid => {
|
||||
if (valid) {
|
||||
const data = JSON.parse(JSON.stringify(this.form))
|
||||
data.configuration = JSON.stringify(data.configuration)
|
||||
getSchema(data).then(res => {
|
||||
this.schemas = res.data
|
||||
this.$success(i18n.t('commons.success'))
|
||||
})
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
})
|
||||
},
|
||||
next() {
|
||||
if (this.active === 1) {
|
||||
let hasRepeatName = false
|
||||
|
@ -41,7 +41,7 @@
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
|
||||
<ds-configuration ref="dsConfig" v-if="!datasourceType.isPlugin" :form="form" :disabled="params && params.id && params.showModel && params.showModel === 'show' && !canEdit"></ds-configuration>
|
||||
<ds-configuration ref="dsConfig" v-if="!datasourceType.isPlugin" :datasource-type='datasourceType' :form="form" :disabled="params && params.id && params.showModel && params.showModel === 'show' && !canEdit"></ds-configuration>
|
||||
<plugin-com ref="pluginDsConfig" v-if="datasourceType.isPlugin" :component-name="datasourceType.type" :obj="{form, disabled }" />
|
||||
|
||||
|
||||
@ -352,7 +352,7 @@ export default {
|
||||
if(this.datasourceType.isPlugin){
|
||||
status = this.$refs['pluginDsConfig'].callPluginInner({methodName: 'validate'})
|
||||
}else {
|
||||
status = this.$refs['dsConfig'].$refs['DsConfig'].validate(valid => {
|
||||
this.$refs['dsConfig'].$refs['DsConfig'].validate(valid => {
|
||||
status = valid
|
||||
})
|
||||
}
|
||||
@ -424,7 +424,6 @@ export default {
|
||||
})
|
||||
},
|
||||
validaDatasource() {
|
||||
console.log(this.$refs)
|
||||
if (!this.form.configuration.schema && this.form.type === 'oracle') {
|
||||
this.$message.error(i18n.t('datasource.please_choose_schema'))
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user