Paging and sorting in Spring Data Neo4j 4

纵然是瞬间 提交于 2019-11-29 09:54:29

At the moment this isn't possible.

To enable this feature we'd need to do a few things. First at startup we would need to inspect the query's associated method signature and mark the query as requiring paging. Then at runtime when the method was invoked we'd need to obtain the pageable instance, extract the page parameters and apply them as SKIP and LIMIT clauses to the associated Cypher query. Finally, on return, we'd need wrap the results in a Page object. So there's a bit of work to be done to enable this.

In the meantime you could try adding the SKIP and LIMIT clauses with parameterised values to the query, and pass the appropriate values in via to the query method. I haven't tried this, but it should work - in theory:

  @Query("MATCH (t:Topic)-[:HAS_OFFICER]->(u:User) "
+ "WHERE t.id = {0} "
+ "RETURN  u SKIP {1} LIMIT {2}" )
public List<User> topicOfficers(long topicId, long skip, long limit)

This is now allowed using Sort or Pageable interfaces in your query, and was fixed in DATAGRAPH-653 and marked as fixed in version 4.2.0.M1 (currently in pre-release).

Queries such as the following are possible:

@Query("MATCH (movie:Movie {title={0}})<-[:ACTS_IN]-(actor) RETURN actor")
List<Actor> getActorsThatActInMovieFromTitle(String movieTitle, Sort sort);

and:

@Query("MATCH (movie:Movie {title={0}})<-[:ACTS_IN]-(actor) RETURN actor")
Page<Actor> getActorsThatActInMovieFromTitle(String movieTitle, PageRequest page);

(sample from Cypher Examples in the Spring Data + Neo4j docs)

Finding Spring Data Neo4j Pre-Release Milestone Builds:

You can view the dependencies information for any release on the project page. And for the 4.2.0.M1 build the information for Gradle (you can infer Maven) is:

dependencies {
    compile 'org.springframework.data:spring-data-neo4j:4.2.0.M1'
}

repositories {
    maven {
        url 'https://repo.spring.io/libs-milestone'
    }
}

Any newer final release should be used instead.

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