Last active
April 15, 2019 17:57
-
-
Save TimmyStorms/5531172 to your computer and use it in GitHub Desktop.
Example that shows how to use QueryDSL with Neo4j.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.github.timmystorms.querydsl.entity; | |
import com.mysema.query.annotations.QueryEntity; | |
@QueryEntity | |
public final class Person { | |
private Long id; | |
private String firstName; | |
private String lastName; | |
public Person() { | |
} | |
public Person(final String firstName, final String lastName) { | |
this.firstName = firstName; | |
this.lastName = lastName; | |
} | |
public Long getId() { | |
return id; | |
} | |
public void setId(Long id) { | |
this.id = id; | |
} | |
public String getFirstName() { | |
return firstName; | |
} | |
public void setFirstName(String firstName) { | |
this.firstName = firstName; | |
} | |
public String getLastName() { | |
return lastName; | |
} | |
public void setLastName(String lastName) { | |
this.lastName = lastName; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.github.timmystorms.querydsl.entity; | |
import static org.junit.Assert.assertEquals; | |
import static org.neo4j.cypherdsl.CypherQuery.node; | |
import static org.neo4j.cypherdsl.CypherQuery.nodesById; | |
import static org.neo4j.cypherdsl.CypherQuery.start; | |
import static org.neo4j.cypherdsl.querydsl.CypherQueryDSL.toBooleanExpression; | |
import org.junit.Test; | |
public class PersonTest { | |
@Test | |
public void queryFirstName() { | |
final QPerson person = QPerson.person; | |
final String query = "CYPHER 1.8 START person=node(1) WHERE person.firstName=\"P\" RETURN (person)"; | |
assertEquals( | |
query, | |
start(nodesById("person", 1)).where(toBooleanExpression(person.firstName.eq("P"))).returns( | |
node("person")).toString()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>com.github.timmystorms</groupId> | |
<artifactId>neo4j-querydsl</artifactId> | |
<version>0.0.1-SNAPSHOT</version> | |
<build> | |
<plugins> | |
<plugin> | |
<groupId>com.mysema.maven</groupId> | |
<artifactId>maven-apt-plugin</artifactId> | |
<version>1.0.4</version> | |
<configuration> | |
<processor>com.mysema.query.apt.QuerydslAnnotationProcessor</processor> | |
</configuration> | |
<executions> | |
<execution> | |
<id>sources</id> | |
<phase>generate-sources</phase> | |
<goals> | |
<goal>process</goal> | |
</goals> | |
<configuration> | |
<outputDirectory>src/main/java</outputDirectory> | |
</configuration> | |
</execution> | |
</executions> | |
</plugin> | |
</plugins> | |
<pluginManagement> | |
<plugins> | |
<plugin> | |
<groupId>org.eclipse.m2e</groupId> | |
<artifactId>lifecycle-mapping</artifactId> | |
<version>1.0.0</version> | |
<configuration> | |
<lifecycleMappingMetadata> | |
<pluginExecutions> | |
<pluginExecution> | |
<pluginExecutionFilter> | |
<groupId>com.mysema.maven</groupId> | |
<artifactId>maven-apt-plugin</artifactId> | |
<versionRange>[1.0.2,)</versionRange> | |
<goals> | |
<goal>process</goal> | |
</goals> | |
</pluginExecutionFilter> | |
<action> | |
<execute /> | |
</action> | |
</pluginExecution> | |
</pluginExecutions> | |
</lifecycleMappingMetadata> | |
</configuration> | |
</plugin> | |
</plugins> | |
</pluginManagement> | |
</build> | |
<dependencies> | |
<dependency> | |
<groupId>org.neo4j</groupId> | |
<artifactId>neo4j</artifactId> | |
<version>1.9.RC1</version> | |
</dependency> | |
<dependency> | |
<groupId>org.neo4j</groupId> | |
<artifactId>neo4j-cypher-dsl</artifactId> | |
<version>1.9.M04</version> | |
</dependency> | |
<dependency> | |
<groupId>com.mysema.querydsl</groupId> | |
<artifactId>querydsl-core</artifactId> | |
<version>2.8.0</version> | |
</dependency> | |
<dependency> | |
<groupId>com.mysema.querydsl</groupId> | |
<artifactId>querydsl-apt</artifactId> | |
<version>2.8.0</version> | |
</dependency> | |
<dependency> | |
<groupId>com.mysema.querydsl</groupId> | |
<artifactId>querydsl-lucene</artifactId> | |
<version>2.8.0</version> | |
<exclusions> | |
<exclusion> | |
<groupId>org.apache.lucene</groupId> | |
<artifactId>lucene-core</artifactId> | |
</exclusion> | |
</exclusions> | |
</dependency> | |
<!-- Optional test dependencies --> | |
<dependency> | |
<groupId>junit</groupId> | |
<artifactId>junit</artifactId> | |
<version>4.11</version> | |
<scope>test</scope> | |
</dependency> | |
</dependencies> | |
<repositories> | |
<repository> | |
<id>neo4j-release-repository</id> | |
<name>Neo4j Maven 2 release repository</name> | |
<url>http://m2.neo4j.org/releases</url> | |
<releases> | |
<enabled>true</enabled> | |
</releases> | |
<snapshots> | |
<enabled>false</enabled> | |
</snapshots> | |
</repository> | |
</repositories> | |
</project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you want to make Querydsl and Neo4j also work from Eclipse builds you need to follow the tutorial at http://blog.mysema.com/2010/10/using-querydsl-in-eclipse.html but include the
querydsl-apt-X.X.X-general-one-jar.jar
instead of or together with the JPA one.