From 31e3bfb3e435433b80038a0561331f4a9f5d771f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fo=CC=81rizs=20Jeno=CC=8B?= Date: Wed, 22 Apr 2020 19:29:13 +0200 Subject: [PATCH] dao: update function: generated SQL was incorrect, because of handling of virtual fields --- .../main/java/hu/vanio/easydao/model/Table.java | 16 +++++++++++++++- .../resources/hu/vanio/easydao/templates/dao.ftl | 4 +--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/easydao-maven-plugin/src/main/java/hu/vanio/easydao/model/Table.java b/easydao-maven-plugin/src/main/java/hu/vanio/easydao/model/Table.java index 3fa9a37..a639f36 100644 --- a/easydao-maven-plugin/src/main/java/hu/vanio/easydao/model/Table.java +++ b/easydao-maven-plugin/src/main/java/hu/vanio/easydao/model/Table.java @@ -113,7 +113,21 @@ public List getNonPkFields() { } return retVal; } - + + /** + * Returns non-primary and not virtual key fields + * @return The list of non-primary key and not virtual key fields + */ + public List getNonPkAndNotVirtualFields() { + List retVal = new ArrayList<>(); + for (Field fd : this.fieldList) { + if (!fd.isPrimaryKey() && !fd.isVirtual()) { + retVal.add(fd); + } + } + return retVal; + } + /** * Returns the standalone primary key field of this table. If there is no primary key field in this table, it returns null. * @return The standalone primary key field of this table or null if there is no primary key field in this table. diff --git a/easydao-maven-plugin/src/main/resources/hu/vanio/easydao/templates/dao.ftl b/easydao-maven-plugin/src/main/resources/hu/vanio/easydao/templates/dao.ftl index e51a943..c5501a3 100644 --- a/easydao-maven-plugin/src/main/resources/hu/vanio/easydao/templates/dao.ftl +++ b/easydao-maven-plugin/src/main/resources/hu/vanio/easydao/templates/dao.ftl @@ -251,10 +251,8 @@ public class ${t.javaName}${e.daoSuffix}Impl implements ${t.javaName}${e.daoSuff String sql = "update ${t.dbName} " + "set " + <#assign fieldList> -<#list t.nonPkFields as field> -<#if !field.virtual> +<#list t.nonPkAndNotVirtualFields as field> <#if field.blob||field.clob>(updateLobFields?"${field.dbName} = ? <#if field_has_next>, ":"") +<#else> "${field.dbName} = ? <#if field_has_next>, " + - ${fieldList?remove_ending(", ")}