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

Refactor and fix repository and REST API #14

Open
hohwille opened this issue Aug 13, 2021 · 0 comments
Open

Refactor and fix repository and REST API #14

hohwille opened this issue Aug 13, 2021 · 0 comments
Assignees

Comments

@hohwille
Copy link
Contributor

hohwille commented Aug 13, 2021

The reference app should be a best-practice reference.
During my reviews of #7 I looked a little deeper into the code that was never entirely reviewed before as it seems.

The repository has several flaws:
https://github.com/devonfw-sample/devon4quarkus-reference/tree/master/src/main/java/com/devonfw/demoquarkus/domain/repo

  • it does not properly support paging
  • it does a query with a JPQL query given as String inside fragment implementation rather than using @Query annotation in repository omitting any implementation. The latter is actually the real benefit of spring-data-jpa as it will find the query when the application starts up and will create a prepared statement for it. This will improve performance and also ensures that invalid queries lead to fast failure (developers get exception when app is started rather than at runtime).
  • it does more or less the same query with 4 different technologies. While this was great for evaluaiton (see issue Evaluate spring-data on quarkus devonfw-forge/devonfw-microservices#37) it does not make sense from a business point of view (see Change quarkus reference app from animals to products #9). Besides best practice is to use native queries only in rare cases for performance-tuning where JPQL is not sufficient. Therefore my suggestion would be to reduce all this to QueryDSL what is our recommended technology for dyanmic queries and alongside have something like findByName (or findByTitle) based on static @Query method.

As a result also the REST API is not suitable for a reference.

Also I collected review-feedback for logic layer:

  • Delete method should be void and shall not load the entity what is a waste of performance.
  • Save method should be void and shall not return updated Dto: With our new approach based on quarkus we can not make save return the new Dto as the result will be incorrect. You can manually test it and will see that you will get a wrong modificationCounter (@Version). To do so you first need to implement Add abstract Entity base-class #13 as currently we are lacking the @Version property. The problem is that hibernate only updates the @Version property after TX gets committed, but we create the DTO from the entity via MapStruct before that. In devon4j with spring we have solved this complex issue in our bean-mapper solution for dozer and orika but with OCX we agreed on MapStruct and that we simply try to avoid this problem by design of the REST API. So to actually get the update after save you will have to call another REST method to get the entity by its ID again on the client.
  • With devon4j we so far suggested this UcFind* and UcManage* approach. As I already stated in Add guide for quarkus logic layer devonfw/devon4j#432 (review) this leads to developers stop thinking and putting everything else into UcManage*. So I am thinking to create always dedicated use-cases and split up UcManage* into UcSave* and UcDelete* instead. If we want to save boilerplate code, I am fine with omitting the interfaces and just have the implementation class. All public methods are the API, all other methods are not API. No interface required.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants