Database Reference
In-Depth Information
The next snippet shows how you can return basic aggregation-type values in Cypher, such
as counts. In this case, you're looking for a count of the total number of friends of friends,
which according to the submodel depicted in
figure 9.9
,
should be four:
@Query(value =
"match (n)-[r:IS_FRIEND_OF]-(friend)-[r2:IS_FRIEND_OF]-(fof) " +
"where id(n) = {self} " +
"return count(distinct fof)")
Long totalNumFriendsOfFriends;
Annotation on repository interfaces
The
@Query
annotation can also be applied to methods that you may want to define
against a repository method.
Listing 9.13.
@Query
annotation on repository
Note that you're no longer using the
{self}
reference. Now, even more powerfully, you
have access to the parameters passed into the method. The parameters are available as in-
crementingvaluesstartingatzero{0},whichcorrespondstothefirstargumentinthemeth-
od signature, {1} to the second, and so on.
Once again there's no need for you to implement any of the logic to execute the query or
dothemappingtoconverttheresultintoPOJOs,primitives,andthelike.SDNdoesthisall
for you.
9.5.2. Dynamically derived queries
Anotherreallyneatwayofbeingabletodefineaquerywithoutneedingtowriteevenaline
ofCyphercodeistotakeadvantageofdynamicallynamedfinderorgetmethods.Whenev-