diff --git a/api-rest/src/main/java/com/homihq/db2rest/jdbc/config/JdbcConfiguration.java b/api-rest/src/main/java/com/homihq/db2rest/jdbc/config/JdbcConfiguration.java index 603cce19..b00da507 100644 --- a/api-rest/src/main/java/com/homihq/db2rest/jdbc/config/JdbcConfiguration.java +++ b/api-rest/src/main/java/com/homihq/db2rest/jdbc/config/JdbcConfiguration.java @@ -269,12 +269,12 @@ public DeleteService deleteService( //RPC @Bean - public FunctionService functionService(JdbcManager jdbcManager) { + public RpcService functionService(JdbcManager jdbcManager) { return new JdbcFunctionService(jdbcManager); } @Bean - public ProcedureService procedureService(JdbcManager jdbcManager) { + public RpcService procedureService(JdbcManager jdbcManager) { return new JdbcProcedureService(jdbcManager); } @@ -357,14 +357,14 @@ public DeleteController deleteController(DeleteService deleteService, Db2RestCon //RPC @Bean - @ConditionalOnBean(FunctionService.class) - public FunctionController functionController(FunctionService functionService) { + @ConditionalOnBean(RpcService.class) + public FunctionController functionController(RpcService functionService) { return new FunctionController(functionService); } @Bean - @ConditionalOnBean(ProcedureService.class) - public ProcedureController procedureController(ProcedureService procedureService) { + @ConditionalOnBean(RpcService.class) + public ProcedureController procedureController(RpcService procedureService) { return new ProcedureController(procedureService); } diff --git a/api-rest/src/main/java/com/homihq/db2rest/jdbc/rest/RpcApi.java b/api-rest/src/main/java/com/homihq/db2rest/jdbc/rest/RpcApi.java new file mode 100644 index 00000000..b938e164 --- /dev/null +++ b/api-rest/src/main/java/com/homihq/db2rest/jdbc/rest/RpcApi.java @@ -0,0 +1,24 @@ +package com.homihq.db2rest.jdbc.rest; + +import com.homihq.db2rest.jdbc.core.service.RpcService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.ResponseEntity; + +import java.util.Map; + +@Slf4j +public abstract class RpcApi { + private final RpcService service; + + protected RpcApi(RpcService service) { + this.service = service; + } + + public ResponseEntity> execute( + String dbId, + String funcName, + Map inParams) { + log.debug("Execute function {} with IN params {}", funcName, inParams.entrySet()); + return ResponseEntity.ok(service.execute(dbId, funcName, inParams)); + } +} diff --git a/api-rest/src/main/java/com/homihq/db2rest/jdbc/rest/rpc/FunctionController.java b/api-rest/src/main/java/com/homihq/db2rest/jdbc/rest/rpc/FunctionController.java index 452063e9..979b36b3 100644 --- a/api-rest/src/main/java/com/homihq/db2rest/jdbc/rest/rpc/FunctionController.java +++ b/api-rest/src/main/java/com/homihq/db2rest/jdbc/rest/rpc/FunctionController.java @@ -1,6 +1,7 @@ package com.homihq.db2rest.jdbc.rest.rpc; -import com.homihq.db2rest.jdbc.core.service.FunctionService; +import com.homihq.db2rest.jdbc.core.service.RpcService; +import com.homihq.db2rest.jdbc.rest.RpcApi; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.http.ResponseEntity; @@ -11,19 +12,16 @@ @RestController @RequestMapping(VERSION + "/{dbId}/function") @Slf4j -@RequiredArgsConstructor -public class FunctionController { - - private final FunctionService functionService; +public class FunctionController extends RpcApi { + public FunctionController(RpcService functionService) { + super(functionService); + } @PostMapping("/{funcName}") public ResponseEntity> execute( @PathVariable String dbId, @PathVariable String funcName, @RequestBody Map inParams) { - - log.debug("Execute function {} with IN params {}", funcName, inParams.entrySet()); - - return ResponseEntity.ok(functionService.execute(dbId, funcName, inParams)); + return super.execute(dbId, funcName, inParams); } } diff --git a/api-rest/src/main/java/com/homihq/db2rest/jdbc/rest/rpc/ProcedureController.java b/api-rest/src/main/java/com/homihq/db2rest/jdbc/rest/rpc/ProcedureController.java index 8af5f1bd..2ca5d31d 100644 --- a/api-rest/src/main/java/com/homihq/db2rest/jdbc/rest/rpc/ProcedureController.java +++ b/api-rest/src/main/java/com/homihq/db2rest/jdbc/rest/rpc/ProcedureController.java @@ -1,7 +1,7 @@ package com.homihq.db2rest.jdbc.rest.rpc; -import com.homihq.db2rest.jdbc.core.service.ProcedureService; -import lombok.RequiredArgsConstructor; +import com.homihq.db2rest.jdbc.core.service.RpcService; +import com.homihq.db2rest.jdbc.rest.RpcApi; import lombok.extern.slf4j.Slf4j; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -11,17 +11,17 @@ @RestController @RequestMapping(VERSION + "/{dbId}/procedure") @Slf4j -@RequiredArgsConstructor -public class ProcedureController { - - private final ProcedureService procedureService; +public class ProcedureController extends RpcApi { + public ProcedureController(RpcService procedureService) { + super(procedureService); + } + @Override @PostMapping("/{procName}") public ResponseEntity> execute( @PathVariable String dbId, @PathVariable String procName, - @RequestBody Map inParams) { - log.debug("Execute stored procedure {} with IN params {}", procName, inParams.entrySet()); - return ResponseEntity.ok(procedureService.execute(dbId,procName, inParams)); + @RequestBody Map inParams) { + return super.execute(dbId, procName, inParams); } } diff --git a/rdbms-support/src/main/java/com/homihq/db2rest/jdbc/core/service/JdbcFunctionService.java b/rdbms-support/src/main/java/com/homihq/db2rest/jdbc/core/service/JdbcFunctionService.java index dda9da09..20db2323 100644 --- a/rdbms-support/src/main/java/com/homihq/db2rest/jdbc/core/service/JdbcFunctionService.java +++ b/rdbms-support/src/main/java/com/homihq/db2rest/jdbc/core/service/JdbcFunctionService.java @@ -10,8 +10,7 @@ @Slf4j @RequiredArgsConstructor -public class JdbcFunctionService implements FunctionService { - +public class JdbcFunctionService implements RpcService { private final JdbcManager jdbcManager; @Override diff --git a/rdbms-support/src/main/java/com/homihq/db2rest/jdbc/core/service/JdbcProcedureService.java b/rdbms-support/src/main/java/com/homihq/db2rest/jdbc/core/service/JdbcProcedureService.java index d5bc1004..83778621 100644 --- a/rdbms-support/src/main/java/com/homihq/db2rest/jdbc/core/service/JdbcProcedureService.java +++ b/rdbms-support/src/main/java/com/homihq/db2rest/jdbc/core/service/JdbcProcedureService.java @@ -15,10 +15,16 @@ @Slf4j @RequiredArgsConstructor -public class JdbcProcedureService implements ProcedureService { - +public class JdbcProcedureService implements RpcService { private final JdbcManager jdbcManager; + @Override + public SimpleJdbcCall getSimpleJdbcCall(String dbId, String subRoutineName) { + log.info("dbId - {}", dbId); + JdbcTemplate jdbcTemplate = jdbcManager.getNamedParameterJdbcTemplate(dbId).getJdbcTemplate(); + return new SimpleJdbcCall(jdbcTemplate).withProcedureName(subRoutineName); + } + @Override public Map execute(String dbId, String subRoutineName, Map inParams) { JdbcTemplate jdbcTemplate = jdbcManager.getNamedParameterJdbcTemplate(dbId).getJdbcTemplate(); diff --git a/rdbms-support/src/main/java/com/homihq/db2rest/jdbc/core/service/ProcedureService.java b/rdbms-support/src/main/java/com/homihq/db2rest/jdbc/core/service/ProcedureService.java deleted file mode 100644 index 3152c758..00000000 --- a/rdbms-support/src/main/java/com/homihq/db2rest/jdbc/core/service/ProcedureService.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.homihq.db2rest.jdbc.core.service; - - -import java.util.Map; - -public interface ProcedureService { - - Map execute(String dbId, String subRoutineName, Map inParams); -} diff --git a/rdbms-support/src/main/java/com/homihq/db2rest/jdbc/core/service/FunctionService.java b/rdbms-support/src/main/java/com/homihq/db2rest/jdbc/core/service/RpcService.java similarity index 85% rename from rdbms-support/src/main/java/com/homihq/db2rest/jdbc/core/service/FunctionService.java rename to rdbms-support/src/main/java/com/homihq/db2rest/jdbc/core/service/RpcService.java index 3a703e82..db868046 100644 --- a/rdbms-support/src/main/java/com/homihq/db2rest/jdbc/core/service/FunctionService.java +++ b/rdbms-support/src/main/java/com/homihq/db2rest/jdbc/core/service/RpcService.java @@ -5,7 +5,7 @@ import java.util.Map; -public interface FunctionService extends SubRoutine { +public interface RpcService extends SubRoutine { SimpleJdbcCall getSimpleJdbcCall(String dbId, String subRoutineName); Map execute(String dbId, String subRoutineName, Map inParams); }