diff --git a/src/docbkx/reference/programming-model/conversion.xml b/src/docbkx/reference/programming-model/conversion.xml index d1efd64fc..0060fa5ff 100644 --- a/src/docbkx/reference/programming-model/conversion.xml +++ b/src/docbkx/reference/programming-model/conversion.xml @@ -13,4 +13,57 @@ It is also possible to provide a custom ResultConverter that additionally takes care of conversions. + +
+ Mapping Query Results + + For both queries executed via the result conversion DSL as well as repository methods, it is possible to specify + a conversion of complex query results to POJO interfaces or objects. Those result objects are then populated with + the query result data and can be serialized and sent to a different part of the applicaton, e.g. a frontend-ui. + + + Use an interface annotated with @QueryResult and getter methods which might be annotated with + @ResultColumn("columnName") to match the query-result column names. Or use a plain POJO, both work. + + + + Example of query result mapping + { + +@Query("START movie=node:Movie(id={0}) + MATCH movie-[rating?:rating]->(), + movie<-[:ACTS_IN]-actor + RETURN movie, COLLECT(actor), AVG(rating.stars)") +MovieData getMovieData(String movieId); + +@QueryResult +public class MovieData { + Movie movie; + + @ResultColumn("AVG(rating.stars)") + Double rating; + + @ResultColumn("COLLECT(actor)") + Collection cast; +} + +// alternatively use +@QueryResult +public interface MovieData { + @ResultColumn("movie") + Movie getMovie(); + + @ResultColumn("AVG(rating.stars)") + Double getRating(); + + @ResultColumn("COLLECT(actor)") + Iterable getCast(); +} +}]]> + + + + +
\ No newline at end of file diff --git a/src/docbkx/reference/programming-model/programming-model.xml b/src/docbkx/reference/programming-model/programming-model.xml index 848eca3ae..2d3241ede 100644 --- a/src/docbkx/reference/programming-model/programming-model.xml +++ b/src/docbkx/reference/programming-model/programming-model.xml @@ -16,6 +16,7 @@ +