SDN4 custom query pagination alternative for Page contents

送分小仙女□ 提交于 2019-12-12 02:51:53

问题


Currently Pagination isn't supported in SDN4 (Ref: Paging and sorting in Spring Data Neo4j 4)

It's possible to specify the SKIP and LIMIT clauses ourselves to retrieve parts of the results, however for our system we also need the getTotalPages(), isFirst() and isLast() values from the Page returned when performing a custom paging query.

Is there an alternative way for us to retrieve these values using SDN4 / OGM? Alternatively, are there any recommendations / references to code that can be provided for us to implement this ourselves (perhaps in the construction of the Page object)?

Thanks!


回答1:


As you have gathered, the Pagination object in the OGM which backs Spring's Page object does not use a page count or return one. Spring's Page object provides a method to return the total number of pages, but it is up to the underlying implementation - Mongo, JPA, Neo4j, etc to implement this. Spring's Page object uses this value to determine whether or not a "next" page exists. Our implementation "cheats" by telling Spring that it always does - until a request for a new page returns fewer than a page worth of results.

Unfortunately there is no generalised way to return a page count that doesn't involve finding all of the results first and then counting them. Doing this for custom queries that may potentially return many thousands of rows runs the obvious risk of running out of heap space on the server. (Note that the underlying implementation in Neo4j using SKIP and LIMIT does not have to pre-load all the results into memory so it does not run into this problem).



来源:https://stackoverflow.com/questions/32011358/sdn4-custom-query-pagination-alternative-for-page-contents

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!