java - MapResult with CypherDSL -
i have query, built cypher-dsl (b/c match
-clause dynamic) , result-set contains nodes represented @nodeentity
annotated pojos (amongst other columns).
my question is: there way have result of dynamic (non-annotated) query, wrapped @mapresult
(or regular map nodeentities values)?
the following approach doesn't seem work, because inferred type of graphrepository
has either node- or relationshipentity:
@nodeentity public class customer { @graphid long id; ... } @mapresult public interface customerqueryresult { @resultcolumn("cust") customer getcustomer(); @resultcolumn("val1") int getval1(); ... } public interface customerqueryrepository extends graphrepository<customerqueryresult> { } @service public class searchservice { private customerqueryrepository repo; ... @inject public searchservice(customerqueryrepository repo, ...) { this.repo = repo; ... } public iterable<customerqueryresult> search(...) { execute cyquery = start(...) ... .returns( "cust", "val1", ... ); return this.repo.query(cyquery.tostring(), ...); } }
i'm using spring-data-neo4j version 2.3.0.m1
thanks help, in advance
update: ok, using neo4jtemplate
's query
, convert
methods, job:
@inject public searchservice(neo4jtemplate template, ...) { this.template = template; ... } public list<queryresult> search(...) { list<queryresult> result = new arraylist<>(); execute cyquery = start(...) ... .returns( "cust", "val1", ... ); (map<string, object> res : this.template.query(cyquery.tostring(), ...)) { customer cust = this.template.convert((nodeproxy)res.get("cust"), customer.class); result.add(new queryresult() .setcustomer(cust) ... ); } return result; }
(assuming customer class , not interface anymore)
however, there maybe better way it?
you should able use query(...).to(customerqueryresult.class)
.
and there cypherdslrepository
can use run queries , endresult
can use to(customerqueryresult.class)
on.
public interface cypherdslrepository<t> { page<t> query(execute query, map<string, object> params, pageable page); page<t> query(execute query, execute countquery, map<string, object> params, pageable page); endresult<t> query(execute query, map<string, object> params); } public interface customerqueryrepository extends graphrepository<customer>, cypherdslrepository<customer> { }
Comments
Post a Comment