diff --git a/README.textile b/README.textile index d07bcd239..4bc624957 100644 --- a/README.textile +++ b/README.textile @@ -125,18 +125,26 @@ h2. Spring configuration * Configure Spring Data Neo4j for Neo4j in your application using the provided XML namespace:
-
+
 
+       xmlns:context="http://www.springframework.org/schema/context"
+       xmlns:neo4j="http://www.springframework.org/schema/data/neo4j"
+       xmlns:tx="http://www.springframework.org/schema/tx"
+       xsi:schemaLocation="
+       	http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
+		http://www.springframework.org/schema/data/neo4j http://www.springframework.org/schema/data/neo4j/spring-neo4j.xsd
+		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
+
+	
     
-    
+    
+
+    
+    
+
+    
 
 
@@ -148,10 +156,12 @@ h2. Graph entities @NodeEntity public class World { + // Uses default schema based index @Indexed private String name; - @Indexed( indexName = "moons" ) + // Uses legacy index mechanism + @Indexed(indexType = IndexType.SIMPLE) private int moons; @RelatedTo( type = "REACHABLE_BY_ROCKET", direction = Direction.BOTH, elementClass = World.class ) @@ -179,57 +189,65 @@ public class World { h2. Transactional services -* Create a repository or service to perform typical operations on your entities. The FinderFactory and Finder helper classes make searching easy for common use cases. The complete functionality is covered in the "reference manual":http://static.springsource.org/spring-data/data-neo4j/docs/current/reference/html/#programming-model. +* Create a repository or service to perform typical operations on your entities. The complete functionality is covered in the "reference manual":http://static.springsource.org/spring-data/data-neo4j/docs/current/reference/html/#programming-model.
-public interface WorldRepository extends GraphRepository, NamedIndexRepository {}
+public interface WorldRepository extends GraphRepository {}
 
-@Repository
-public class WorldRepositoryImpl implements WorldRepositoryExtension {
+@Service
+@Transactional
+public class GalaxyService {
 
-    @Autowired
-    private WorldRepository worldRepository;
+	@Autowired
+	private WorldRepository worldRepository;
 
-    @Transactional
-    public Collection makeSomeWorlds()  {
-        World earth = world( "Earth", 1 );
-        World mars = world( "Mars", 2 );
-        mars.addRocketRouteTo( earth );
+	public long getNumberOfWorlds() {
+		return worldRepository.count();
+	}
 
-        return Arrays.asList(
-            world( "Mercury", 0 ), world( "Venus", 0 ), earth, mars,
-            world( "Jupiter", 63 ), world( "Saturn", 62 ),
-            world( "Uranus", 27 ), world( "Neptune", 13 ));
-    }
+	public World createWorld(String name, int moons) {
+		return worldRepository.save(new World(name, moons));
+	}
 
-    private World world(String name, int moons) {
-        return new World(name, moons).persist();
-    }
+	public Iterable getAllWorlds() {
+		return worldRepository.findAll();
+	}
 
-    public World findWorldIdentifiedBy( long id )  {
-        return worldRepository.findById( id );
-    }
+	public World findWorldById(Long id) {
+		return worldRepository.findOne(id);
+	}
 
-    public Iterable findAllWorlds()  {
-        return worldRepository.findAll();
-    }
+    // This is using the schema based index
+	public World findWorldByName(String name) {
+		return worldRepository.findBySchemaPropertyValue("name", name);
+	}
 
-    public long countWorlds()  {
-        return worldRepository.count();
-    }
+    // This is using the legacy index
+	public Iterable findAllByNumberOfMoons(int numberOfMoons) {
+		return worldRepository.findAllByPropertyValue("moons", numberOfMoons);
+	}
 
-    public World findWorldNamed( String name ) {
-        return worldRepository.findByPropertyValue( "name", name );
-    }
+	public Collection makeSomeWorlds() {
+		Collection worlds = new ArrayList();
 
-    public World findWorldWithMoons( long moonCount ) {
-        return worldRepository.findByPropertyValue( "moons", "moons", moonCount );
-    }
+		// Solar worlds
+		worlds.add(createWorld("Mercury", 0));
+		worlds.add(createWorld("Venus", 0));
+
+        World earth = createWorld("Earth", 1);
+        World mars = createWorld("Mars", 2);
+        mars.addRocketRouteTo(earth);
+        worldRepository.save(mars);
+        worlds.add(earth);
+        worlds.add(mars);
+
+        // ... Create more worlds
+
+        return worlds;
+	}
 
-    public Iterable findWorldsWithMoons( int moonCount )  {
-        return worldRepository.findAllByPropertyValue( "moons", "moons", moonCount );
-    }
 }
+
 
diff --git a/spring-data-neo4j-examples/hello-worlds-aspects/src/main/java/org/springframework/data/neo4j/examples/hellograph/GalaxyService.java b/spring-data-neo4j-examples/hello-worlds-aspects/src/main/java/org/springframework/data/neo4j/examples/hellograph/GalaxyService.java index 144230968..de89b427e 100644 --- a/spring-data-neo4j-examples/hello-worlds-aspects/src/main/java/org/springframework/data/neo4j/examples/hellograph/GalaxyService.java +++ b/spring-data-neo4j-examples/hello-worlds-aspects/src/main/java/org/springframework/data/neo4j/examples/hellograph/GalaxyService.java @@ -1,13 +1,17 @@ package org.springframework.data.neo4j.examples.hellograph; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.neo4j.aspects.core.NodeBacked; +import org.springframework.data.neo4j.examples.hellograph.domain.World; +import org.springframework.data.neo4j.examples.hellograph.repositories.WorldRepository; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + import java.util.ArrayList; import java.util.Collection; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.neo4j.aspects.core.NodeBacked; -import org.springframework.stereotype.Service; - @Service +@Transactional public class GalaxyService { @Autowired @@ -18,8 +22,8 @@ public class GalaxyService { } public World createWorld(String name, int moons) { - // The lin below is just as valid within you code (it assumes) - // the aspectj compilcation has occured, however the cast to + // The line below is just as valid within you code (it assumes) + // the aspectj compilation has occurred, however the cast to // the NodeBacked class is being used here as its helpful to // IDE's which struggle with aspectj stuff // @@ -37,7 +41,8 @@ public class GalaxyService { public World findWorldById(Long id) { return worldRepository.findOne(id); } - + + // This is using the schema based index public World findWorldByName(String name) { return worldRepository.findBySchemaPropertyValue("name", name); } diff --git a/spring-data-neo4j-examples/hello-worlds-aspects/src/main/java/org/springframework/data/neo4j/examples/hellograph/WorldRepository.java b/spring-data-neo4j-examples/hello-worlds-aspects/src/main/java/org/springframework/data/neo4j/examples/hellograph/WorldRepository.java deleted file mode 100644 index 350acbf34..000000000 --- a/spring-data-neo4j-examples/hello-worlds-aspects/src/main/java/org/springframework/data/neo4j/examples/hellograph/WorldRepository.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.springframework.data.neo4j.examples.hellograph; - -import org.springframework.data.neo4j.repository.GraphRepository; - -public interface WorldRepository extends GraphRepository {} diff --git a/spring-data-neo4j-examples/hello-worlds-aspects/src/main/java/org/springframework/data/neo4j/examples/hellograph/World.java b/spring-data-neo4j-examples/hello-worlds-aspects/src/main/java/org/springframework/data/neo4j/examples/hellograph/domain/World.java similarity index 80% rename from spring-data-neo4j-examples/hello-worlds-aspects/src/main/java/org/springframework/data/neo4j/examples/hellograph/World.java rename to spring-data-neo4j-examples/hello-worlds-aspects/src/main/java/org/springframework/data/neo4j/examples/hellograph/domain/World.java index a3bd618be..523bbe158 100644 --- a/spring-data-neo4j-examples/hello-worlds-aspects/src/main/java/org/springframework/data/neo4j/examples/hellograph/World.java +++ b/spring-data-neo4j-examples/hello-worlds-aspects/src/main/java/org/springframework/data/neo4j/examples/hellograph/domain/World.java @@ -1,11 +1,7 @@ -package org.springframework.data.neo4j.examples.hellograph; +package org.springframework.data.neo4j.examples.hellograph.domain; import org.neo4j.graphdb.Direction; -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; -import org.springframework.data.neo4j.annotation.RelatedTo; +import org.springframework.data.neo4j.annotation.*; import org.springframework.data.neo4j.support.index.IndexType; import java.util.Set; @@ -16,10 +12,12 @@ public class World { @GraphId private Long id; - + + // Uses default schema based index @Indexed private String name; + // Uses legacy index mechanism @Indexed(indexType = IndexType.SIMPLE) private int moons; diff --git a/spring-data-neo4j-examples/hello-worlds-aspects/src/main/java/org/springframework/data/neo4j/examples/hellograph/repositories/WorldRepository.java b/spring-data-neo4j-examples/hello-worlds-aspects/src/main/java/org/springframework/data/neo4j/examples/hellograph/repositories/WorldRepository.java new file mode 100644 index 000000000..73dfef6c6 --- /dev/null +++ b/spring-data-neo4j-examples/hello-worlds-aspects/src/main/java/org/springframework/data/neo4j/examples/hellograph/repositories/WorldRepository.java @@ -0,0 +1,6 @@ +package org.springframework.data.neo4j.examples.hellograph.repositories; + +import org.springframework.data.neo4j.examples.hellograph.domain.World; +import org.springframework.data.neo4j.repository.GraphRepository; + +public interface WorldRepository extends GraphRepository {} diff --git a/spring-data-neo4j-examples/hello-worlds-aspects/src/main/resources/spring/helloWorldContext.xml b/spring-data-neo4j-examples/hello-worlds-aspects/src/main/resources/spring/helloWorldContext.xml index 57abf0fd3..fb1b1bd37 100644 --- a/spring-data-neo4j-examples/hello-worlds-aspects/src/main/resources/spring/helloWorldContext.xml +++ b/spring-data-neo4j-examples/hello-worlds-aspects/src/main/resources/spring/helloWorldContext.xml @@ -18,8 +18,9 @@ - - + + diff --git a/spring-data-neo4j-examples/hello-worlds-aspects/src/test/java/org/springframework/data/neo4j/examples/hellograph/GalaxyServiceTest.java b/spring-data-neo4j-examples/hello-worlds-aspects/src/test/java/org/springframework/data/neo4j/examples/hellograph/GalaxyServiceTest.java index 8e4ad0cc3..e5a7dba5c 100644 --- a/spring-data-neo4j-examples/hello-worlds-aspects/src/test/java/org/springframework/data/neo4j/examples/hellograph/GalaxyServiceTest.java +++ b/spring-data-neo4j-examples/hello-worlds-aspects/src/test/java/org/springframework/data/neo4j/examples/hellograph/GalaxyServiceTest.java @@ -3,6 +3,7 @@ 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.examples.hellograph.domain.World; import org.springframework.data.neo4j.support.Neo4jTemplate; import org.springframework.data.neo4j.support.node.Neo4jHelper; import org.springframework.test.annotation.Rollback; diff --git a/spring-data-neo4j-examples/hello-worlds/src/main/java/org/springframework/data/neo4j/examples/hellograph/GalaxyService.java b/spring-data-neo4j-examples/hello-worlds/src/main/java/org/springframework/data/neo4j/examples/hellograph/GalaxyService.java index 93188c501..f2ffc743e 100644 --- a/spring-data-neo4j-examples/hello-worlds/src/main/java/org/springframework/data/neo4j/examples/hellograph/GalaxyService.java +++ b/spring-data-neo4j-examples/hello-worlds/src/main/java/org/springframework/data/neo4j/examples/hellograph/GalaxyService.java @@ -1,12 +1,16 @@ package org.springframework.data.neo4j.examples.hellograph; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.neo4j.examples.hellograph.domain.World; +import org.springframework.data.neo4j.examples.hellograph.repositories.WorldRepository; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + import java.util.ArrayList; import java.util.Collection; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - @Service +@Transactional public class GalaxyService { @Autowired @@ -27,7 +31,8 @@ public class GalaxyService { public World findWorldById(Long id) { return worldRepository.findOne(id); } - + + // This is using the schema based index public World findWorldByName(String name) { return worldRepository.findBySchemaPropertyValue("name", name); } diff --git a/spring-data-neo4j-examples/hello-worlds/src/main/java/org/springframework/data/neo4j/examples/hellograph/WorldRepository.java b/spring-data-neo4j-examples/hello-worlds/src/main/java/org/springframework/data/neo4j/examples/hellograph/WorldRepository.java deleted file mode 100644 index 350acbf34..000000000 --- a/spring-data-neo4j-examples/hello-worlds/src/main/java/org/springframework/data/neo4j/examples/hellograph/WorldRepository.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.springframework.data.neo4j.examples.hellograph; - -import org.springframework.data.neo4j.repository.GraphRepository; - -public interface WorldRepository extends GraphRepository {} 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/domain/World.java similarity index 80% rename from spring-data-neo4j-examples/hello-worlds/src/main/java/org/springframework/data/neo4j/examples/hellograph/World.java rename to spring-data-neo4j-examples/hello-worlds/src/main/java/org/springframework/data/neo4j/examples/hellograph/domain/World.java index a3bd618be..523bbe158 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/domain/World.java @@ -1,11 +1,7 @@ -package org.springframework.data.neo4j.examples.hellograph; +package org.springframework.data.neo4j.examples.hellograph.domain; import org.neo4j.graphdb.Direction; -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; -import org.springframework.data.neo4j.annotation.RelatedTo; +import org.springframework.data.neo4j.annotation.*; import org.springframework.data.neo4j.support.index.IndexType; import java.util.Set; @@ -16,10 +12,12 @@ public class World { @GraphId private Long id; - + + // Uses default schema based index @Indexed private String name; + // Uses legacy index mechanism @Indexed(indexType = IndexType.SIMPLE) private int moons; diff --git a/spring-data-neo4j-examples/hello-worlds/src/main/java/org/springframework/data/neo4j/examples/hellograph/repositories/WorldRepository.java b/spring-data-neo4j-examples/hello-worlds/src/main/java/org/springframework/data/neo4j/examples/hellograph/repositories/WorldRepository.java new file mode 100644 index 000000000..73dfef6c6 --- /dev/null +++ b/spring-data-neo4j-examples/hello-worlds/src/main/java/org/springframework/data/neo4j/examples/hellograph/repositories/WorldRepository.java @@ -0,0 +1,6 @@ +package org.springframework.data.neo4j.examples.hellograph.repositories; + +import org.springframework.data.neo4j.examples.hellograph.domain.World; +import org.springframework.data.neo4j.repository.GraphRepository; + +public interface WorldRepository extends GraphRepository {} 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 index 942f585e3..c90285f74 100644 --- 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 @@ -23,8 +23,9 @@ - - + + diff --git a/spring-data-neo4j-examples/hello-worlds/src/main/resources/spring/helloWorldContext.xml b/spring-data-neo4j-examples/hello-worlds/src/main/resources/spring/helloWorldContext.xml index 256f491b7..d6ec72e33 100644 --- a/spring-data-neo4j-examples/hello-worlds/src/main/resources/spring/helloWorldContext.xml +++ b/spring-data-neo4j-examples/hello-worlds/src/main/resources/spring/helloWorldContext.xml @@ -18,8 +18,10 @@ - - + + + 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 e5ccf7e87..56a63d2fc 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 @@ -3,13 +3,13 @@ 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.examples.hellograph.domain.World; 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; @@ -22,9 +22,8 @@ import static org.junit.Assert.*; @ContextConfiguration(locations = "classpath:/spring/helloWorldContext.xml") @RunWith(SpringJUnit4ClassRunner.class) @Transactional -@TransactionConfiguration(defaultRollback = false) public class GalaxyServiceTest { - + @Autowired private GalaxyService galaxyService; @@ -59,7 +58,7 @@ public class GalaxyServiceTest { galaxyService.makeSomeWorlds(); for(World world : galaxyService.getAllWorlds()) { - World foundWorld = galaxyService.findWorldById(world.getId()); + World foundWorld = galaxyService.findWorldById(world.getId()); assertNotNull(foundWorld); } } 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 index 03ef1f269..4263ff70a 100644 --- 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 @@ -3,6 +3,7 @@ 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.examples.hellograph.domain.World; import org.springframework.data.neo4j.support.Neo4jTemplate; import org.springframework.data.neo4j.support.node.Neo4jHelper; import org.springframework.test.annotation.Rollback;