[Neo4j] Cypher DSL and result mapping

Tobias Ivarsson tobias.ivarsson at neotechnology.com
Fri Nov 4 10:50:19 CET 2011


I started a prototype for something similar a while back:
https://github.com/thobe/neo4j-community-experiments/tree/cypher-annotations

It has a different approach to constructing queries, it uses annotations
with query strings in them, but uses compile time annotation processing to
process those annotations in order to verify syntax. In the future (when
Cypher supports it) I'd like to do type checking as well.

What it has that is similar though is the way it converts the result to
java classes. I know that Spring-Data-Neo4j does similar things as well.
Since that kind of conversion seems to be something that multiple higher
level libraries do, it would probably make sense to move it to a shared
place.

Note please that this branch is just three hours worth of throwing some
ideas together, it's not complete, but should at least display the ideas.

-tobias

On Fri, Nov 4, 2011 at 6:10 AM, Rickard Öberg <
rickard.oberg at neotechnology.com> wrote:

> Hi,
>
> I've briefly started to look at how to map Cypher query results into
> DTO's. I'm using the QueryDSL helper classes to do it, but instead of
> putting the projection methods into the query object (as QueryDSL does
> it), I have a separate Projection class for it. The reason is that I
> don't want to require DSL users to have access to the execution engine,
> which will obviously not be the case if you are creating queries on the
> client which are to be sent to the server.
>
> Here's an example of what I want it to look like when used:
> Projection projection = new Projection(engine);
>
> Iterable<Friend> friends = projection.iterable( start( node( "john",
> john ) )
>               .match( path().from( "john" ).out( "friend" )
>                           .link().out( "friend" ).to( "fof" ) )
>               .returns( properties( "john.name", "fof.name" ) ),
> Friend.class );
> System.out.println( friends );
> ---
> So the Projection encapsulates the reference to the query execution,
> which means that you don't need to have a reference to it when executing
> the queries to do the projection. The "iterable" method takes a DSL
> query and the Java class you want the results to be projected into.
> Pretty straightforward.
>
> For now the code assumes that the fields in Friend is the same as the
> order of the return results. This is broken, and will be fixed later to
> use proper mapping, preferably with aliases in the return statement as
> hints.
>
> What are the projection methods that you would like to see? What are
> common usecases?
>
> /Rickard
>
> --
> Rickard Öberg
> Developer
> Neo Technology
> Twitter: @rickardoberg, Skype: rickardoberg
> _______________________________________________
> Neo4j mailing list
> User at lists.neo4j.org
> https://lists.neo4j.org/mailman/listinfo/user
>



-- 
Tobias Ivarsson <tobias.ivarsson at neotechnology.com>
Hacker, Neo Technology
www.neotechnology.com
Cellphone: +46 706 534857 (Swe); +1 650 450 3806 (US)


More information about the User mailing list