Showing
6 changed files
with
28 additions
and
4 deletions
@@ -66,6 +66,12 @@ public class TkDbConnectController extends BaseController { | @@ -66,6 +66,12 @@ public class TkDbConnectController extends BaseController { | ||
66 | return ResponseEntity.ok(dto); | 66 | return ResponseEntity.ok(dto); |
67 | } | 67 | } |
68 | 68 | ||
69 | + @PostMapping("/testDbConnect") | ||
70 | + @PreAuthorize("hasAnyAuthority('TENANT_ADMIN','CUSTOMER_USER')") | ||
71 | + public ResponseEntity<Boolean> testDbConnect(@RequestBody TkDbConnectDTO tkDbConnectDTO) throws ThingsboardException { | ||
72 | + return ResponseEntity.ok(tkDbConnectService.checkConnect(tkDbConnectDTO)); | ||
73 | + } | ||
74 | + | ||
69 | @GetMapping("/delete") | 75 | @GetMapping("/delete") |
70 | @PreAuthorize("hasAnyAuthority('TENANT_ADMIN','CUSTOMER_USER')") | 76 | @PreAuthorize("hasAnyAuthority('TENANT_ADMIN','CUSTOMER_USER')") |
71 | public ResponseEntity<Boolean> delete(@RequestParam("id") String id) throws ThingsboardException { | 77 | public ResponseEntity<Boolean> delete(@RequestParam("id") String id) throws ThingsboardException { |
@@ -34,9 +34,11 @@ import java.util.Properties; | @@ -34,9 +34,11 @@ import java.util.Properties; | ||
34 | public class BaseDbConnectServiceImpl implements BaseDbConnectService { | 34 | public class BaseDbConnectServiceImpl implements BaseDbConnectService { |
35 | 35 | ||
36 | private static SSLContext sslContext = null; | 36 | private static SSLContext sslContext = null; |
37 | + private static Boolean checkConnect = null; | ||
37 | 38 | ||
38 | @Override | 39 | @Override |
39 | - public Object connect(TkDbConnectDTO tkDbConnectDTO) { | 40 | + public Object connect(TkDbConnectDTO tkDbConnectDTO, boolean checkConnect) { |
41 | + this.checkConnect = checkConnect; | ||
40 | if (BooleanUtils.isNotTrue(tkDbConnectDTO.isOpenSsh()) && BooleanUtils.isNotTrue(tkDbConnectDTO.isOpenSsl())) { | 42 | if (BooleanUtils.isNotTrue(tkDbConnectDTO.isOpenSsh()) && BooleanUtils.isNotTrue(tkDbConnectDTO.isOpenSsl())) { |
41 | return commonConnect(tkDbConnectDTO); | 43 | return commonConnect(tkDbConnectDTO); |
42 | } else if (BooleanUtils.isTrue(tkDbConnectDTO.isOpenSsh()) && BooleanUtils.isNotTrue(tkDbConnectDTO.isOpenSsl())) { | 44 | } else if (BooleanUtils.isTrue(tkDbConnectDTO.isOpenSsh()) && BooleanUtils.isNotTrue(tkDbConnectDTO.isOpenSsl())) { |
@@ -216,6 +218,10 @@ public class BaseDbConnectServiceImpl implements BaseDbConnectService { | @@ -216,6 +218,10 @@ public class BaseDbConnectServiceImpl implements BaseDbConnectService { | ||
216 | 218 | ||
217 | dataSource = new HikariDataSource(config); | 219 | dataSource = new HikariDataSource(config); |
218 | connection = dataSource.getConnection(); | 220 | connection = dataSource.getConnection(); |
221 | + if (BooleanUtils.isTrue(checkConnect)) { | ||
222 | + return true; | ||
223 | + } | ||
224 | + | ||
219 | statement = connection.prepareStatement(replaceParam(tkDbConnectDTO.getSql(), tkDbConnectDTO.getParamMap())); | 225 | statement = connection.prepareStatement(replaceParam(tkDbConnectDTO.getSql(), tkDbConnectDTO.getParamMap())); |
220 | resultSet = statement.executeQuery(); | 226 | resultSet = statement.executeQuery(); |
221 | ResultSetMetaData metaData = resultSet.getMetaData(); | 227 | ResultSetMetaData metaData = resultSet.getMetaData(); |
@@ -130,6 +130,16 @@ public class TkDbConnectServiceImpl extends AbstractBaseService<TkDbConnectMappe | @@ -130,6 +130,16 @@ public class TkDbConnectServiceImpl extends AbstractBaseService<TkDbConnectMappe | ||
130 | 130 | ||
131 | dbDto.setSql(tkDbConnectDTO.getSql()); | 131 | dbDto.setSql(tkDbConnectDTO.getSql()); |
132 | dbDto.setParamMap(tkDbConnectDTO.getParamMap()); | 132 | dbDto.setParamMap(tkDbConnectDTO.getParamMap()); |
133 | - return connectServiceFactory.getService("baseConnect").connect(dbDto); | 133 | + return connectServiceFactory.getService("baseConnect").connect(dbDto, false); |
134 | + } | ||
135 | + | ||
136 | + @Override | ||
137 | + public boolean checkConnect(TkDbConnectDTO tkDbConnectDTO) { | ||
138 | + Object result = connectServiceFactory.getService("baseConnect").connect(tkDbConnectDTO, true); | ||
139 | + if (result instanceof Boolean) { | ||
140 | + return (Boolean) result; | ||
141 | + } | ||
142 | + | ||
143 | + return false; | ||
134 | } | 144 | } |
135 | } | 145 | } |
@@ -68,7 +68,7 @@ public class TkDbDataSetServiceImpl extends AbstractBaseService<TkDbDataSetMappe | @@ -68,7 +68,7 @@ public class TkDbDataSetServiceImpl extends AbstractBaseService<TkDbDataSetMappe | ||
68 | TkDbConnectDTO dbConnectDTO = dto.getTkDbConnectDTO(); | 68 | TkDbConnectDTO dbConnectDTO = dto.getTkDbConnectDTO(); |
69 | dbConnectDTO.setParamMap(paramMap); | 69 | dbConnectDTO.setParamMap(paramMap); |
70 | dbConnectDTO.setSql(dto.getSql()); | 70 | dbConnectDTO.setSql(dto.getSql()); |
71 | - return connectServiceFactory.getService("baseConnect").connect(dbConnectDTO); | 71 | + return connectServiceFactory.getService("baseConnect").connect(dbConnectDTO, false); |
72 | } | 72 | } |
73 | 73 | ||
74 | private void checkDto(TkDbDataSetDTO dto) { | 74 | private void checkDto(TkDbDataSetDTO dto) { |
@@ -10,5 +10,5 @@ public interface BaseDbConnectService { | @@ -10,5 +10,5 @@ public interface BaseDbConnectService { | ||
10 | * @param tkDbConnectDTO | 10 | * @param tkDbConnectDTO |
11 | * @return | 11 | * @return |
12 | */ | 12 | */ |
13 | - Object connect(TkDbConnectDTO tkDbConnectDTO); | 13 | + Object connect(TkDbConnectDTO tkDbConnectDTO, boolean checkConnect); |
14 | } | 14 | } |
@@ -17,4 +17,6 @@ public interface TkDbConnectService extends BaseService<TkDbConnectEntity> { | @@ -17,4 +17,6 @@ public interface TkDbConnectService extends BaseService<TkDbConnectEntity> { | ||
17 | TkDbConnectDTO get(String id); | 17 | TkDbConnectDTO get(String id); |
18 | 18 | ||
19 | Object connectResult(TkDbConnectDTO tkDbConnectDTO); | 19 | Object connectResult(TkDbConnectDTO tkDbConnectDTO); |
20 | + | ||
21 | + boolean checkConnect(TkDbConnectDTO tkDbConnectDTO); | ||
20 | } | 22 | } |