-
Notifications
You must be signed in to change notification settings - Fork 30
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
Adding CRUD Annotations for Dynamic Repositories #282
Conversation
@gavinking @njr-11 it still WIP, I hope finishi until our meeting today. |
I think this is reasonable, though would still expect a method called |
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 this is reasonable, though would still expect a method called
save
ordelete
to just do the right thing
I agree with Graeme. This pattern is reasonable, but unnecessary.
It would also prevent us from being able to better define these annotations for other purposes in the future, so I am not in favor of it.
If the consensus of the group is to put these changes in now, there are a couple of minor errors in the JavaDoc that will need correcting. I do appreciate that you've put in the effort to fully specify the requirements that the user will need to know within the JavaDoc.
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.
It turns out there were more issues than I realized in the JavaDoc. Hopefully I found all of them.
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.
It looks like you missed some review comments from before (Github probably collapsed/hid them) and I added a couple of new ones, at least one of which is my fault from introducing a grammar mistake (left out the word "the") in one of my previous suggestions.
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.
Recommend switching the exception type from IllegalStateException
to UnsupportedOperationException
Looking at the JavaDoc for IllegalStateException would imply that the operation is valid, but being invoked at the wrong time:
Signals that a method has been invoked at an illegal or inappropriate time. In other words, the Java environment or Java application is not in an appropriate state for the requested operation.
That isn't what we want to convey. The point we are trying to get across with the exception is that combining multiple operation annotations isn't supported.
@njr-11 I mean when this code happened: @Insert
@Update
void operation(Car car); Given a relational database, both have support, don't they? But is it one I will execute? |
I think we agree here. A combination |
I will improve the documentation, but I hold this one, mainly, because the insert and update behavior will move to here as well. |
It might be worth pointing out that an implementation of Jakarta Data might also choose to detect (and report) this error at compile time. |
Signed-off-by: Otavio Santana <[email protected]>
Signed-off-by: Otavio Santana <[email protected]>
Signed-off-by: Otavio Santana <[email protected]>
Signed-off-by: Otavio Santana <[email protected]>
Signed-off-by: Otavio Santana <[email protected]>
Signed-off-by: Otavio Santana <[email protected]>
Signed-off-by: Otavio Santana <[email protected]>
Co-authored-by: Nathan Rauh <[email protected]>
Co-authored-by: Nathan Rauh <[email protected]>
Co-authored-by: Nathan Rauh <[email protected]>
Co-authored-by: Nathan Rauh <[email protected]>
Co-authored-by: Nathan Rauh <[email protected]>
Co-authored-by: Nathan Rauh <[email protected]>
Co-authored-by: Nathan Rauh <[email protected]>
Signed-off-by: Otavio Santana <[email protected]>
Signed-off-by: Otavio Santana <[email protected]>
Signed-off-by: Otavio Santana <[email protected]>
Co-authored-by: Nathan Rauh <[email protected]>
Co-authored-by: Nathan Rauh <[email protected]>
Co-authored-by: Nathan Rauh <[email protected]>
Co-authored-by: Nathan Rauh <[email protected]>
Signed-off-by: Otavio Santana <[email protected]>
Signed-off-by: Otavio Santana <[email protected]>
8e7428c
to
cf60d68
Compare
Signed-off-by: Otavio Santana <[email protected]>
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'll agree to the same compromise here as on 287 - the entity return value is okay for Insert, but not for Update, where it is inefficient and forces extra retrieval from the database.
Co-authored-by: Nathan Rauh <[email protected]>
Co-authored-by: Nathan Rauh <[email protected]>
Co-authored-by: Nathan Rauh <[email protected]>
Co-authored-by: Nathan Rauh <[email protected]>
Co-authored-by: Nathan Rauh <[email protected]>
Co-authored-by: Nathan Rauh <[email protected]>
Co-authored-by: Nathan Rauh <[email protected]>
Signed-off-by: Otavio Santana <[email protected]>
Signed-off-by: Otavio Santana <[email protected]>
As we did with insert, how about allowing both? However, if the user works with a Java record of any version control they can work with that as well. |
Yes, that's a good point, in the case of the annotation, we don't need to choose a single return type, and can be more flexible like this. I would be fine with that, but please let's use a different pull after this one goes in. It is already big enough and I think we're otherwise almost ready to merge this pull. I highlighted 3 code review comments from before (hopefully non-controversial) that hid had marked outdated but still apply. |
Co-authored-by: Nathan Rauh <[email protected]>
Co-authored-by: Nathan Rauh <[email protected]>
Co-authored-by: Nathan Rauh <[email protected]>
You are right it became huge! |
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.
You are right it became huge!
Please review it and I will open a new PR to move this update discussion.
It looks good now. Thanks!
This Pull Request (PR) proposes the addition of new annotations for dynamic Repositories within the Jakarta Data framework:
Insert
,Delete
,Update
, andSave
. These annotations simplify and enhance the interaction with data entities in dynamic Repository interfaces. They provide a more intuitive way to declare methods for various CRUD (Create, Read, Update, Delete) operations.Benefits:
Improved Code Readability: The new annotations make it easier to identify the intended operation of each method within dynamic Repositories, improving code readability and maintainability.
Consistency Across Operations: Each annotation enforces a specific operation type, ensuring consistency in method declarations and reducing potential errors.
Enhanced Documentation: The Javadoc documentation for these annotations offers comprehensive explanations, helping developers understand their usage and behavior.
Type-Safe Returns: The annotations provide type safety by ensuring that the return type matches the parameter type, enhancing code quality.
Sample Dynamic Repository:
As an example, consider a dynamic Repository interface for a
Garage
that managesCar
entities:In this example, the
@Save
annotation indicates that thepark
method performs an insert operation and returns the insertedCar
entity. Similarly, the@Update
,@Delete
, and@Save
annotations indicate their respective operations.Usage:
Developers can now use these annotations to create dynamic Repository interfaces that are more expressive and self-documenting, leading to cleaner and more maintainable code.