Skip to content

Commit 1721cfd

Browse files
fix: source schema sync
1 parent 4f170c4 commit 1721cfd

File tree

6 files changed

+37
-12
lines changed

6 files changed

+37
-12
lines changed

core/src/main/java/datart/core/mappers/ext/SourceSchemasMapperExt.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import datart.core.entity.SourceSchemas;
2121
import datart.core.mappers.SourceSchemasMapper;
22+
import org.apache.ibatis.annotations.Delete;
2223
import org.apache.ibatis.annotations.Mapper;
2324
import org.apache.ibatis.annotations.Select;
2425

@@ -33,4 +34,7 @@ public interface SourceSchemasMapperExt extends SourceSchemasMapper {
3334
@Select("SELECT update_time FROM source_schemas where source_id = #{sourceId}")
3435
Date selectUpdateDateBySource(String sourceId);
3536

37+
@Delete("DELETE FROM source_schemas where source_id = #{sourceId}")
38+
int deleteBySource(String sourceId);
39+
3640
}

data-providers/src/main/java/datart/data/provider/DefaultDataProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public boolean validateFunction(DataProviderSource source, String snippet) {
189189
@Override
190190
public void resetSource(DataProviderSource source) {
191191
try {
192-
LocalDB.clearCache(source.getSourceId());
192+
LocalDB.clearCache("DB" + source.getSourceId());
193193
} catch (Exception e) {
194194
log.error("reset datasource error ", e);
195195
}

server/src/main/java/datart/server/controller/SourceController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ public ResponseData<Source> getSourceDetail(@PathVariable String sourceId) {
6969
@ApiOperation(value = "create source")
7070
@PostMapping()
7171
public ResponseData<Source> createSource(@Validated @RequestBody SourceCreateParam createParam) {
72-
return ResponseData.success(sourceService.create(createParam));
72+
return ResponseData.success(sourceService.createSource(createParam));
7373
}
7474

7575
@ApiOperation(value = "update a source")
7676
@PutMapping(value = "/{sourceId}")
7777
public ResponseData<Boolean> updateSource(@PathVariable String sourceId,
7878
@Validated @RequestBody SourceUpdateParam updateParam) {
79-
return ResponseData.success(sourceService.update(updateParam));
79+
return ResponseData.success(sourceService.updateSource(updateParam));
8080
}
8181

8282
@ApiOperation(value = "delete a source")

server/src/main/java/datart/server/service/SourceService.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import datart.core.data.provider.SchemaInfo;
2222
import datart.core.entity.Source;
2323
import datart.core.mappers.ext.SourceMapperExt;
24+
import datart.server.base.params.SourceCreateParam;
25+
import datart.server.base.params.SourceUpdateParam;
2426
import datart.server.base.transfer.model.SourceTransferModel;
2527

2628
import java.util.List;
@@ -33,4 +35,8 @@ public interface SourceService extends BaseCRUDService<Source, SourceMapperExt>,
3335

3436
SchemaInfo syncSourceSchema(String sourceId) throws Exception;
3537

38+
Source createSource(SourceCreateParam createParam);
39+
40+
boolean updateSource(SourceUpdateParam updateParam);
41+
3642
}

server/src/main/java/datart/server/service/impl/DataProviderServiceImpl.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,10 @@ public DataProviderSource parseDataProviderConfig(Source source) {
145145
providerSource.setSourceId(source.getId());
146146
providerSource.setType(source.getType());
147147
providerSource.setName(source.getName());
148-
Map<String, Object> properties = objectMapper.readValue(source.getConfig(), HashMap.class);
148+
Map<String, Object> properties = new HashMap<>();
149+
if (StringUtils.isNotBlank(source.getConfig())) {
150+
properties = objectMapper.readValue(source.getConfig(), HashMap.class);
151+
}
149152
// decrypt values
150153
for (String key : properties.keySet()) {
151154
Object val = properties.get(key);

server/src/main/java/datart/server/service/impl/SourceServiceImpl.java

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,13 @@ private boolean hasPermission(Role role, Source source, int permission) {
249249
}
250250
}
251251

252+
@Override
253+
public Source createSource(SourceCreateParam createParam) {
254+
Source source = create(createParam);
255+
updateJdbcSourceSyncJob(source);
256+
return source;
257+
}
258+
252259
@Override
253260
@Transactional
254261
public Source create(BaseCreateParam createParam) {
@@ -263,11 +270,21 @@ public Source create(BaseCreateParam createParam) {
263270
Source source = SourceService.super.create(createParam);
264271

265272
grantDefaultPermission(source);
266-
updateJdbcSourceSyncJob(source);
267273
return source;
268274

269275
}
270276

277+
@Override
278+
public boolean updateSource(SourceUpdateParam updateParam) {
279+
boolean success = update(updateParam);
280+
if (success) {
281+
Source source = retrieve(updateParam.getId());
282+
getDataProviderService().updateSource(source);
283+
updateJdbcSourceSyncJob(source);
284+
}
285+
return false;
286+
}
287+
271288
@Override
272289
@Transactional
273290
public boolean update(BaseUpdateParam updateParam) {
@@ -278,13 +295,7 @@ public boolean update(BaseUpdateParam updateParam) {
278295
} catch (Exception e) {
279296
Exceptions.e(e);
280297
}
281-
boolean success = SourceService.super.update(updateParam);
282-
if (success) {
283-
Source source = retrieve(updateParam.getId());
284-
getDataProviderService().updateSource(source);
285-
updateJdbcSourceSyncJob(source);
286-
}
287-
return success;
298+
return SourceService.super.update(updateParam);
288299
}
289300

290301
@Override
@@ -337,6 +348,7 @@ public Source retrieve(String id) {
337348
@Override
338349
public void deleteReference(Source source) {
339350
deleteJdbcSourceSyncJob(source);
351+
sourceSchemasMapper.deleteBySource(source.getId());
340352
}
341353

342354
@Override

0 commit comments

Comments
 (0)