Paging and Sorting in Spring Neo4j 4 Data

Is there page support for custom queries in SDN4?

  • If so, how does it work?
  • If not, is there a desktop?

I have the following Spring Data Neo4j 4 repository:

@Repository public interface TopicRepository extends GraphRepository<Topic>,IAuthorityLookup { // other methods omitted @Query("MATCH (t:Topic)-[:HAS_OFFICER]->(u:User) " + "WHERE t.id = {0} " + "RETURN u") public Page<User> topicOfficers(Long topicId, Pageable pageable); } 

And the corresponding test file:

 @Test public void itShouldReturnAllOfficersAsAPage() { Pageable pageable = new PageRequest(1,10); Page<User> officers = topicRepository.topicOfficers(1L, pageable); assertNotNull(officers); } 

When I run the test, I encounter the following exception

 Failed to convert from type java.util.ArrayList<?> to type org.springframework.data.domain.Page<?> for value '[ org.lecture.model.User@1 ]'; nested exception is org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type java.util.ArrayList<?> to type org.springframework.data.domain.Page<?> 

This is my setup:

 dependencies { //other dependencies omitted compile("org.neo4j:neo4j-cypher-dsl:2.0.1") compile "org.neo4j.app:neo4j-server:2.2.2" compile(group: 'org.springframework.data', name: 'spring-data-neo4j', version: '4.0.0.BUILD-SNAPSHOT') compile(group: 'org.springframework.data', name: 'spring-data-neo4j', version: '4.0.0.BUILD-SNAPSHOT', classifier: 'tests') testCompile(group: 'org.neo4j', name: 'neo4j-kernel', version: '2.2.2', classifier: 'tests') testCompile(group: 'org.neo4j.app', name: 'neo4j-server', version: '2.2.2', classifier: 'tests') testCompile(group: 'org.neo4j', name: 'neo4j-io', version: '2.2.2', classifier: 'tests') } 

The snapshot used allows you to handle pagination, since the following test is simple:

 @Test public void itShouldReturnAllTopicsAsAPage() { Pageable pageable = new PageRequest(1,10); Page<Topic> topics = topicRepository.findAll(pageable); assertNotNull(topics); } 
+7
java spring neo4j spring-data-neo4j-4
source share
2 answers

This is currently not possible.

To enable this feature, we need to do a few things. First, at startup, we will need to verify the signature of the method associated with the request and mark the request as requiring paging. Then, at run time, when the method was called, we would need to get an instance with the ability to view it, extract the page parameters and apply them as SKIP and LIMIT sentences to the corresponding Cypher request. Finally, upon returning, we need to wrap the results in a page object. Therefore, a little work needs to be done to do this.

In the meantime, you can try adding SKIP and LIMIT clauses with parameterized values ​​to the query and pass the corresponding values ​​in the via method using the query method. I have not tried this, but it should work - theoretically:

  @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) 
+4
source share

This is now resolved using the Sort or Pageable in your request and fixed in DATAGRAPH-653 and marked as fixed in version 4.2.0.M1 (currently in the preliminary release).

Requests such as:

 @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 Spring Data + Neo4j docs)

Search for Spring Data Neo4j Milestone Builds Preview:

You can view dependency information for any version on the project page. And for the assembly 4.2.0.M1 information for Gradle (you can conclude that Maven):

 dependencies { compile 'org.springframework.data:spring-data-neo4j:4.2.0.M1' } repositories { maven { url 'https://repo.spring.io/libs-milestone' } } 

Instead, any new final release should be used.

+4
source share

All Articles