Skip to content

Commit

Permalink
Merge pull request #582 from kdhrubo/feature/578_change_dbName_dbId
Browse files Browse the repository at this point in the history
Feature/578 change db name db
  • Loading branch information
kdhrubo authored May 18, 2024
2 parents d5a2d7a + 7747ccb commit a84110f
Show file tree
Hide file tree
Showing 47 changed files with 182 additions and 185 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons

if(Objects.isNull(pathVariables)) throw new GenericDataAccessException("Database ID not found.");

String dbName = pathVariables.get("dbName");
String dbId = pathVariables.get("dbId");

log.info("Db identifier : {}", dbName);
log.info("Db identifier : {}", dbId);

if(StringUtils.isNotBlank(dbName)) {
this.setTenantContext(dbName);
if(StringUtils.isNotBlank(dbId)) {
this.setTenantContext(dbId);
}
else{
log.debug("DB could not be determined.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class BulkCreateController implements BulkCreateRestApi {


public CreateBulkResponse save(
String dbName,
String dbId,
String tableName,
String schemaName,
List<String> includeColumns,
Expand All @@ -41,7 +41,7 @@ public CreateBulkResponse save(


return
bulkCreateService.saveBulk(dbName, schemaName, tableName, includeColumns, data, tsIdEnabled, sequences);
bulkCreateService.saveBulk(dbId, schemaName, tableName, includeColumns, data, tsIdEnabled, sequences);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

public interface BulkCreateRestApi {
@ResponseStatus(HttpStatus.CREATED)
@PostMapping(value = VERSION + "/{dbName}/{tableName}/bulk",
@PostMapping(value = VERSION + "/{dbId}/{tableName}/bulk",
consumes = {"application/json", "text/csv"}
)
CreateBulkResponse save(@PathVariable String dbName,
CreateBulkResponse save(@PathVariable String dbId,
@PathVariable String tableName,
@RequestHeader(name="Content-Profile", required = false) String schemaName,
@RequestParam(name = "columns", required = false) List<String> includeColumns,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ public class CreateController implements CreateRestApi {

@Override
public CreateResponse save(
String dbName, String schemaName,
String dbId, String schemaName,
String tableName,
List<String> includeColumns,
List<String> sequences,
Map<String, Object> data,
boolean tsIdEnabled) {

return createService
.save(dbName, schemaName, tableName, includeColumns, data, tsIdEnabled, sequences);
.save(dbId, schemaName, tableName, includeColumns, data, tsIdEnabled, sequences);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

public interface CreateRestApi {
@ResponseStatus(HttpStatus.CREATED)
@PostMapping(VERSION + "/{dbName}/{tableName}")
CreateResponse save(@PathVariable String dbName,
@PostMapping(VERSION + "/{dbId}/{tableName}")
CreateResponse save(@PathVariable String dbId,
@RequestHeader(name="Content-Profile", required = false) String schemaName,
@PathVariable String tableName,
@RequestParam(name = "columns", required = false) List<String> includeColumns,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ public class DeleteController implements DeleteRestApi {

@Override
public DeleteResponse delete(
String dbName,
String dbId,
String schemaName,
String tableName,
String filter) {

db2RestConfigProperties.checkDeleteAllowed(filter);

int rows = deleteService.delete(dbName, schemaName, tableName, filter);
int rows = deleteService.delete(dbId, schemaName, tableName, filter);
log.debug("Number of rows deleted - {}", rows);
return DeleteResponse.builder().rows(rows).build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import static com.homihq.db2rest.jdbc.rest.RdbmsRestApi.VERSION;
public interface DeleteRestApi {
@ResponseStatus(HttpStatus.OK)
@DeleteMapping(VERSION + "/{dbName}/{tableName}")
@DeleteMapping(VERSION + "/{dbId}/{tableName}")
DeleteResponse delete(
@PathVariable String dbName,
@PathVariable String dbId,
@RequestHeader(name="Content-Profile", required = false) String schemaName,
@PathVariable String tableName,
@RequestParam(name = "filter", required = false, defaultValue = "") String filter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
@RequiredArgsConstructor
public class CountQueryController {
private final CountQueryService countQueryService;
@GetMapping(VERSION + "/{dbName}/{tableName}/count")
public CountResponse count(@PathVariable String dbName,
@GetMapping(VERSION + "/{dbId}/{tableName}/count")
public CountResponse count(@PathVariable String dbId,
@PathVariable String tableName,
@RequestHeader(name="Accept-Profile", required = false) String schemaName,
@RequestParam(name = "filter", required = false, defaultValue = "") String filter) {
Expand All @@ -23,7 +23,7 @@ public CountResponse count(@PathVariable String dbName,
log.debug("filter - {}", filter);

ReadContext readContext = ReadContext.builder()
.dbName(dbName)
.dbId(dbId)
.schemaName(schemaName)
.tableName(tableName)
.filter(filter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ public class CustomQueryController {

private final CustomQueryService customQueryService;

@PostMapping(value =VERSION + "/{dbName}/query", consumes = MediaType.APPLICATION_JSON_VALUE,
@PostMapping(value =VERSION + "/{dbId}/query", consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Object> findByCustomQuery(
@PathVariable String dbName,
@PathVariable String dbId,
@RequestBody @Valid QueryRequest queryRequest) {
log.debug("Execute SQL statement {} with params {}", queryRequest.sql(), queryRequest.params());
return ResponseEntity.ok(customQueryService.find(dbName, queryRequest));
return ResponseEntity.ok(customQueryService.find(dbId, queryRequest));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public class ExistsQueryController {

private final ExistsQueryService existsQueryService;

@GetMapping(value = VERSION + "/{dbName}/{tableName}/exists", produces = "application/json")
public ExistsResponse exists(@PathVariable String dbName,
@GetMapping(value = VERSION + "/{dbId}/{tableName}/exists", produces = "application/json")
public ExistsResponse exists(@PathVariable String dbId,
@PathVariable String tableName,
@RequestHeader(name="Accept-Profile", required = false) String schemaName,
@RequestParam(name = "filter", required = false, defaultValue = "") String filter) {
Expand All @@ -28,7 +28,7 @@ public ExistsResponse exists(@PathVariable String dbName,
log.debug("filter - {}", filter);

ReadContext readContext = ReadContext.builder()
.dbName(dbName)
.dbId(dbId)
.schemaName(schemaName)
.tableName(tableName)
.filter(filter)
Expand All @@ -37,16 +37,16 @@ public ExistsResponse exists(@PathVariable String dbName,
return existsQueryService.exists(readContext);
}

@PostMapping(value = VERSION + "/{dbName}/{tableName}/exists/_expand", produces = "application/json")
public ExistsResponse exists(@PathVariable String dbName,
@PostMapping(value = VERSION + "/{dbId}/{tableName}/exists/_expand", produces = "application/json")
public ExistsResponse exists(@PathVariable String dbId,
@PathVariable String tableName,
@RequestHeader(name="Accept-Profile", required = false) String schemaName,
@RequestParam(name = "filter", required = false, defaultValue = "") String filter,
@RequestBody List<JoinDetail> joins
) {

ReadContext readContext = ReadContext.builder()
.dbName(dbName)
.dbId(dbId)
.schemaName(schemaName)
.tableName(tableName)
.fields("*")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public class FindOneController {

private final FindOneService findOneService;

@GetMapping(VERSION + "/{dbName}/{tableName}/one")
public Map<String,Object> findOne(@PathVariable String dbName,
@GetMapping(VERSION + "/{dbId}/{tableName}/one")
public Map<String,Object> findOne(@PathVariable String dbId,
@PathVariable String tableName,
@RequestHeader(name="Accept-Profile", required = false) String schemaName,
@RequestParam(name = "fields", required = false, defaultValue = "*") String fields,
Expand All @@ -29,7 +29,7 @@ public Map<String,Object> findOne(@PathVariable String dbName,
log.debug("filter - {}", filter);

ReadContext readContext = ReadContext.builder()
.dbName(dbName)
.dbId(dbId)
.defaultFetchLimit(100) //todo update with config
.schemaName(schemaName)
.tableName(tableName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public class ReadController {

private final ReadService readService;

@GetMapping(value =VERSION + "/{dbName}/{tableName}" , produces = "application/json")
@GetMapping(value =VERSION + "/{dbId}/{tableName}" , produces = "application/json")
public Object findAll(
@PathVariable String dbName,
@PathVariable String dbId,
@PathVariable String tableName,
@RequestHeader(name="Accept-Profile", required = false) String schemaName,
@RequestParam(name = "fields", required = false, defaultValue = "*") String fields,
Expand All @@ -30,7 +30,7 @@ public Object findAll(
log.info("filter - {}", filter);

ReadContext readContext = ReadContext.builder()
.dbName(dbName)
.dbId(dbId)
.schemaName(schemaName)
.tableName(tableName)
.fields(fields)
Expand All @@ -44,9 +44,9 @@ public Object findAll(
return readService.findAll(readContext);
}

@PostMapping(value =VERSION + "/{dbName}/{tableName}/_expand" , produces = "application/json")
@PostMapping(value =VERSION + "/{dbId}/{tableName}/_expand" , produces = "application/json")
public Object find(
@PathVariable String dbName,
@PathVariable String dbId,
@PathVariable String tableName,
@RequestHeader(name="Accept-Profile", required = false) String schemaName,
@RequestParam(name = "fields", required = false, defaultValue = "*") String fields,
Expand All @@ -58,7 +58,7 @@ public Object find(
) {

ReadContext readContext = ReadContext.builder()
.dbName(dbName)
.dbId(dbId)
.schemaName(schemaName)
.tableName(tableName)
.fields(fields)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import java.util.Map;
import static com.homihq.db2rest.jdbc.rest.RdbmsRestApi.VERSION;
@RestController
@RequestMapping(VERSION + "/{dbName}/function")
@RequestMapping(VERSION + "/{dbId}/function")
@Slf4j
@RequiredArgsConstructor
public class FunctionController {
Expand All @@ -18,12 +18,12 @@ public class FunctionController {

@PostMapping("/{funcName}")
public ResponseEntity<Map<String, Object>> execute(
@PathVariable String dbName,
@PathVariable String dbId,
@PathVariable String funcName,
@RequestBody Map<String,Object> inParams) {

log.debug("Execute function {} with IN params {}", funcName, inParams.entrySet());

return ResponseEntity.ok(functionService.execute(dbName, funcName, inParams));
return ResponseEntity.ok(functionService.execute(dbId, funcName, inParams));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import java.util.Map;
import static com.homihq.db2rest.jdbc.rest.RdbmsRestApi.VERSION;
@RestController
@RequestMapping(VERSION + "/{dbName}/procedure")
@RequestMapping(VERSION + "/{dbId}/procedure")
@Slf4j
@RequiredArgsConstructor
public class ProcedureController {
Expand All @@ -18,10 +18,10 @@ public class ProcedureController {

@PostMapping("/{procName}")
public ResponseEntity<Map<String, Object>> execute(
@PathVariable String dbName,
@PathVariable String dbId,
@PathVariable String procName,
@RequestBody Map<String,Object> inParams) {
log.debug("Execute stored procedure {} with IN params {}", procName, inParams.entrySet());
return ResponseEntity.ok(procedureService.execute(dbName,procName, inParams));
return ResponseEntity.ok(procedureService.execute(dbId,procName, inParams));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
public class UpdateController {

private final UpdateService updateService;
@PatchMapping(VERSION + "/{dbName}/{tableName}")
public UpdateResponse save(@PathVariable String dbName,
@PatchMapping(VERSION + "/{dbId}/{tableName}")
public UpdateResponse save(@PathVariable String dbId,
@PathVariable String tableName,
@RequestHeader(name="Content-Profile", required = false) String schemaName,
@RequestBody Map<String,Object> data
, @RequestParam(name = "filter", required = false, defaultValue = "") String filter) {


int rows = updateService.patch(dbName,schemaName, tableName, data, filter);
int rows = updateService.patch(dbId,schemaName, tableName, data, filter);
return new UpdateResponse(rows);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public class MongoController implements MongoRestApi {
private final Db2RestConfigProperties db2RestConfigProperties;

@Override
public CreateResponse save(String collectionName,
public CreateResponse save(String dbId,
String collectionName,
List<String> includeFields,
Map<String, Object> data) {
return mongoRepository
Expand All @@ -44,22 +45,22 @@ public CreateResponse save(String collectionName,
}

@Override
public CreateBulkResponse saveAll(String collectionName,
public CreateBulkResponse saveAll(String dbId,String collectionName,
List<String> includeFields,
List<Map<String, Object>> dataList) {
return mongoRepository.saveAll(collectionName, includeFields, dataList);
}

@Override
public UpdateResponse patch(String collectionName, Map<String, Object> data, String filter) {
public UpdateResponse patch(String dbId,String collectionName, Map<String, Object> data, String filter) {
log.debug("Filter - {}", filter);
var query = new Query();
addCriteria(filter, query);
return mongoRepository.patch(query, collectionName, data);
}

@Override
public DeleteResponse delete(String collectionName, String filter) {
public DeleteResponse delete(String dbId,String collectionName, String filter) {
log.debug("Filter - {}", filter);
db2RestConfigProperties.checkDeleteAllowed(filter);
var query = new Query();
Expand All @@ -68,7 +69,7 @@ public DeleteResponse delete(String collectionName, String filter) {
}

@Override
public Object findAll(String collectionName, String fields, String filter, List<String> sorts,
public Object findAll(String dbId,String collectionName, String fields, String filter, List<String> sorts,
int limit, long offset) {
fields = StringUtils.trim(fields);
log.debug("Filter - {}", filter);
Expand Down Expand Up @@ -106,22 +107,22 @@ private record FieldSort(String field, Sort.Direction sortDirection) {
}

@Override
public Map<String, Object> findOne(String collectionName, String fields, String filter) {
public Map<String, Object> findOne(String dbId,String collectionName, String fields, String filter) {
var query = new Query();
addCriteria(filter, query);
includeFields(fields, query);
return mongoRepository.findOne(query, collectionName);
}

@Override
public CountResponse count(String collectionName, String filter) {
public CountResponse count(String dbId,String collectionName, String filter) {
var query = new Query();
addCriteria(filter, query);
return mongoRepository.count(query, collectionName);
}

@Override
public ExistsResponse exists(String collectionName, String filter) {
public ExistsResponse exists(String dbId,String collectionName, String filter) {
if (StringUtils.isBlank(filter)) {
throw new GenericDataAccessException("Required parameter 'filter' is not present.");
}
Expand Down
Loading

0 comments on commit a84110f

Please sign in to comment.