CypherDSL update to Neo4j 1.7

This commit is contained in:
Michael Hunger
2012-04-19 11:15:23 +02:00
parent caed15e2b7
commit 1ba49bdf1a
2 changed files with 41 additions and 16 deletions

View File

@@ -15,21 +15,14 @@
*/
package org.springframework.data.neo4j.repository;
import com.mysema.query.types.expr.Param;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.neo4j.cypherdsl.CypherQuery;
import static org.neo4j.cypherdsl.CypherQuery.*;
import static org.neo4j.cypherdsl.querydsl.CypherQueryDSL.*;
import org.neo4j.cypherdsl.Execute;
import org.neo4j.cypherdsl.OrderBy;
import org.neo4j.cypherdsl.query.Expression;
import org.neo4j.cypherdsl.query.ReturnExpression;
import org.neo4j.cypherdsl.query.StartExpression;
import org.neo4j.cypherdsl.query.WhereExpression;
import org.neo4j.cypherdsl.querydsl.CypherQueryDSL;
import org.neo4j.cypherdsl.querydsl.QueryDSLReturnExpression;
import org.neo4j.cypherdsl.querydsl.QueryDSLStartExpression;
import org.neo4j.cypherdsl.querydsl.QueryDSLWhere;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
@@ -66,10 +59,10 @@ public class CypherDslRepositoryTest {
@Autowired Neo4jOperations template;
private TestTeam team;
private Map<String,Object> peopleParams;
private Execute query = CypherQuery.start(StartExpression.node("n", "people")).returns(ReturnExpression.nodes("n"));
private Execute query2 = CypherQueryDSL.start(QueryDSLStartExpression.node(QPerson.person, "people")).
private Execute query = start(node("n", "people")).returns(identifier("n"));
private Execute query2 = CypherQueryDSL.start(CypherQueryDSL.node(QPerson.person, "people")).
where(QPerson.person.name.eq("Michael")).
returns(QueryDSLReturnExpression.nodes(QPerson.person));
returns(identifier(QPerson.person));
@Before
public void setUp() throws Exception {

View File

@@ -272,8 +272,10 @@ Iterable<Person> findByParentAgeAndMarried(int age, boolean married)
</para>
<example>
<title>Examples for Cypher-DSL repository</title>
<!-- TODO QueryDSL -->
<programlisting language="java"><![CDATA[
import static org.neo4j.cypherdsl.CypherQuery.*;
import static org.neo4j.cypherdsl.querydsl.CypherQueryDSL.*;
public interface PersonRepository extends GraphRepository<Person>,
CypherDslRepository<Person> {}
@@ -282,7 +284,7 @@ Iterable<Person> findByParentAgeAndMarried(int age, boolean married)
Execute query = start( lookup( "company", "Company", "name", param("name") ) ).
match( path().from( "company" ).in( "WORKS_AT" ).to( "person" )).
returns( nodes( "person" ))
returns( identifier( "person" ))
Page<Person> people = repo.query(query , map("name","Neo4j"), new PageRequest(1,10));
QPerson person = QPerson.person;
@@ -290,7 +292,7 @@ Iterable<Person> findByParentAgeAndMarried(int age, boolean married)
Execute query = start( lookup( company, "Company", company.name, param("name") ) ).
match( path().from( company ).in( "WORKS_AT" ).to( person ).
.where(person.firstName.like("P*").and(person.age.gt(25))).
returns( nodes( person ))
returns( identifier(person) )
EndResult<Person> people = repo.query(query , map("name","Neo4j"));
]]></programlisting>
@@ -299,6 +301,36 @@ Iterable<Person> findByParentAgeAndMarried(int age, boolean married)
</section>
<section>
<title>CypherDSL and QueryDSL</title>
<para>
To use Cypher-DSL with QueryDSL the Mysema dependencies have to be declared explicitly as they are
optional in the CypherDSL project.
</para>
<programlisting language="xml"><![CDATA[<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-core</artifactId>
<version>2.2.3</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-lucene</artifactId>
<version>2.2.3</version>
<optional>true</optional>
<exclusions>
<exclusion>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
<version>2.2.3</version>
<scope>provided</scope>
</dependency>
]]></programlisting>
<para>
It is possible to use the Cypher DSL along with the predicates and code generation features of the QueryDSL project. This will allow
you to use Java objects as part of the query, rather than strings, for the names of properties and such. In order to get this to work you first have