Re: [Neo4j] Cypher DSL and result mapping
On 11/5/11 24:41 , Daniel Yokomizo wrote: > Is there a raw type if nothing is provided (e.g. Map with > alias,result)? With something like this the programmer can use any mapping > tool after. But would be nice to have json support. The Projection class does not perform the query (the results are passed into it), so if you want the raw Iterable, simply don't use Projection. Support for JSON is a great idea though! /Rickard -- Rickard Öberg Developer Neo Technology Twitter: @rickardoberg, Skype: rickardoberg ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] Cypher DSL and result mapping
On Nov 4, 2011 7:45 AM, "Rickard Öberg" wrote: > > On 11/4/11 17:29 , Daniel Yokomizo wrote: > >> What are the projection methods that you would like to see? What are > >> common usecases? > > > > Supporting @java.beans.ConstructorProperties is nice because we can use > > immutable objects as dtos. > > Right, that is a good point, and that will definitely be supported. > > I was more thinking about what kind of ways do you want to transform the > result to objects. QueryDSL has a TON of methods, most of which I think > are mixing concepts wildly: > http://www.querydsl.com/static/querydsl/2.2.3/apidocs/com/mysema/query/Projectable.html > > The methods with "distinct", for example, are done by the DSL itself, > rather than in the projection. Similarly, "unique" and "single" I think > are probably better done by using a functional library on top of an > Iterable (this is available in Qi4j, and most other functional libraries > that work with Iterables as well), i.e. no need to add to the basic > interface. > > But are there other legitimate ways of transforming the result to > objects? Or is iterable(result,resultType) enough? Is there a raw type if nothing is provided (e.g. Map with alias,result)? With something like this the programmer can use any mapping tool after. But would be nice to have json support. > /Rickard > > -- > Rickard Öberg > Developer > Neo Technology > Twitter: @rickardoberg, Skype: rickardoberg > ___ > Neo4j mailing list > User@lists.neo4j.org > https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] Cypher DSL and result mapping
On Fri, Nov 4, 2011 at 10:45 AM, Rickard Öberg < rickard.ob...@neotechnology.com> wrote: > On 11/4/11 17:29 , Daniel Yokomizo wrote: > >> What are the projection methods that you would like to see? What are > >> common usecases? > > > > Supporting @java.beans.ConstructorProperties is nice because we can use > > immutable objects as dtos. > > Right, that is a good point, and that will definitely be supported. > +1, a really good suggestion. I'm not a big fan of that annotation per se, it would have been nicer to annotate each parameter individually, but it is standardized which makes it VERY compelling. -- Tobias Ivarsson Hacker, Neo Technology www.neotechnology.com Cellphone: +46 706 534857 (Swe); +1 650 450 3806 (US) ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] Cypher DSL and result mapping
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.ob...@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 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@lists.neo4j.org > https://lists.neo4j.org/mailman/listinfo/user > -- Tobias Ivarsson Hacker, Neo Technology www.neotechnology.com Cellphone: +46 706 534857 (Swe); +1 650 450 3806 (US) ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] Cypher DSL and result mapping
On 11/4/11 17:29 , Daniel Yokomizo wrote: >> What are the projection methods that you would like to see? What are >> common usecases? > > Supporting @java.beans.ConstructorProperties is nice because we can use > immutable objects as dtos. Right, that is a good point, and that will definitely be supported. I was more thinking about what kind of ways do you want to transform the result to objects. QueryDSL has a TON of methods, most of which I think are mixing concepts wildly: http://www.querydsl.com/static/querydsl/2.2.3/apidocs/com/mysema/query/Projectable.html The methods with "distinct", for example, are done by the DSL itself, rather than in the projection. Similarly, "unique" and "single" I think are probably better done by using a functional library on top of an Iterable (this is available in Qi4j, and most other functional libraries that work with Iterables as well), i.e. no need to add to the basic interface. But are there other legitimate ways of transforming the result to objects? Or is iterable(result,resultType) enough? /Rickard -- Rickard Öberg Developer Neo Technology Twitter: @rickardoberg, Skype: rickardoberg ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] Cypher DSL and result mapping
On Nov 4, 2011 3:11 AM, "Rickard Öberg" 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 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? Supporting @java.beans.ConstructorProperties is nice because we can use immutable objects as dtos. > /Rickard > > -- > Rickard Öberg > Developer > Neo Technology > Twitter: @rickardoberg, Skype: rickardoberg > ___ > Neo4j mailing list > User@lists.neo4j.org > https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
[Neo4j] Cypher DSL and result mapping
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 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@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user