Skip to content

Commit

Permalink
Remove dsTypeId on definition of dsModelTypeKey
Browse files Browse the repository at this point in the history
  • Loading branch information
jefftlin committed Nov 17, 2024
1 parent 49c7f3a commit 2a50723
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

public class DataSourceModelTypeKey extends DataSourceParamKeyDefinition {

private Long dsTypeId;

private String dsType;

private DataSourceParamKeyDefinition.ValueType nestType;
Expand All @@ -21,14 +19,6 @@ public class DataSourceModelTypeKey extends DataSourceParamKeyDefinition {

private Date modifyTime;

public Long getDsTypeId() {
return dsTypeId;
}

public void setDsTypeId(Long dsTypeId) {
this.dsTypeId = dsTypeId;
}

public String getDsType() {
return dsType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public boolean isPrimitive(Class<?> type) {

public static void main(String[] args) {
DataSourceModelTypeKey typeKey = new DataSourceModelTypeKey();
typeKey.setDsTypeId(9L);
typeKey.setDsType("tdsql");
typeKey.setKey("params");
typeKey.setName("连接参数");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package com.webank.wedatasphere.exchangis.datasource.core.splitter;


import com.webank.wedatasphere.exchangis.common.util.json.JsonEntity;
import com.webank.wedatasphere.exchangis.datasource.core.utils.Json;
import org.apache.commons.lang.StringUtils;

import java.util.*;
import java.util.function.BiConsumer;

/**
* Split strategy: field split
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<mapper namespace="com.webank.wedatasphere.exchangis.datasource.mapper.DataSourceModelTypeKeyMapper">
<resultMap id="dsTypeKey" type="com.webank.wedatasphere.exchangis.datasource.core.domain.DataSourceModelTypeKey">
<result property="id" column="id"/>
<result property="dsTypeId" column="ds_type_id"/>
<result property="dsType" column="ds_type"/>
<result property="key" column="key"/>
<result property="name" column="name"/>
Expand All @@ -29,7 +28,7 @@
</sql>

<sql id="columns">
id,ds_type_id,ds_type,`key`,name,
id,ds_type,`key`,name,
default_value,value_type,value_regex,nest_type,nest_fields,is_serialize,
`scope`,`require`,description,
ref_id,ref_value,
Expand Down Expand Up @@ -62,9 +61,6 @@
<if test="id != null and id != ''">
AND id = #{id}
</if>
<if test="dsTypeId != null and dsTypeId != ''">
AND ds_type_id = #{dsTypeId}
</if>
<if test="dsType != null and dsType != ''">
AND ds_type = #{dsType}
</if>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,22 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.RowBounds;
import org.apache.linkis.datasource.client.impl.LinkisDataSourceRemoteClient;
import org.apache.linkis.datasource.client.request.GetAllDataSourceTypesAction;
import org.apache.linkis.datasource.client.request.GetKeyTypeDatasourceAction;
import org.apache.linkis.datasource.client.response.GetAllDataSourceTypesResult;
import org.apache.linkis.datasource.client.response.GetKeyTypeDatasourceResult;
import org.apache.linkis.datasourcemanager.common.domain.DataSourceParamKeyDefinition;
import org.apache.linkis.datasourcemanager.common.domain.DataSourceType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;

import static com.webank.wedatasphere.exchangis.datasource.core.exception.ExchangisDataSourceExceptionCode.CLIENT_DATASOURCE_GET_KEY_DEFINES_ERROR;
import static com.webank.wedatasphere.exchangis.datasource.core.exception.ExchangisDataSourceExceptionCode.CLIENT_DATASOURCE_GET_TYPES_ERROR;

@Service
public class DataSourceModelTypeKeyServiceImpl extends AbstractLinkisDataSourceService implements DataSourceModelTypeKeyService {
Expand All @@ -34,6 +39,31 @@ public class DataSourceModelTypeKeyServiceImpl extends AbstractLinkisDataSourceS
@Resource
private DataSourceModelTypeKeyMapper dataSourceModelTypeKeyMapper;

private Map<String, String> dsTypeMap = null;

public Long getDsTypeIdByName(String operator, String dsName) throws ExchangisDataSourceException {
if (Objects.isNull(dsTypeMap)) {
synchronized(this) {
dsTypeMap = new HashMap<>();
GetAllDataSourceTypesResult result = rpcSend(ExchangisLinkisRemoteClient.getLinkisDataSourceRemoteClient(), () -> GetAllDataSourceTypesAction.builder()
.setUser(operator)
.build(),
LinkisDataSourceRemoteClient::getAllDataSourceTypes, CLIENT_DATASOURCE_GET_TYPES_ERROR.getCode(),
"datasource get types null or empty");
List<DataSourceType> dataSourceTypes = result.getAllDataSourceType();
dsTypeMap = dataSourceTypes.stream()
.collect(Collectors.toMap(
DataSourceType::getName,
DataSourceType::getId,
(existing, replacement) -> existing
));
}
}
return Optional.ofNullable(dsTypeMap)
.map(m -> Long.parseLong(m.get(dsName)))
.orElse(null);
}

@Override
public PageList<DataSourceModelTypeKey> findDsModelTypeKeyPageList(DataSourceModelTypeKeyQuery pageQuery) {
int currentPage = pageQuery.getPage();
Expand All @@ -56,7 +86,7 @@ public List<Map<String, Object>> queryDsModelTypeKeys(String operator, DataSourc
if (Objects.isNull(dsModelTypeKeys) || dsModelTypeKeys.size() <= 0 ) {
return new ArrayList<>();
}
long typeId = dsModelTypeKeys.get(0).getDsTypeId();
Long typeId = getDsTypeIdByName(operator, dsType);
GetKeyTypeDatasourceResult result = rpcSend(ExchangisLinkisRemoteClient.getLinkisDataSourceRemoteClient(), () ->
GetKeyTypeDatasourceAction.builder()
.setUser(operator).setDataSourceTypeId(typeId).build(),
Expand Down

0 comments on commit 2a50723

Please sign in to comment.