diff --git a/spring-data-neo4j-examples/hello-worlds/pom.xml b/spring-data-neo4j-examples/hello-worlds/pom.xml index c1aa647e7..a7b33ba40 100644 --- a/spring-data-neo4j-examples/hello-worlds/pom.xml +++ b/spring-data-neo4j-examples/hello-worlds/pom.xml @@ -118,50 +118,6 @@ - - org.apache.maven.plugins diff --git a/spring-data-neo4j-examples/hello-worlds/src/main/java/org/springframework/data/neo4j/examples/hellograph/App.java b/spring-data-neo4j-examples/hello-worlds/src/main/java/org/springframework/data/neo4j/examples/hellograph/App.java index 16f3f3449..064d864bd 100644 --- a/spring-data-neo4j-examples/hello-worlds/src/main/java/org/springframework/data/neo4j/examples/hellograph/App.java +++ b/spring-data-neo4j-examples/hello-worlds/src/main/java/org/springframework/data/neo4j/examples/hellograph/App.java @@ -19,13 +19,10 @@ public class App WorldRepositoryImpl galaxy = applicationContext.getBean(WorldRepositoryImpl.class); - Iterable worlds = galaxy.makeSomeWorlds(); + galaxy.makeSomeWorlds(); - World homeWorld = worlds.iterator().next(); - System.out.println("At home on: " + homeWorld); - - World foundHomeWorld = galaxy.findWorldNamed( homeWorld.getName() ); - System.out.println( "found home world: " + foundHomeWorld ); + World homeWorld = galaxy.findWorldNamed( "Earth" ); + System.out.println( "At home on: " + homeWorld ); Iterable worldsBeyond = galaxy.exploreWorldsBeyond( homeWorld ); for (World world : worldsBeyond) { diff --git a/spring-data-neo4j-examples/hello-worlds/src/main/java/org/springframework/data/neo4j/examples/hellograph/World.java b/spring-data-neo4j-examples/hello-worlds/src/main/java/org/springframework/data/neo4j/examples/hellograph/World.java index b80c0c8ad..6e02e1b00 100644 --- a/spring-data-neo4j-examples/hello-worlds/src/main/java/org/springframework/data/neo4j/examples/hellograph/World.java +++ b/spring-data-neo4j-examples/hello-worlds/src/main/java/org/springframework/data/neo4j/examples/hellograph/World.java @@ -3,6 +3,7 @@ package org.springframework.data.neo4j.examples.hellograph; import org.neo4j.graphdb.Direction; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.neo4j.annotation.Fetch; import org.springframework.data.neo4j.annotation.GraphId; import org.springframework.data.neo4j.annotation.Indexed; import org.springframework.data.neo4j.annotation.NodeEntity; @@ -28,8 +29,9 @@ public class World @Indexed(indexName = "moon-index") private int moons; - @RelatedTo(type = "REACHABLE_BY_ROCKET", elementClass = World.class, direction = Direction.BOTH) - private Set reachableByRocket = new HashSet(); + @Fetch + @RelatedTo(type = "REACHABLE_BY_ROCKET", direction = Direction.BOTH) + Set reachableByRocket = new HashSet(); public World( String name, int moons ) { @@ -69,26 +71,16 @@ public class World @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((id == null) ? 0 : id.hashCode()); - return result; + return (id == null) ? 0 : id.hashCode(); } @Override public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; + if (this == obj) return true; + if (obj == null) return false; + if (getClass() != obj.getClass()) return false; World other = (World) obj; - if (id == null) { - if (other.id != null) - return false; - } else if (!id.equals(other.id)) - return false; - return true; - } + if (id == null) return other.id == null; + return id.equals(other.id); + } } diff --git a/spring-data-neo4j-examples/hello-worlds/src/main/java/org/springframework/data/neo4j/examples/hellograph/WorldRepositoryImpl.java b/spring-data-neo4j-examples/hello-worlds/src/main/java/org/springframework/data/neo4j/examples/hellograph/WorldRepositoryImpl.java index f01173b86..1abe82a03 100644 --- a/spring-data-neo4j-examples/hello-worlds/src/main/java/org/springframework/data/neo4j/examples/hellograph/WorldRepositoryImpl.java +++ b/spring-data-neo4j-examples/hello-worlds/src/main/java/org/springframework/data/neo4j/examples/hellograph/WorldRepositoryImpl.java @@ -31,8 +31,8 @@ public class WorldRepositoryImpl implements MyWorldRepository { newWorlds.add(earth); World mars = world("Mars", 2); - mars.addRocketRouteTo(earth); - worldRepository.save(mars); + earth.addRocketRouteTo(mars); + worldRepository.save(earth); newWorlds.add(mars); newWorlds.add(world("Jupiter", 63)); @@ -47,8 +47,6 @@ public class WorldRepositoryImpl implements MyWorldRepository { newWorlds.add(world("Asgard", 63)); newWorlds.add(world("Hel", 62)); - worldRepository.save(newWorlds); - return newWorlds; } diff --git a/spring-data-neo4j-examples/hello-worlds/src/test/java/org/springframework/data/neo4j/examples/hellograph/WorldRepositoryTest.java b/spring-data-neo4j-examples/hello-worlds/src/test/java/org/springframework/data/neo4j/examples/hellograph/WorldRepositoryTest.java index b28d1432b..e9d0c8883 100644 --- a/spring-data-neo4j-examples/hello-worlds/src/test/java/org/springframework/data/neo4j/examples/hellograph/WorldRepositoryTest.java +++ b/spring-data-neo4j-examples/hello-worlds/src/test/java/org/springframework/data/neo4j/examples/hellograph/WorldRepositoryTest.java @@ -111,9 +111,11 @@ public class WorldRepositoryTest World earth = galaxy.findWorldNamed( "Earth" ); World mars = galaxy.findWorldNamed( "Mars" ); + System.err.println(earth.reachableByRocket); + System.err.println(mars.reachableByRocket); - assertTrue( mars.canBeReachedFrom( earth ) ); - assertTrue( earth.canBeReachedFrom( mars ) ); + assertTrue("mars can be reached from earth", mars.canBeReachedFrom( earth ) ); + assertTrue("earth can be reached from mars", earth.canBeReachedFrom( mars ) ); } }