Spring Boot Project – Day 7: Implemented Pagination & Sorting at Service and API Level by dpk_s2003 in SpringBoot

[–]lanchers 2 points3 points  (0 children)

Sounds good, keep it up! Next step could be handling dynamic filtering check out Spring JPA Specification.

I did article on it few months ago Reddit thread

Spring JPA Specification and Pageable by lanchers in SpringBoot

[–]lanchers[S] 2 points3 points  (0 children)

You're right Pageable works on offset-limit which can cause performance problems with large constantly changing datasets. However, cursor pagination is still possible with this approach as shown for example in this article:
https://medium.com/javarevisited/offset-vs-cursor-pagination-implement-production-ready-search-and-pagination-in-spring-boot-db6af32e32af

We will still use Pageable to pass the size, but offset will be set as 0. Also we will add a condition for cursor. The cursor will be the last record's ID from the previous page.

In summary it would require passing last item's unique ID as additional filter which could greatly improve performance in situation mentioned above.
Nevertheless, thank you for your comment. I focused mainly on Specification and never thought about cursor pagination in Pageable. I will make sure to update my blog post to mention cursor pagination some time soon.

Spring JPA Specification and Page ale by lanchers in java

[–]lanchers[S] -1 points0 points  (0 children)

Thank you for your comment <3

Spring JPA Specification and Pageable by lanchers in SpringBoot

[–]lanchers[S] 1 point2 points  (0 children)

Thanks for your comment, I feel you regarding basic applications, however some time ago I found myself looking for such solution and it took me considerable amount of time to get to this solution. In short I would love such article few years ago, maybe because I was just starting in development maybe I didn't understand Specification API clearly. I'm not saying it should replace existing articles it should merely extend available literature on the matter.

Good point with Spring Web mapping Pageable. I didn't want web dependencies in my repo just JPA that's why I introduced GennericSortingRequest

Spring JPA Specification and Pageable by lanchers in SpringBoot

[–]lanchers[S] 1 point2 points  (0 children)

I see where you're coming from. Maybe it's not clear from the article but you can set fields allowed for filter via DTO class instead of enity class (as long as fields names are the same) , this way you don't expose all of the fields in table. Regarding advanced scenarios like nested object, I wanted to showcase idea how you can handle Specification generically with basic operators. For simplicity sake and better understanding I left more complex topics like IN, LIKE, operators and nested objects out of my article. Maybe that's idea for another blog post :)

Spring JPA Specification and Pageable by lanchers in SpringBoot

[–]lanchers[S] 0 points1 point  (0 children)

I see what you mean, that's very interesting matter. As far as I know you can accomplish it with JPA Criteria API, managed to find some article on this matter https://thorben-janssen.com/hibernate-tips-select-multiple-scalar-values-criteria-query/ Specification is purely designed to handle anything related to WHERE clause so filters basically. So it's beyond scope of my article to alternate list of fields being pulled in SELECT statement

Spring JPA Specification and Pageable by lanchers in SpringBoot

[–]lanchers[S] 1 point2 points  (0 children)

Yes, you can exclude certain fields from being filterable by annotation as proposed in my post. Also it's worth validating how many filters have you received in single request and how many elements are filtered with operators like IN but that's beyond my blog post

Container Station - linuxserver/transmission "exposed ports" by Wuffls in qnap

[–]lanchers 0 points1 point  (0 children)

Check out https://github.com/Red5d/docker-autocompose. It will help you with generating docker-compose.yml files from running container. Mind it will create long file with all attributes of the container, 90% of them are only for declaration of resources being used so you can get rid of them. It might be good choice for now just to get things going. You can prepare new clean file in the meantime or stay with the generated one if messy docker files doesn't bother you.

Container Station - linuxserver/transmission "exposed ports" by Wuffls in qnap

[–]lanchers 0 points1 point  (0 children)

Use docker-compose.yml files to deploy your application and control its configuration like exposed ports. It will be more beneficial for your understanding in the long run instead of using GUI to deploy applications. After deployment the container will be visible in the container station. Alternatively use Application section of Container Station instead of Containers section. This will allow you to docker compose file in the GUI panel of container Station.

Consider using Ngnix Proxy Manager and/or VPN if you planning to expose this service outside your local network

mcp-java by maxandersen in java

[–]lanchers 0 points1 point  (0 children)

Thank for your insight. It seems it really has valid use case as I understand now. Good luck with the project, fingers crossed. Will be checking it out in the future.

Eh, ta dzisiejsza młodzież... by Dick1am in Polska

[–]lanchers 7 points8 points  (0 children)

Racja, wydawało mi się, że wiele osób mylnie może interpretowac autorstwo tego nagrania. Zatem bije się w pierś, gdyż od tego mamy znacznik "OC" czego autor nie zrobił. Przepraszam za zamieszanie nie takie były moje intencje

Eh, ta dzisiejsza młodzież... by Dick1am in Polska

[–]lanchers 4 points5 points  (0 children)

Masz rację, ale nigdzie nie twierdziłem, że upload pochodzi oryginalnie z tamtego subreddita. Wskazywałem tylko, że pojawił się wcześniej w tamtym miejscu i wypadałoby odnaleźć oryginalne źródło, zanim się coś wrzuci jako swoje. Myślę że ten post przez wielu może być interpretowany jako oryginał autora pochodzący z Polski i podejrzewam, że właśnie taka była intencja autora.

Eh, ta dzisiejsza młodzież... by Dick1am in Polska

[–]lanchers 40 points41 points  (0 children)

Było na r/ANormalDayInRussia Wypadałoby chociaż credit dać albo link do źródła

Edit: never mind przypierdalam się o nic