-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
generate sql script from entity #1202
Conversation
<#assign type = "BOOLEAN"> | ||
<#elseif input_type?contains("Instant") || input_type?contains("Timestamp")> | ||
<#assign type = "TIMESTAMP"> | ||
<#elseif input_type?contains("Date") || input_type?contains("Calender")> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is "Calendar" (typo)
If you have types here, please check for the full type name as otherwise, it might have unexpected side effects if there are more than one class named like that.
</#if> | ||
<#assign columns = columns + [{"name": name, "type":type}]> | ||
<#elseif !field.type?starts_with("List<") && !field.type?starts_with("Set<")> | ||
<#if field.type?contains("Entity")> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
more compliant would be to check if the type name ends with.
As a class named EntityCrawler would even match this check
<#assign type = type + " AUTO_INCREMENT"> | ||
</#if> | ||
<#assign columns = columns + [{"name": name, "type":type}]> | ||
<#elseif !field.type?starts_with("List<") && !field.type?starts_with("Set<")> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here I would better ask for instanceof in a java implementation. I think there are already functions to do so.
So you could easily ask JavaUtil.isCollection( for the full qualified type name.
This would even include the cases where you have Collection< or LinkedList< or anything else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current implementation of isCollection only checks the field which is declared in the class itself and not from parent class. I added a new implementation to check all field recursively!
<#else> | ||
<#assign type = "VARCHAR(255)"> | ||
</#if> | ||
</#macro> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here I would think macro is a little problematic.
In FreeMarker, you have macros and functions.
Macros are program snippets which will be copied to the place and executed there. No isolation of variables etc. such that it might be hard to reuse macros in any place as variables have to have the same name etc.
So what you want to do here is I think better call a freemarker function which returns to you the string of the type, which you can then assign in your template to a local variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, but the new Java methods should have test cases to make sure they always work correctly
* full qualified class name | ||
* @return the annotated table name if existed or null | ||
*/ | ||
public String getEntityTableName(String className) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a test case for this method to src/test/java/com/devonfw/cobigen/templates/devon4j/test/utils/JavaUtilTest.java
* full qualified class name | ||
* @return the primary key and its type if found or null | ||
*/ | ||
public String getPrimaryKey(String className) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a test case for this method to src/test/java/com/devonfw/cobigen/templates/devon4j/test/utils/JavaUtilTest.java
* {@link String} the name of the field | ||
* @return type of the field in String | ||
*/ | ||
public String getCanonicalNameOfField(String className, String fieldName) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a test case for this method to src/test/java/com/devonfw/cobigen/templates/devon4j/test/utils/JavaUtilTest.java
* {@link String} the name of the field | ||
* @return true if the field is an instance of java.utils.Collections | ||
*/ | ||
public boolean isCollection2(Class<?> pojoClass, String fieldName) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a test case for this method to src/test/java/com/devonfw/cobigen/templates/devon4j/test/utils/JavaUtilTest.java
1d87bb7
to
4e046bf
Compare
The base branch was changed.
|
continued in #1570 |
Relate #955 .
Implements