From 952f4bf5a50df5adef77c89cfc68a41609d12e3b Mon Sep 17 00:00:00 2001 From: Jan Wedding Date: Mon, 26 Aug 2024 10:39:42 +0200 Subject: [PATCH] WIP: Refactor to avoid duplicate code and to more easily extend jakarta persistence configuration in Column #27048 --- ...istClass_.java.jhi.jakarta_persistence.ejs | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/generators/spring-data-relational/templates/src/main/java/_package_/_entityPackage_/domain/_persistClass_.java.jhi.jakarta_persistence.ejs b/generators/spring-data-relational/templates/src/main/java/_package_/_entityPackage_/domain/_persistClass_.java.jhi.jakarta_persistence.ejs index e5360b26c18e..b293a79cd2e6 100644 --- a/generators/spring-data-relational/templates/src/main/java/_package_/_entityPackage_/domain/_persistClass_.java.jhi.jakarta_persistence.ejs +++ b/generators/spring-data-relational/templates/src/main/java/_package_/_entityPackage_/domain/_persistClass_.java.jhi.jakarta_persistence.ejs @@ -52,16 +52,31 @@ import org.hibernate.type.SqlTypes; <%_ if (field.fieldTypeBytes) { _%> @Lob <%_ } _%> - <%_ if (field.fieldTypeTemporal || field.fieldTypeDuration) { _%> - @Column(name = "<%- field.fieldNameAsDatabaseColumn %>"<% if (field.fieldValidationRequired) { %>, nullable = false<% } %><% if (field.fieldValidationUnique) { %>, unique = true<% } %>) - <%_ } else if (field.fieldTypeBigDecimal) { _%> - @Column(name = "<%- field.fieldNameAsDatabaseColumn %>", precision = 21, scale = 2<% if (field.fieldValidationRequired) { %>, nullable = false<% } %><% if (field.fieldValidationUnique) { %>, unique = true<% } %>) - <%_ } else if (field.fieldTypeUUID && (prodDatabaseTypeMysql || prodDatabaseTypeMariadb)) { _%> + <%_ + const fieldTypeUuidAndMysqlDbType = field.fieldTypeUUID && (prodDatabaseTypeMysql || prodDatabaseTypeMariadb); + if (fieldTypeUuidAndMysqlDbType) { _%> @JdbcTypeCode(SqlTypes.VARCHAR) - @Column(name = "<%- field.fieldNameAsDatabaseColumn %>", length = 36<% if (field.fieldValidationRequired) { %>, nullable = false<% } %><% if (field.fieldValidationUnique) { %>, unique = true<% } %>) - <%_ } else { _%> - @Column(name = "<%- field.fieldNameAsDatabaseColumn %>"<% if (field.fieldValidate === true) { %><% if (field.fieldValidationMaxLength) { %>, length = <%= field.fieldValidateRulesMaxlength %><% } %><% if (field.fieldValidationRequired) { %>, nullable = false<% } %><% if (field.fieldValidationUnique) { %>, unique = true<% } %><% } %>) <%_ } _%> + @Column(name = "<%- field.fieldNameAsDatabaseColumn %>" + <%_ if (field.fieldTypeBigDecimal) { _%> + , precision = 21, scale = 2 + <%_ } else if (fieldTypeUuidAndMysqlDbType) { _%> + , length = 36 + <%_ } _%> + + <%_ if (field.fieldValidate === true) { _%> + <%_ if (field.fieldValidationMaxLength && !fieldTypeUuidAndMysqlDbType) { _%> + , length = <%= field.fieldValidateRulesMaxlength %> + <%_ } _%> + <%_ if (field.fieldValidationRequired) { _%> + , nullable = false + <%_ } _%> + <%_ if (field.fieldValidationUnique) { _%> + , unique = true + <% } %> + <%_ } _%> + ) + <&_ } -&> <%_ } -%>