diff --git a/spring-data-neo4j-examples/hello-worlds/src/main/resources/spring/helloWorldContext-subRef-TRS.xml b/spring-data-neo4j-examples/hello-worlds/src/main/resources/spring/helloWorldContext-subRef-TRS.xml
new file mode 100644
index 000000000..942f585e3
--- /dev/null
+++ b/spring-data-neo4j-examples/hello-worlds/src/main/resources/spring/helloWorldContext-subRef-TRS.xml
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/spring-data-neo4j-examples/hello-worlds/src/test/java/org/springframework/data/neo4j/examples/hellograph/GalaxyServiceTest.java b/spring-data-neo4j-examples/hello-worlds/src/test/java/org/springframework/data/neo4j/examples/hellograph/GalaxyServiceTest.java
index 8e4ad0cc3..e5ccf7e87 100644
--- a/spring-data-neo4j-examples/hello-worlds/src/test/java/org/springframework/data/neo4j/examples/hellograph/GalaxyServiceTest.java
+++ b/spring-data-neo4j-examples/hello-worlds/src/test/java/org/springframework/data/neo4j/examples/hellograph/GalaxyServiceTest.java
@@ -9,6 +9,7 @@ import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.BeforeTransaction;
+import org.springframework.test.context.transaction.TransactionConfiguration;
import org.springframework.transaction.annotation.Transactional;
import java.util.Collection;
@@ -21,6 +22,7 @@ import static org.junit.Assert.*;
@ContextConfiguration(locations = "classpath:/spring/helloWorldContext.xml")
@RunWith(SpringJUnit4ClassRunner.class)
@Transactional
+@TransactionConfiguration(defaultRollback = false)
public class GalaxyServiceTest {
@Autowired
diff --git a/spring-data-neo4j-examples/hello-worlds/src/test/java/org/springframework/data/neo4j/examples/hellograph/SubRefBasedTRSGalaxyServiceTest.java b/spring-data-neo4j-examples/hello-worlds/src/test/java/org/springframework/data/neo4j/examples/hellograph/SubRefBasedTRSGalaxyServiceTest.java
new file mode 100644
index 000000000..03ef1f269
--- /dev/null
+++ b/spring-data-neo4j-examples/hello-worlds/src/test/java/org/springframework/data/neo4j/examples/hellograph/SubRefBasedTRSGalaxyServiceTest.java
@@ -0,0 +1,121 @@
+package org.springframework.data.neo4j.examples.hellograph;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.neo4j.support.Neo4jTemplate;
+import org.springframework.data.neo4j.support.node.Neo4jHelper;
+import org.springframework.test.annotation.Rollback;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.transaction.BeforeTransaction;
+import org.springframework.test.context.transaction.TransactionConfiguration;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.Collection;
+
+import static org.hamcrest.CoreMatchers.anyOf;
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.*;
+
+@ContextConfiguration(locations = "classpath:/spring/helloWorldContext-subRef-TRS.xml")
+@RunWith(SpringJUnit4ClassRunner.class)
+@Transactional
+@TransactionConfiguration(defaultRollback = false)
+public class SubRefBasedTRSGalaxyServiceTest {
+
+ @Autowired
+ private GalaxyService galaxyService;
+
+ @Autowired
+ private Neo4jTemplate template;
+
+ @Rollback(false)
+ @BeforeTransaction
+ public void cleanUpGraph() {
+ Neo4jHelper.cleanDb(template);
+ }
+
+ @Test
+ public void shouldAllowDirectWorldCreation() {
+ assertEquals(0, galaxyService.getNumberOfWorlds());
+ World myWorld = galaxyService.createWorld("mine", 0);
+ assertEquals(1, galaxyService.getNumberOfWorlds());
+
+ Iterable foundWorlds = galaxyService.getAllWorlds();
+ World mine = foundWorlds.iterator().next();
+ assertEquals(myWorld.getName(), mine.getName());
+ }
+
+ @Test
+ public void shouldHaveCorrectNumberOfWorlds() {
+ galaxyService.makeSomeWorlds();
+ assertEquals(13, galaxyService.getNumberOfWorlds());
+ }
+
+ @Test
+ public void shouldFindWorldsById() {
+ galaxyService.makeSomeWorlds();
+
+ for(World world : galaxyService.getAllWorlds()) {
+ World foundWorld = galaxyService.findWorldById(world.getId());
+ assertNotNull(foundWorld);
+ }
+ }
+
+ @Test
+ public void shouldFindWorldsByName() {
+ galaxyService.makeSomeWorlds();
+
+ for(World world : galaxyService.getAllWorlds()) {
+ World foundWorld = galaxyService.findWorldByName(world.getName());
+ assertNotNull(foundWorld);
+ }
+ }
+
+ @Test
+ public void shouldReachMarsFromEarth() {
+ galaxyService.makeSomeWorlds();
+
+ World earth = galaxyService.findWorldByName("Earth");
+ World mars = galaxyService.findWorldByName("Mars");
+
+ assertTrue(mars.canBeReachedFrom(earth));
+ assertTrue(earth.canBeReachedFrom(mars));
+ }
+
+ @Test
+ public void shouldFindAllWorlds() {
+ Collection madeWorlds = galaxyService.makeSomeWorlds();
+ Iterable foundWorlds = galaxyService.getAllWorlds();
+
+ int countOfFoundWorlds = 0;
+ for(World foundWorld : foundWorlds) {
+ assertTrue(madeWorlds.contains(foundWorld));
+ countOfFoundWorlds++;
+ }
+
+ assertEquals(madeWorlds.size(), countOfFoundWorlds);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void shouldFindWorldsWith1Moon() {
+ galaxyService.makeSomeWorlds();
+
+ for(World worldWithOneMoon : galaxyService.findAllByNumberOfMoons(1)) {
+ assertThat(
+ worldWithOneMoon.getName(),
+ is(anyOf(containsString("Earth"), containsString("Midgard"))));
+ }
+ }
+
+ @Test
+ public void shouldNotFindKrypton() {
+ galaxyService.makeSomeWorlds();
+ World krypton = galaxyService.findWorldByName("Krypton");
+ assertNull(krypton);
+ }
+
+}
diff --git a/src/docbkx/reference/helloworlds-labeltrs.png b/src/docbkx/reference/helloworlds-labeltrs.png
new file mode 100644
index 000000000..0240bd536
Binary files /dev/null and b/src/docbkx/reference/helloworlds-labeltrs.png differ
diff --git a/src/docbkx/reference/helloworlds.png b/src/docbkx/reference/helloworlds-old.png
similarity index 100%
rename from src/docbkx/reference/helloworlds.png
rename to src/docbkx/reference/helloworlds-old.png
diff --git a/src/docbkx/reference/helloworlds-subreftrs.png b/src/docbkx/reference/helloworlds-subreftrs.png
new file mode 100644
index 000000000..acd2c32fa
Binary files /dev/null and b/src/docbkx/reference/helloworlds-subreftrs.png differ
diff --git a/src/docbkx/reference/samples.xml b/src/docbkx/reference/samples.xml
index c5622a65a..be008fac9 100644
--- a/src/docbkx/reference/samples.xml
+++ b/src/docbkx/reference/samples.xml
@@ -16,12 +16,14 @@
Hello Worlds sample application
- The Hello Worlds sample application is a simple console application. It creates some worlds
- (node entities) and rocket routes (relationships) between worlds, all in a galaxy (the graph),
- and then prints them.
+ The Hello Worlds sample application exists merely to provide a client with a way of creating some "worlds"
+ (node entities) and "rocket routes" (relationships) between worlds, all in a galaxy (the graph).
+ There is currently no GUI for this application, rather you can have a look at the associated
+ unit tests for some examples of how to interact with this domain via a dedicated GalaxyService
+ class.
- The unit tests demonstrate some other features of Spring Data Neo4j as well. The sample comes
+ The unit tests additionally demonstrate some other features of Spring Data Neo4j as well. The sample comes
with a minimal configuration for Maven and Spring to get up and running quickly.
@@ -29,18 +31,34 @@
and for the advanced mapping (hello-world-aspects).
- Executing the application creates the following graph in the graph database:
+ Running the unit tests create two versions of the world, one based on the default Label based Type
+ Representation Strategy, and another (for comparison purposes) based on the Sub Reference type
+ representation strategy. From the GalaxyService clients perspective, there is no difference,
+ however how the data physically stored in the graph, does differ, and we take this opportunity to show
+ you how using two different type representation strategies can impact how your data is modelled in the
+ graph itself.
+ Hello World Galaxy - Using default "Label" Type Representation Strategy
-
+
+
+ Hello World Galaxy - Using "Sub Reference" Type Representation Strategy
+
+
+
+
+
+
IMDB sample application
+
+ This sample application still needs to be upgraded to SDN 3.0.X
The IMDB sample is a web application that imports datasets from the Internet Movie Database (IMDB)
into the graph database. It allows the listing of movies with their actors, and of actors and their
roles in different movies. It also uses graph traversal operations to calculate the
@@ -68,6 +86,7 @@
MyRestaurants sample application
+ This sample application still needs to be upgraded to SDN 3.0.X
Simple, JPA-based web application for managing users and restaurants, with the ability to add
restaurants as favorites to a user. It is basically the foundation for the MyRestaurants-Social
application (see), and does therefore not use
@@ -83,6 +102,7 @@
MyRestaurant-Social sample application
+ This sample application still needs to be upgraded to SDN 3.0.X
This application extends the MyRestaurants sample application, adding social networking
functionality to it with cross-store persistence. The web application allows for users to add
friends and rate restaurants. A graph traversal provides recommendations based on your friends'
@@ -104,6 +124,7 @@
Cineasts social movie database
+ This sample application still needs to be upgraded to SDN 3.0.X
The cineasts.net application was introduced extensively in the first part of this guide, the
tutorial. The tutorial covers the development of the simple mapping version of cineasts.