Skip to content

Commit

Permalink
Improve delete script
Browse files Browse the repository at this point in the history
  • Loading branch information
apik007 committed Mar 26, 2024
1 parent ecfb5dd commit d52ff0f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>cz.foresttech</groupId>
<artifactId>ForestDatabase</artifactId>
<version>1.0.6</version>
<version>1.0.7</version>

<properties>
<maven.compiler.source>17</maven.compiler.source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ public String generateCreateScript(Class<?> clazz) {
* @return a string representing a part of SQL script.
*/
private <T> String processDeleteConditionScript(Class<T> clazz, T object) throws IllegalAccessException {
List<String> keys = new ArrayList<>();
List<String> values = new ArrayList<>();
StringBuilder keys = new StringBuilder();
StringBuilder values = new StringBuilder();

for (Field field : clazz.getDeclaredFields()) {
field.setAccessible(true);
Expand All @@ -251,12 +251,15 @@ private <T> String processDeleteConditionScript(Class<T> clazz, T object) throws
DatabaseValueProcessor valueProcessor = databaseAPI.getProcessor(field.getType());

String processedValue = processFieldValue(fieldValue, valueProcessor);
keys.add(dbName);
values.add(processedValue);
keys.append(dbName).append(",");
values.append(processedValue).append(",");
}

if (keys.isEmpty()) return "";

keys.setLength(keys.length() - 1);
values.setLength(values.length() - 1);

return "(" + keys + ") = (" + values + ")";
}

Expand Down

0 comments on commit d52ff0f

Please sign in to comment.