forked from github/dataease
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();
|
final ConfigurableListableBeanFactory beanFactory = ((ConfigurableApplicationContext) context).getBeanFactory();
|
||||||
if(d.isDatasource()){
|
if(d.isDatasource()){
|
||||||
DataSourceType dataSourceType = new DataSourceType(d.getType(), d.getName(), false, d.getExtraParams(), d.getCalculationMode());
|
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);
|
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())) {
|
try (Connection connection = getConnectionFromPool(datasourceRequest); Statement stat = connection.createStatement(); ResultSet rs = stat.executeQuery(datasourceRequest.getQuery())) {
|
||||||
fieldList = fetchResultField(rs, datasourceRequest);
|
fieldList = fetchResultField(rs, datasourceRequest);
|
||||||
result.put("fieldList", fieldList);
|
result.put("fieldList", fieldList);
|
||||||
dataList = getDataResult(rs);
|
dataList = getDataResult(rs, datasourceRequest);
|
||||||
result.put("dataList", dataList);
|
result.put("dataList", dataList);
|
||||||
return result;
|
return result;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
@ -206,7 +206,14 @@ public class JdbcProvider extends DefaultJdbcProvider {
|
|||||||
return new HashMap<>();
|
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<>();
|
List<String[]> list = new LinkedList<>();
|
||||||
ResultSetMetaData metaData = rs.getMetaData();
|
ResultSetMetaData metaData = rs.getMetaData();
|
||||||
int columnCount = metaData.getColumnCount();
|
int columnCount = metaData.getColumnCount();
|
||||||
@ -224,7 +231,11 @@ public class JdbcProvider extends DefaultJdbcProvider {
|
|||||||
row[j] = rs.getBoolean(j + 1) ? "1" : "0";
|
row[j] = rs.getBoolean(j + 1) ? "1" : "0";
|
||||||
break;
|
break;
|
||||||
default:
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -265,6 +276,23 @@ public class JdbcProvider extends DefaultJdbcProvider {
|
|||||||
}
|
}
|
||||||
return fieldList;
|
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
|
@Override
|
||||||
public Connection getConnection(DatasourceRequest datasourceRequest) throws Exception {
|
public Connection getConnection(DatasourceRequest datasourceRequest) throws Exception {
|
||||||
@ -398,7 +426,12 @@ public class JdbcProvider extends DefaultJdbcProvider {
|
|||||||
dataSource.setDriverClassName(oracleConfiguration.getDriver());
|
dataSource.setDriverClassName(oracleConfiguration.getDriver());
|
||||||
dataSource.setUrl(oracleConfiguration.getJdbc());
|
dataSource.setUrl(oracleConfiguration.getJdbc());
|
||||||
dataSource.setValidationQuery("select 1 from dual");
|
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;
|
break;
|
||||||
case pg:
|
case pg:
|
||||||
PgConfiguration pgConfiguration = new Gson().fromJson(datasourceRequest.getDatasource().getConfiguration(), PgConfiguration.class);
|
PgConfiguration pgConfiguration = new Gson().fromJson(datasourceRequest.getDatasource().getConfiguration(), PgConfiguration.class);
|
||||||
|
@ -1350,6 +1350,8 @@ export default {
|
|||||||
get_schema: 'Get Schema',
|
get_schema: 'Get Schema',
|
||||||
schema: 'Database Schema',
|
schema: 'Database Schema',
|
||||||
please_choose_schema: 'Please select 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?',
|
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, ',
|
repeat_datasource_msg: 'Data source information with the same configuration already exists, ',
|
||||||
confirm_save: 'Confirm save?',
|
confirm_save: 'Confirm save?',
|
||||||
|
@ -1351,6 +1351,8 @@ export default {
|
|||||||
get_schema: '獲取 Schema',
|
get_schema: '獲取 Schema',
|
||||||
schema: '數據庫 Schema',
|
schema: '數據庫 Schema',
|
||||||
please_choose_schema: '請選擇數據庫 Schema',
|
please_choose_schema: '請選擇數據庫 Schema',
|
||||||
|
charset: '字符集',
|
||||||
|
please_choose_charset: '請選擇數據庫字符集',
|
||||||
edit_datasource_msg: '修改數據源信息,可能會導致改數據源下的數據集不可用,確認修改?',
|
edit_datasource_msg: '修改數據源信息,可能會導致改數據源下的數據集不可用,確認修改?',
|
||||||
repeat_datasource_msg: '已經存在相同配置的數據源信息,',
|
repeat_datasource_msg: '已經存在相同配置的數據源信息,',
|
||||||
confirm_save: '確認保存?',
|
confirm_save: '確認保存?',
|
||||||
|
@ -1357,7 +1357,9 @@ export default {
|
|||||||
oracle_service_name: '服务名',
|
oracle_service_name: '服务名',
|
||||||
get_schema: '获取 Schema',
|
get_schema: '获取 Schema',
|
||||||
schema: '数据库 Schema',
|
schema: '数据库 Schema',
|
||||||
|
charset: '字符集',
|
||||||
please_choose_schema: '请选择数据库 Schema',
|
please_choose_schema: '请选择数据库 Schema',
|
||||||
|
please_choose_charset: '请选择数据库字符集',
|
||||||
edit_datasource_msg: '修改数据源信息,可能会导致该数据源下的数据集不可用,确认修改?',
|
edit_datasource_msg: '修改数据源信息,可能会导致该数据源下的数据集不可用,确认修改?',
|
||||||
repeat_datasource_msg: '已经存在相同配置的数据源信息, ',
|
repeat_datasource_msg: '已经存在相同配置的数据源信息, ',
|
||||||
confirm_save: '确认保存?',
|
confirm_save: '确认保存?',
|
||||||
|
@ -177,6 +177,13 @@
|
|||||||
</el-select>
|
</el-select>
|
||||||
</el-form-item>
|
</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 v-if="form.type !=='es' && form.type !== 'api' && form.type !== 'mongo'">
|
||||||
<el-collapse-item :title="$t('datasource.priority')" name="1">
|
<el-collapse-item :title="$t('datasource.priority')" name="1">
|
||||||
<el-form-item :label="$t('datasource.initial_pool_size')" prop="configuration.initialPoolSize">
|
<el-form-item :label="$t('datasource.initial_pool_size')" prop="configuration.initialPoolSize">
|
||||||
@ -203,7 +210,7 @@
|
|||||||
|
|
||||||
|
|
||||||
import i18n from "@/lang";
|
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 ApiHttpRequestForm from '@/views/system/datasource/ApiHttpRequestForm'
|
||||||
import LayoutContent from '@/components/business/LayoutContent'
|
import LayoutContent from '@/components/business/LayoutContent'
|
||||||
|
|
||||||
@ -223,6 +230,7 @@ export default {
|
|||||||
method: String,
|
method: String,
|
||||||
request: {},
|
request: {},
|
||||||
response: {},
|
response: {},
|
||||||
|
datasourceType: {},
|
||||||
showScript: {
|
showScript: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: true,
|
default: true,
|
||||||
@ -369,7 +377,20 @@ export default {
|
|||||||
|
|
||||||
},
|
},
|
||||||
methods: {
|
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() {
|
next() {
|
||||||
if (this.active === 1) {
|
if (this.active === 1) {
|
||||||
let hasRepeatName = false
|
let hasRepeatName = false
|
||||||
|
@ -41,7 +41,7 @@
|
|||||||
</el-select>
|
</el-select>
|
||||||
</el-form-item>
|
</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 }" />
|
<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){
|
if(this.datasourceType.isPlugin){
|
||||||
status = this.$refs['pluginDsConfig'].callPluginInner({methodName: 'validate'})
|
status = this.$refs['pluginDsConfig'].callPluginInner({methodName: 'validate'})
|
||||||
}else {
|
}else {
|
||||||
status = this.$refs['dsConfig'].$refs['DsConfig'].validate(valid => {
|
this.$refs['dsConfig'].$refs['DsConfig'].validate(valid => {
|
||||||
status = valid
|
status = valid
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -424,7 +424,6 @@ export default {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
validaDatasource() {
|
validaDatasource() {
|
||||||
console.log(this.$refs)
|
|
||||||
if (!this.form.configuration.schema && this.form.type === 'oracle') {
|
if (!this.form.configuration.schema && this.form.type === 'oracle') {
|
||||||
this.$message.error(i18n.t('datasource.please_choose_schema'))
|
this.$message.error(i18n.t('datasource.please_choose_schema'))
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user