diff --git a/src/docbkx/reference/programming-model/repositories.xml b/src/docbkx/reference/programming-model/repositories.xml index 7f173bef8..3fbec2230 100644 --- a/src/docbkx/reference/programming-model/repositories.xml +++ b/src/docbkx/reference/programming-model/repositories.xml @@ -1,142 +1,154 @@
- GraphRepositories for basic CRUD and find-operations + CRUD with repositories - The repositories provided by Spring Data Graph build on the composable repository infrastructure contained + The repositories provided by Spring Data Graph build on the composable repository infrastructure in Spring Data Commons. - Those repositories allow the interface based composition of the final repository consisting of provided default + They allow for interface based composition of repositories consisting of provided default implementations for certain interfaces and additional custom implementations for other methods. - Spring Data Graph provides only the infrastructure and some default repository implementations so far. In future - releases support for finders derived from method names, named queries and annotated query methods will be added. + Spring Data Graph provides only the infrastructure and some default repository implementations + so far. Future releases will support finders derived from method names, named queries, and + annotated query methods. (e.g. - findByName(name), - @Query(name = "find-by-name-query") findByName(name), - @Query(query = "{name:%s}") findByName(name)) + findByName(name), + @Query(name="find-by-name-query") findByName(name), and + @Query(query="{name:%s}") findByName(name)) - Spring Data Graph comes with typed repository implementations that provide methods for - locating node and relationship entities. There are 3 types of basic repository interfaces and implementations. - One CRUD-Repository (CRUDGraphRepository<T>) that provides basic operations, a IndexQueryExecutor - that delegates to Neo4j's internal indexing subsystem for executing queries. And last but not least - a TraversalQueryExecutor that handles Neo4J Traversals. + + Spring Data Graph comes with typed repository implementations that provide methods for + locating node and relationship entities. There are 3 types of basic repository interfaces + and implementations. CRUDRepository provides basic operations, + IndexRepository and NamedIndexRepository delegate to Neo4j's internal + indexing subsystem for queries, and TraversalRepository handles Neo4j traversals. - CRUDGraphRepository delegates to the configured TypeRepresentationStrategy - () + CRUDRepository delegates to the configured TypeRepresentationStrategy + (see ) for type based queries. - loading an instance via the Neo4j node id - T findOne(id) + Load an instance via a Neo4j node id + T findOne(id) - checks for existence via the Neo4j node id - boolean exists(id) + Check for existence of a Neo4j node id + boolean exists(id) - iterating over all nodes of a node entity type - Iterable<T> findAll() (supported in future versions: Iterable<T> findAll(Sort) and Page<T> findAll(Pageable)) + Iterate over all nodes of a node entity type + Iterable<T> findAll() + (supported in future versions: + Iterable<T> findAll(Sort) and + Page<T> findAll(Pageable)) - counting the instances of a node entity type - Long count() + Count the instances of a node entity type + Long count() - saves the graph entities - T save(T) and Iterable<T> save(Iterable<T>) + Save a graph entity + T save(T) and Iterable<T> save(Iterable<T>) - deletes the graph entities - void delete(T), void; delete(Iterable<T>) and deleteAll() + Delete a graph entity + void delete(T), void; delete(Iterable<T>), + and deleteAll() - - - IndexQueryExecutor works with the indexing subsystem and provides methods to find entities by indexed properties, ranged queries of combination thereof. + + + IndexRepository works with the indexing subsystem and provides methods to find + entities by indexed properties, ranged queries, and combinations thereof. The index key is + the name of the indexed entity field, unless overridden in the @Indexed annotation. - iterating over all indexed instances with a certain property value - Iterable<T> findAllByPropertyValue(indexName, keyName, value) + Iterate over all indexed entity instances with a certain field value + Iterable<T> findAllByPropertyValue(key, value) - getting a single instance with a certain property value - T findByPropertyValue(indexName, keyName, value) + Get a single entity instance with a certain field value + T findByPropertyValue(key, value) - iterating over all indexed instances within a certain numerical range (inclusive) - Iterable<T> findAllByRange(indexName, keyName, from, to) + Iterate over all indexed entity instances with field values in a certain numerical range (inclusive) + Iterable<T> findAllByRange(key, from, to) - iterating over all indexed instances matching the given fulltext (or QueryContext query) - Iterable<T> findAllByQuery(indexName, keyName, queryOrQueryContext) + Iterate over all indexed entity instances with field values matching the given fulltext string or QueryContext query + Iterable<T> findAllByQuery(key, queryOrQueryContext) - - + + There is also a NamedIndexRepository with the same methods, but with an additional index + name parameter, making it possible to query any index. + - TraversalQueryExecutor works with the traversal framework. + TraversalRepository delegates to the Neo4j traversal framework. - iterating over a traversal result - Iterable<T> findAllByTraversal(startNode, traversalDescription) + Iterate over a traversal result + Iterable<T> findAllByTraversal(startEntity, traversalDescription) - The Repository instances are either created manually via a DirectGraphRepositoryFactory to be bound - o a concrete node or relationship entity class. + The Repository instances are either created manually via a + DirectGraphRepositoryFactory, bound to a concrete node or relationship entity class. The DirectGraphRepositoryFactory is configured in the Spring context and can be injected. - - Using GraphRepositories + + + Using GraphRepositories graphRepository = graphRepositoryFactory.createGraphRepository(Person.class); -Person michael = graphRepository.save(new Person("Michael",36)); +Person michael = graphRepository.save(new Person("Michael", 36)); -Person dave=graphRepository.findOne(123); +Person dave = graphRepository.findOne(123); Long numberOfPeople = graphRepository.count(); Person mark = graphRepository.findByPropertyValue("name", "mark"); -Iterable devs = graphRepository.findAllByProperyValue("occupation","developer"); +Iterable devs = graphRepository.findAllByProperyValue("occupation", "developer"); -Iterable middleAgedPeople = graphRepository.findAllByRange("age",20,40); +Iterable middleAgedPeople = graphRepository.findAllByRange("age", 20, 40); -Iterable aTeam = graphRepository.findAllByQuery("name","A*"); +Iterable aTeam = graphRepository.findAllByQuery("name", "A*"); Iterable davesFriends = graphRepository.findAllByTraversal(dave, Traversal.description().pruneAfterDepth(1) .relationships(KNOWS).filter(returnAllButStartNode())); ]]> - - +
- Composing Repositories - - The recommended way of providing repositories is to define a repository-interface per domain class and have the - mechanisms provided by the repository infrastructure automatically detect them and additional implementation - classes and create an injectable repository implementation to be used in services or other spring beans. + Composing repositories + + The recommended way of providing repositories is to define a repository interface per domain + class. The mechanisms provided by the repository infrastructure will automatically detect + them, along with additional implementation classes, and create an injectable repository + implementation to be used in services or other spring beans. + - Composing Repositories + Composing repositories , PersonRepositoryExtension { -} +public interface PersonRepository extends GraphRepository, PersonRepositoryExtension {} + // alternatively select some of the required repositories individually public interface PersonRepository extends CRUDGraphRepository, IndexQueryExecutor, - TraversalQueryExecutor, PersonRepositoryExtension { -} + TraversalQueryExecutor, PersonRepositoryExtension {} + // provide a custom extension if needed public interface PersonRepositoryExtension { Iterable findFriends(Person person); } -public class PersonRepositoryImpl implements PersonRepositoryExtension { +public class PersonRepositoryImpl implements PersonRepositoryExtension { // optionally inject default repository, or use DirectGraphRepositoryFactory @Autowired PersonRepository baseRepository; public Iterable findFriends(Person person) { @@ -151,18 +163,17 @@ public class PersonRepositoryImpl implements PersonRepositoryExtension { @Autowired PersonRepository personRepository; - Person michael = personRepository.save(new Person("Michael",36)); +Person michael = personRepository.save(new Person("Michael",36)); - Person dave=personRepository.findOne(123); +Person dave=personRepository.findOne(123); - Iterable devs = personRepository.findAllByProperyValue("occupation","developer"); +Iterable devs = personRepository.findAllByProperyValue("occupation","developer"); - Iterable aTeam = graphRepository.findAllByQuery( "name","A*"); +Iterable aTeam = graphRepository.findAllByQuery( "name","A*"); - Iterable friends = personRepository.findFriends(dave); - ]]> +Iterable friends = personRepository.findFriends(dave); +]]> -
\ No newline at end of file