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
Generating field names as string constants #2084
Conversation
Keep in mind not all column names are lower camelcase'd. Also, there are times where column name and Java identifier rules differ. |
Fixed considering Java identifiers naming. |
@@ -620,6 +663,10 @@ public void serialize(EntityType model, SerializerConfig config, | |||
|
|||
protected void serialize(EntityType model, Property field, Type type, CodeWriter writer, | |||
String factoryMethod, String... args) throws IOException { | |||
|
|||
String constantFieldName = constantFieldName(field.getEscapedName()); | |||
writer.publicStaticFinal(new ClassType(String.class), constantFieldName, "\"" + field.getName() + "\""); |
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.
use Types.String instead of new ClassType(String.class)
also could these additions be toggable with an option?
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.
@timowest sure, how would you prefer me passing the option? A code example can help.
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.
@timowest ^^
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.
@oleg-smith,
Probably option to toggle this feature could be added as @nAmed constructor param like keywords param in EntitySerializer constructor.
@Named("keywords") Collection<String> keywords
Then default value for it could be binded in CodegenModule.java:69
bind(KEYWORDS, Collections.<String>emptySet());
And in DefaultConfiguration.java you could rebind it to a value gotten from options map.
if (options.containsKey(QUERYDSL_PACKAGE_SUFFIX)) {
module.bind(CodegenModule.PACKAGE_SUFFIX, Strings.nullToEmpty(options.get(QUERYDSL_PACKAGE_SUFFIX)));
}
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.
Sorry for the radio silence.
Yes, that sounds good.
You can kind of see what places you need to update in this PR.
@timowest @Shredder121 @ykrasnouski could you review? |
@timowest @Shredder121 @robertandrewbain @johnktims @ykrasnouski could you review? |
@@ -205,6 +240,12 @@ public DefaultConfiguration( | |||
} | |||
module.bind(CodegenModule.VARIABLE_NAME_FUNCTION_CLASS, variableNameFunction); | |||
|
|||
boolean namesAsConstants = options.containsKey(QUERYDSL_NAMES_AS_CONSTANTS) |
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.
preferably use the same pattern as elsewhere
if (options.containsKey(QUERYDSL_NAMES_AS_CONSTANTS)) {
module.bind(CodegenModule.NAMES_AS_CONSTANTS, Boolean.valueOf(options.get(QUERYDSL_NAMES_AS_CONSTANTS)))
}
import com.google.common.base.Function; | ||
import com.google.common.base.Splitter; | ||
import com.google.common.base.Strings; | ||
import com.mysema.codegen.model.ClassType; | ||
import com.querydsl.codegen.*; | ||
import com.querydsl.codegen.CodegenModule; |
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.
why all these package refactorings?
still to the necessary changes
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.
Can we merge it as is? As it's been a while without update.
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.
PR needs to be updated with current master.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
1 similar comment
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Fixes #2083
Fixes #2314
Fixes #2596