Database Reference
In-Depth Information
// return the mapped content
graphStory.setContent(Lists.newLinkedList(mappedContent.getContent()));
// is there more content?
graphStory.setNext(mappedContent.hasNext());
return graphStory;
}
Mapped Query Results
Query Results are a convenient way to convert results from a Cypher query into POJO interfaces or objects. The
MappedContentRepository 's getContent method first determines the user via a MATCH , then whom the user is
following, and finally the list of status updates to be returned. Using a PageRequest , the query will be provided with a
page, page size, and the sort preference of the sub-graph that is created by the Cypher query.
Using the MappedContent object, the query will map discrete properties that are to be used. In addition to being
able to specify only what needs to be returned, the QueryResult is a more efficient way of reading from the graph. If
the query simply returned each status update as a node, it would require multiple calls to the database and result in a
much slower operation.
To create a QueryResult , you need to apply the @QueryResult annotation as well as @NodeEnity . Next, you need
provide @GraphId for the object and annotate each property with a @ResultColumn that specifies the alias or property
name used within the query. In cases in which you are using aliases for properties, be aware that the @ResultColumn
value must match, including case, exactly to the alias name.
Listing 11-35. The MappedContentRepository Interface and MappedContent Class
// MappedContentRepository
public interface MappedContentRepository extends GraphRepository < MappedContent > {
@Query(" MATCH (u:User {username: {u} }) " +
" WITH u " +
" MATCH (u)-[:FOLLOWS*0..1]->f " +
" WITH DISTINCT f,u " +
" MATCH f-[:CURRENTPOST]-lp-[:NEXTPOST*0..3]-p " +
" RETURN p.contentId as contentId, p.title as title, p.tagstr as tagstr, " +
" p.timestamp as timestamp, p.url as url, f.username as username, f=u as owner ")
Page<MappedContent> getContent (@Param("u") String username, Pageable pageable);
}
// MappedContent
@QueryResult
@NodeEntity
public class MappedContent {
@GraphId
private Long nodeId;
 
Search WWH ::




Custom Search