-
Couldn't load subscription status.
- Fork 74
support JSR305 annotation #22
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
Conversation
Signed-off-by: leonhartX <ke.xu@smartnews.com>
Signed-off-by: leonhartX <ke.xu@smartnews.com>
|
Thank you for the great work 👍 I thought that there are several other options to design the config. NamingI have a little bit different idea on naming of the new attribute in config. I came up with two options. Suggestion 1) jsr305AnnotationsRequiredIf we go with a single boolean value for this, I prefer the following name in terms of the consistency with Naming consistency is not the only reason why I think my suggestion may be better. In my understanding, the configuration just means adding necessary annotations for null checker. Enabling the checker would be done by other configuration in the projects using this library. # If you'd like to have JSR-305 annotations in entity classes as well, set the following attribute
# - boolean value: true if you need to generate Nonnull/Nullable annotation-wired entities as well
jsr305AnnotationsRequired: trueSuggestion 2) enabledJsr305AnnotationsAnother option may be an excessive work. In general, if we take possible future enhancements into account, using a flag value may lack extensibility. So, specifying the class names to use as below may be fine. With this design, we can add addtional annotations when some users really need it. # If you'd like to have JSR-305 annotations in entity classes as well, set the following attribute
# - array of String values: possible values are "Nonnull", "Nullable"
enabledJsr305Annotations: [
"Nonnull",
"Nullable"
]However, I personally don't think such enhancements will be necessary in the future even though I am not an expert on JSR-305 and JSR-308. In addition, if we really need such extensibility someday, it's also possible to mark the existing flag value as deprecated and introduce new ones at the right time. So, I would like to suggest to choose Other RequestsHave a new test for thisIf you have time, having a new test for this configuration in Add the new attribute to entityGenConfig.yml examplesOnce you decide the name of the new attribute, please add the attribute to the following
Also, having some explanation on it as below would be preferrable. # If you'd like to have JSR-305 annotations in entity classes as well, set the following attribute
# - boolean value: true if you need to generate Nonnull/Nullable annotation-wired entities as well
jsr305AnnotationsRequired: trueThank you for reading this! |
|
Once you finish working on this, please feel free to ping me. I'm willing to do re-review (I've already approved, my review is no longer required) and work on new version releases! Of course, it's also fine if you could request Sonatype to have your account in |
|
Thanks, I prefer option 1 too, will take some time to fix. |
|
I'm writing tests for this, and found that the current implementation will add the annotation to primitive type either (which is slightly illegal).
what's your opinion about this? |
|
@leonhartX Your idea looks good to me. 👍 |
Signed-off-by: leonhartX <ke.xu@smartnews.com>
Signed-off-by: leonhartX <ke.xu@smartnews.com>
|
When adding tests, the P.S: I checked both |
|
Are you talking about this column? It seems to be a non-null column. https://github.com/smartnews/jpa-entity-generator/blob/v0.99.5/src/test/java/com/example/unit/DatabaseUtil.java#L23 |
|
Yes, so how can this test passed without setting the |
|
hmm, I have been familiar with h2's imperfect behaviers but this one is new to me. We all expect the insertion queries in the following code example result in errors but the reality is that h2 database silently inserts current_timestamp for us. Anyway, the metaedata API seems to be working correctly. // libraryDependencies += "com.h2database" % "h2" % "1.4.199"
import java.sql._
Class.forName("org.h2.Driver")
val conn = DriverManager.getConnection("jdbc:h2:file:./sample/db/blog;MODE=MySQL;TRACE_LEVEL_FILE=2;TRACE_LEVEL_SYSTEM_OUT=2", "USER", "")
val stmt = conn.createStatement()
stmt.executeUpdate("""
create table blog (id integer primary key auto_increment not null, name varchar(30), active tinyint default 0, created_at timestamp not null)
""")
val stmt = conn.createStatement()
stmt.executeUpdate("""insert into blog (name, created_at) values ('tech blog', null);""")
stmt.executeUpdate("""insert into blog (name, created_at) values ('corporate blog', now());""")
val rs = stmt.executeQuery("select * from blog")
while(rs.next()) {
println(rs.getInt("ID") + ", " + rs.getString("NAME") + ", " + rs.getTimestamp("CREATED_AT"))
}
val meta = conn.getMetaData
val rs = meta.getColumns(null, "", "blog", "%")
while(rs.next()) {
println(rs.getString("COLUMN_NAME") + " " + rs.getString("IS_NULLABLE"))
} |
|
I see, so I'll just set the |
|
It seems to be good enough. If you're ready to merge this, please feel free to merge this. Also, if you would like me to work on a new version release, I'm willing to work on it. |
|
Merged the PR but still not sure how to release (I'm requesting the permission on sonatype), so really appreciate if you could do a release this time. 🙇 |
|
Will do. |
|
I just published the following jars. They'll be automatically synced with Maven Central artifacts shortly.
The operations are easy. Running two commands + Clicking buttons several times on Sonatype management console. |
enableJSR305NullCheck(default false) to addNullableandNonnullannotation for code checknullablefield in@Columnannotation