Clarified repositories in reference.
This commit is contained in:
@@ -8,17 +8,17 @@
|
||||
They allow for interface based composition of repositories consisting of provided default
|
||||
implementations for certain interfaces and additional custom implementations for other methods.
|
||||
</para>
|
||||
<note>
|
||||
<para>
|
||||
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.
|
||||
<code>findByName(name)</code>,
|
||||
<code>@Query(name="find-by-name-query") findByName(name)</code>, and
|
||||
<code>@Query(query="{name:%s}") findByName(name)</code>)
|
||||
</para>
|
||||
</note>
|
||||
<!--<note>-->
|
||||
<!--<para>-->
|
||||
<!--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.-->
|
||||
<!--<code>findByName(name)</code>,-->
|
||||
<!--<code>@Query(name="find-by-name-query") findByName(name)</code>, and-->
|
||||
<!--<code>@Query(query="{name:%s}") findByName(name)</code>)-->
|
||||
<!--</para>-->
|
||||
<!--</note>-->
|
||||
<para>
|
||||
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
|
||||
@@ -27,106 +27,136 @@
|
||||
indexing subsystem for queries, and <code>TraversalRepository</code> handles Neo4j traversals.
|
||||
</para>
|
||||
<para>
|
||||
<code>CRUDRepository</code> delegates to the configured <code>TypeRepresentationStrategy</code>
|
||||
(see <xref linkend="reference:programming-model:typerepresentationstrategy"/>)
|
||||
for type based queries.
|
||||
<variablelist>
|
||||
<varlistentry>
|
||||
<term>Load an instance via a Neo4j node id</term>
|
||||
<listitem><para><code>T findOne(id)</code></para></listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term>Check for existence of a Neo4j node id</term>
|
||||
<listitem><para><code>boolean exists(id)</code></para></listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term>Iterate over all nodes of a node entity type</term>
|
||||
<listitem><para><code>Iterable<T> findAll()</code>
|
||||
(supported in future versions:
|
||||
<code>Iterable<T> findAll(Sort)</code> and
|
||||
<code>Page<T> findAll(Pageable)</code>)</para></listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term>Count the instances of a node entity type</term>
|
||||
<listitem><para><code>Long count()</code></para></listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term>Save a graph entity</term>
|
||||
<listitem><para><code>T save(T)</code> and <code>Iterable<T> save(Iterable<T>)</code></para></listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term>Delete a graph entity</term>
|
||||
<listitem><para><code>void delete(T)</code>, <code>void; delete(Iterable<T>)</code>,
|
||||
and <code>deleteAll()</code></para></listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
|
||||
</para>
|
||||
<para>
|
||||
<code>IndexRepository</code> 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 <code>@Indexed</code> annotation.
|
||||
<variablelist>
|
||||
<varlistentry>
|
||||
<term>Iterate over all indexed entity instances with a certain field value</term>
|
||||
<listitem><para><code>Iterable<T> findAllByPropertyValue(key, value)</code></para></listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term>Get a single entity instance with a certain field value</term>
|
||||
<listitem><para><code>T findByPropertyValue(key, value)</code></para></listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term>Iterate over all indexed entity instances with field values in a certain numerical range (inclusive)</term>
|
||||
<listitem><para><code>Iterable<T> findAllByRange(key, from, to)</code></para></listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term>Iterate over all indexed entity instances with field values matching the given fulltext string or QueryContext query</term>
|
||||
<listitem><para><code>Iterable<T> findAllByQuery(key, queryOrQueryContext)</code></para></listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
There is also a <code>NamedIndexRepository</code> with the same methods, but with an additional index
|
||||
name parameter, making it possible to query any index.
|
||||
<code>GraphRepository</code> is a convenience repository interface, extending <code>CRUDRepository</code>,
|
||||
<code>IndexRepository</code>, and <code>TraversalRepository</code>. Generally, it has all the
|
||||
desired repository methods. If named index operations are required, then <code>NamedIndexRepository</code>
|
||||
may also be included.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
<code>TraversalRepository</code> delegates to the Neo4j traversal framework.
|
||||
<variablelist>
|
||||
<varlistentry>
|
||||
<term>Iterate over a traversal result</term>
|
||||
<listitem><para><code>Iterable<T> findAllByTraversal(startEntity, traversalDescription)</code></para></listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
</para>
|
||||
<para>
|
||||
The <code>Repository</code> instances are either created manually via a
|
||||
<code>DirectGraphRepositoryFactory</code>, bound to a concrete node or relationship entity class.
|
||||
The <code>DirectGraphRepositoryFactory</code> is configured in the Spring context and can be injected.
|
||||
</para>
|
||||
<example>
|
||||
<title>Using GraphRepositories</title>
|
||||
<programlisting language="java"><![CDATA[
|
||||
GraphRepository<Person> graphRepository = graphRepositoryFactory
|
||||
.createGraphRepository(Person.class);
|
||||
<section>
|
||||
<title>CRUDRepository</title>
|
||||
<para>
|
||||
<code>CRUDRepository</code> delegates to the configured <code>TypeRepresentationStrategy</code>
|
||||
(see <xref linkend="reference:programming-model:typerepresentationstrategy"/>)
|
||||
for type based queries.
|
||||
<variablelist>
|
||||
<varlistentry>
|
||||
<term>Load an instance via a Neo4j node id</term>
|
||||
<listitem><para><code>T findOne(id)</code></para></listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term>Check for existence of a Neo4j node id</term>
|
||||
<listitem><para><code>boolean exists(id)</code></para></listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term>Iterate over all nodes of a node entity type</term>
|
||||
<listitem><para><code>Iterable<T> findAll()</code>
|
||||
(supported in future versions:
|
||||
<code>Iterable<T> findAll(Sort)</code> and
|
||||
<code>Page<T> findAll(Pageable)</code>)</para></listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term>Count the instances of a node entity type</term>
|
||||
<listitem><para><code>Long count()</code></para></listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term>Save a graph entity</term>
|
||||
<listitem><para><code>T save(T)</code> and <code>Iterable<T> save(Iterable<T>)</code></para></listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term>Delete a graph entity</term>
|
||||
<listitem><para><code>void delete(T)</code>, <code>void; delete(Iterable<T>)</code>,
|
||||
and <code>deleteAll()</code></para></listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
</para>
|
||||
<para>
|
||||
Important to note here is that the <code>save</code>, <code>delete</code>, and <code>deleteAll</code>
|
||||
methods are only there to conform to the <code>org.springframework.data.repository.Repository</code>
|
||||
interface. The recommended way of saving and deleting entities is by using <code>entity.persist()</code>
|
||||
and <code>entity.remove()</code>.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
Person michael = graphRepository.save(new Person("Michael", 36));
|
||||
<section>
|
||||
<title>IndexRepository and NamedIndexRepository</title>
|
||||
<para>
|
||||
<code>IndexRepository</code> 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 <code>@Indexed</code> annotation.
|
||||
<variablelist>
|
||||
<varlistentry>
|
||||
<term>Iterate over all indexed entity instances with a certain field value</term>
|
||||
<listitem><para><code>Iterable<T> findAllByPropertyValue(key, value)</code></para></listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term>Get a single entity instance with a certain field value</term>
|
||||
<listitem><para><code>T findByPropertyValue(key, value)</code></para></listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term>Iterate over all indexed entity instances with field values in a certain numerical range (inclusive)</term>
|
||||
<listitem><para><code>Iterable<T> findAllByRange(key, from, to)</code></para></listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term>Iterate over all indexed entity instances with field values matching the given fulltext string or QueryContext query</term>
|
||||
<listitem><para><code>Iterable<T> findAllByQuery(key, queryOrQueryContext)</code></para></listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
</para>
|
||||
<para>
|
||||
There is also a <code>NamedIndexRepository</code> with the same methods, but with an additional index
|
||||
name parameter, making it possible to query any index.
|
||||
</para>
|
||||
|
||||
Person dave = graphRepository.findOne(123);
|
||||
</section>
|
||||
|
||||
Long numberOfPeople = graphRepository.count();
|
||||
<section>
|
||||
<title>TraversalRepository</title>
|
||||
<para>
|
||||
<code>TraversalRepository</code> delegates to the Neo4j traversal framework.
|
||||
<variablelist>
|
||||
<varlistentry>
|
||||
<term>Iterate over a traversal result</term>
|
||||
<listitem><para><code>Iterable<T> findAllByTraversal(startEntity, traversalDescription)</code></para></listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
</para>
|
||||
</section>
|
||||
|
||||
Person mark = graphRepository.findByPropertyValue("name", "mark");
|
||||
<section>
|
||||
<title>Creating repositories</title>
|
||||
<para>
|
||||
The <code>Repository</code> instances are either created manually via a
|
||||
<code>DirectGraphRepositoryFactory</code>, bound to a concrete node or relationship entity class.
|
||||
The <code>DirectGraphRepositoryFactory</code> is configured in the Spring context and can be injected.
|
||||
</para>
|
||||
<example>
|
||||
<title>Using GraphRepositories</title>
|
||||
<programlisting language="java"><![CDATA[
|
||||
GraphRepository<Person> graphRepository = graphRepositoryFactory
|
||||
.createGraphRepository(Person.class);
|
||||
|
||||
Iterable<Person> devs = graphRepository.findAllByProperyValue("occupation", "developer");
|
||||
Person michael = graphRepository.save(new Person("Michael", 36));
|
||||
|
||||
Iterable<Person> middleAgedPeople = graphRepository.findAllByRange("age", 20, 40);
|
||||
Person dave = graphRepository.findOne(123);
|
||||
|
||||
Iterable<Person> aTeam = graphRepository.findAllByQuery("name", "A*");
|
||||
Long numberOfPeople = graphRepository.count();
|
||||
|
||||
Person mark = graphRepository.findByPropertyValue("name", "mark");
|
||||
|
||||
Iterable<Person> devs = graphRepository.findAllByProperyValue("occupation", "developer");
|
||||
|
||||
Iterable<Person> middleAgedPeople = graphRepository.findAllByRange("age", 20, 40);
|
||||
|
||||
Iterable<Person> aTeam = graphRepository.findAllByQuery("name", "A*");
|
||||
|
||||
Iterable<Person> davesFriends = graphRepository.findAllByTraversal(dave,
|
||||
Traversal.description().pruneAfterDepth(1)
|
||||
.relationships(KNOWS).filter(returnAllButStartNode()));
|
||||
]]></programlisting>
|
||||
</example>
|
||||
</section>
|
||||
|
||||
Iterable<Person> davesFriends = graphRepository.findAllByTraversal(dave,
|
||||
Traversal.description().pruneAfterDepth(1)
|
||||
.relationships(KNOWS).filter(returnAllButStartNode()));
|
||||
]]></programlisting>
|
||||
</example>
|
||||
<section>
|
||||
<title>Composing repositories</title>
|
||||
<para>
|
||||
|
||||
Reference in New Issue
Block a user