Skip to content
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

Closed
wants to merge 7 commits into from

Conversation

oleg-smith
Copy link

@oleg-smith oleg-smith commented Jan 15, 2017

Fixes #2083
Fixes #2314
Fixes #2596

@Shredder121
Copy link
Member

Keep in mind not all column names are lower camelcase'd.

Also, there are times where column name and Java identifier rules differ.
Java identifiers cannot start with a number, or contain spaces.

@oleg-smith
Copy link
Author

Fixed considering Java identifiers naming.
I'm assuming that if field name is not in lower Camel case, then it will be translated as upper case, which is also suitable for this case.

@@ -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() + "\"");
Copy link
Member

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?

Copy link
Author

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)));
        }

Copy link
Member

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.

@oleg-smith
Copy link
Author

@timowest @Shredder121 @ykrasnouski could you review?

@oleg-smith
Copy link
Author

oleg-smith commented May 9, 2017

@@ -205,6 +240,12 @@ public DefaultConfiguration(
}
module.bind(CodegenModule.VARIABLE_NAME_FUNCTION_CLASS, variableNameFunction);

boolean namesAsConstants = options.containsKey(QUERYDSL_NAMES_AS_CONSTANTS)
Copy link
Member

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;
Copy link
Member

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

Copy link
Author

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.

@jwgmeligmeyling jwgmeligmeyling changed the title 2083 Generating field names as string constants Generating field names as string constants May 31, 2020
Copy link
Member

@jwgmeligmeyling jwgmeligmeyling left a 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.

@stale
Copy link

stale bot commented Jun 2, 2022

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
@stale
Copy link

stale bot commented Jun 8, 2023

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.

@stale stale bot added the wontfix label Jun 8, 2023
@stale stale bot closed this Jun 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support generating field name constants Generating field names as string constants
5 participants