Last active
December 16, 2015 22:30
-
-
Save TimmyStorms/5507893 to your computer and use it in GitHub Desktop.
Java example for Neo4j labels and indexing, see http://www.terminalstate.net/2013/05/labels-and-schema-indexes-in-neo4j.html.
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
public final class Neo2Label { | |
public static void main(final String[] args) { | |
final GraphDatabaseService db = new TestGraphDatabaseFactory().newImpermanentDatabase(); | |
ExecutionEngine engine = new ExecutionEngine(db); | |
System.out.println(engine.execute("create (n:Person {first_name : \"Peppa\", last_name : \"Pig\"})").dumpToString()); | |
System.out.println(engine.execute("create (n:Person {first_name : \"George\", last_name : \"Pig\"})").dumpToString()); | |
System.out.println(engine.execute("create (n:Person {first_name : \"Mummy\", last_name : \"Pig\"})").dumpToString()); | |
System.out.println(engine.execute("create (n:Person {first_name : \"Daddy\", last_name : \"Pig\"})").dumpToString()); | |
System.out.println(engine.execute("create (n:Location {location : \"The Pigs house\"})").dumpToString()); | |
System.out.println(engine.execute("create (n:Person {name : \"Bob the bat\"})").dumpToString()); | |
ExecutionResult result = engine.profile("match n:Person where n.first_name! =\"George\" return n"); | |
Iterator<Map<String,Object>> it = result.iterator(); | |
while (it.hasNext()) { | |
it.next(); | |
} | |
System.out.println(result.executionPlanDescription()); | |
System.out.println(engine.execute("create index on :Person(first_name)").executionPlanDescription()); | |
result = engine.profile("match p:Person where p.first_name! = \"George\" return p"); | |
it = result.iterator(); | |
while (it.hasNext()) { | |
it.next(); | |
} | |
System.out.println(result.executionPlanDescription()); | |
db.shutdown(); | |
} | |
} |
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-2</artifactId> | |
<version>0.0.1-SNAPSHOT</version> | |
<dependencies> | |
<dependency> | |
<groupId>org.neo4j</groupId> | |
<artifactId>neo4j</artifactId> | |
<version>2.0.0-M02</version> | |
<exclusions> | |
<exclusion> | |
<groupId>org.neo4j</groupId> | |
<artifactId>neo4j-udc</artifactId> | |
</exclusion> | |
</exclusions> | |
</dependency> | |
<dependency> | |
<groupId>org.neo4j</groupId> | |
<artifactId>neo4j-kernel</artifactId> | |
<version>2.0.0-M02</version> | |
<classifier>tests</classifier> | |
</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>true</enabled> | |
</snapshots> | |
</repository> | |
</repositories> | |
</project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment