DATAGRAPH-175 Improve Hello-Worlds example

This commit is contained in:
Michael Hunger
2012-02-07 13:32:44 +01:00
parent 7189742e2a
commit ee4bafa550
5 changed files with 20 additions and 75 deletions

View File

@@ -118,50 +118,6 @@
</configuration>
</plugin>
<!--
<plugin>
< ! - - required to resolve aspectj-enhanced class features - - >
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.2</version>
<configuration>
<outxml>true</outxml>
<aspectLibraries>
<aspectLibrary>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</aspectLibrary>
<aspectLibrary>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j-aspects</artifactId>
</aspectLibrary>
</aspectLibraries>
<source>1.6</source>
<target>1.6</target>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${aspectj.version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
</plugin>
-->
<plugin>
<!-- IntelliJ Idea Support -->
<groupId>org.apache.maven.plugins</groupId>

View File

@@ -19,13 +19,10 @@ public class App
WorldRepositoryImpl galaxy = applicationContext.getBean(WorldRepositoryImpl.class);
Iterable<World> 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<World> worldsBeyond = galaxy.exploreWorldsBeyond( homeWorld );
for (World world : worldsBeyond) {

View File

@@ -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<World> reachableByRocket = new HashSet<World>();
@Fetch
@RelatedTo(type = "REACHABLE_BY_ROCKET", direction = Direction.BOTH)
Set<World> reachableByRocket = new HashSet<World>();
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);
}
}

View File

@@ -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;
}

View File

@@ -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 ) );
}
}