Skip to content

Commit

Permalink
#98 - update based on tests
Browse files Browse the repository at this point in the history
  • Loading branch information
grabdoc committed Jan 9, 2024
1 parent 2bca5fd commit 5565b50
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ public class DB2RestRenderingStrategy extends SpringNamedParameterRenderingStrat

@Override
public String getRecordBasedInsertBinding(BindableColumn<?> column, String prefix, String parameterName) {
log.info("Here - 1");

return super.getRecordBasedInsertBinding(column, parameterName);
}

@Override
public String getRecordBasedInsertBinding(BindableColumn<?> column, String parameterName) {
log.info("Here - 2");

return super.getRecordBasedInsertBinding(column, parameterName);
}
}
23 changes: 14 additions & 9 deletions src/main/java/com/homihq/db2rest/rest/create/CreateController.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.homihq.db2rest.rest.create;

import com.homihq.db2rest.rest.create.dto.CreateBulkResponse;
import com.homihq.db2rest.rest.create.dto.CreateResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
Expand All @@ -14,21 +16,24 @@ public class CreateController {

private final CreateService createService;
@PostMapping ("/{tableName}")
public void save(@PathVariable String tableName,
@RequestHeader(name = "Content-Profile") String schemaName,
@RequestBody Map<String,Object> data) {

public CreateResponse save(@PathVariable String tableName,
@RequestHeader(name = "Content-Profile") String schemaName,
@RequestBody Map<String,Object> data) {

int rows =
createService.save(schemaName, tableName, data);

return new CreateResponse(rows);
}

@PostMapping ( "/{tableName}/bulk")
public void saveBulk(@PathVariable String tableName,
@RequestHeader(name = "Content-Profile") String schemaName,
@RequestBody List<Map<String,Object>> data) {
log.info("data -> {}", data);

public CreateBulkResponse saveBulk(@PathVariable String tableName,
@RequestHeader(name = "Content-Profile") String schemaName,
@RequestBody List<Map<String,Object>> data) {

int [] rows =
createService.saveBulk(schemaName, tableName,data);

return new CreateBulkResponse(rows);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class CreateService {
private final DB2RestRenderingStrategy db2RestRenderingStrategy = new DB2RestRenderingStrategy();

@Transactional
public void save(String schemaName, String tableName, Map<String,Object> data) {
public int save(String schemaName, String tableName, Map<String,Object> data) {
db2RestConfigProperties.verifySchema(schemaName);

SqlTable table = SqlTable.of(tableName);
Expand All @@ -53,10 +53,12 @@ public void save(String schemaName, String tableName, Map<String,Object> data) {

log.debug("Inserted - {} row(s)", rows);

return rows;

}

@Transactional
public void saveBulk(String schemaName, String tableName, List<Map<String, Object>> dataList) {
public int[] saveBulk(String schemaName, String tableName, List<Map<String, Object>> dataList) {
if(Objects.isNull(dataList) || dataList.isEmpty()) throw new RuntimeException("No data provided");

SqlTable table = SqlTable.of(tableName);
Expand All @@ -83,6 +85,8 @@ public void saveBulk(String schemaName, String tableName, List<Map<String, Objec
int[] updateCounts = namedParameterJdbcTemplate.batchUpdate(batchInsert.getInsertStatementSQL(), batch);

log.debug("Update counts - {}", updateCounts.length);

return updateCounts;
}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.homihq.db2rest.rest.create.dto;

public record CreateBulkResponse(int [] rows) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.homihq.db2rest.rest.create.dto;

public record CreateResponse(int rows) {
}
2 changes: 2 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ db2rest:

logging:
level:
com.homihq.db2rest:
rest: DEBUG
org.springframework.web : INFO
schemacrawler:
schemacrawler: ERROR
Expand Down

0 comments on commit 5565b50

Please sign in to comment.