-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#296 - cleanup schema dependency and mybatis for update
- Loading branch information
Showing
8 changed files
with
149 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/java/com/homihq/db2rest/rest/update/UpdateCreatorTemplate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.homihq.db2rest.rest.update; | ||
|
||
import com.homihq.db2rest.rest.delete.dto.DeleteContext; | ||
import com.homihq.db2rest.rest.update.dto.UpdateContext; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Component; | ||
import org.thymeleaf.context.Context; | ||
import org.thymeleaf.spring6.SpringTemplateEngine; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
|
||
@Component | ||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class UpdateCreatorTemplate { | ||
|
||
|
||
private final SpringTemplateEngine templateEngine; | ||
public String updateQuery(UpdateContext updateContext) { | ||
|
||
Map<String,Object> data = new HashMap<>(); | ||
|
||
data.put("rootTable", updateContext.getTable().render()); | ||
data.put("rootWhere", updateContext.getWhere()); | ||
data.put("columnSets", updateContext.renderSetColumns()); | ||
|
||
Context context = new Context(); | ||
context.setVariables(data); | ||
return templateEngine.process("update", context); | ||
|
||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/main/java/com/homihq/db2rest/rest/update/dto/UpdateContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.homihq.db2rest.rest.update.dto; | ||
|
||
import com.homihq.db2rest.model.DbTable; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
|
||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Data | ||
@Slf4j | ||
public class UpdateContext { | ||
|
||
|
||
String tableName; | ||
DbTable table; | ||
String where; | ||
Map<String,Object> paramMap; | ||
List<String> updatableColumns; | ||
|
||
|
||
public String renderSetColumns() { | ||
return StringUtils.join( | ||
updatableColumns.stream().map(i -> i + " = " + ":set_" + i).toList(), | ||
"," | ||
); | ||
} | ||
|
||
public void createParamMap(Map<String, Object> data) { | ||
if(Objects.isNull(paramMap)) { | ||
paramMap = new HashMap<>(); | ||
} | ||
|
||
for(String key : data.keySet()) { | ||
paramMap.put("set_" + key , data.get(key)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,5 +53,4 @@ logging: | |
jdbc: | ||
datasource: | ||
init: DEBUG | ||
core: | ||
JdbcTemplate: DEBUG | ||
core.*: DEBUG |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
UPDATE [(${rootTable})] | ||
SET [(${columnSets})] | ||
[# th:if="${rootWhere}"]WHERE | ||
[(${rootWhere})] | ||
[/] |