org.springframework.batch.item.data

## Class Neo4jItemReader<T>

- java.lang.Object
- - org.springframework.batch.item.ItemStreamSupport
  - - org.springframework.batch.item.support.AbstractItemStreamItemReader<T>
    - - org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader<T>
      - - org.springframework.batch.item.data.AbstractPaginatedDataItemReader<T>
        - - org.springframework.batch.item.data.Neo4jItemReader<T>

- All Implemented Interfaces:
    ItemReader<T>, ItemStream, ItemStreamReader<T>, org.springframework.beans.factory.InitializingBean

      public class Neo4jItemReader<T>
      extends AbstractPaginatedDataItemReader<T>
      implements org.springframework.beans.factory.InitializingBean

  Restartable `ItemReader` that reads objects from the graph database Neo4j via a paging technique.

  It executes cypher queries built from the statement fragments provided to retrieve the requested data. The query is executed using paged requests of a size specified in `AbstractPaginatedDataItemReader.setPageSize(int)`. Additional pages are requested as needed when the `AbstractItemCountingItemStreamItemReader.read()` method is called. On restart, the reader will begin again at the same number item it left off at.

  Performance is dependent on your Neo4J configuration (embedded or remote) as well as page size. Setting a fairly large page size and using a commit interval that matches the page size should provide better performance.

  This implementation is thread-safe between calls to `AbstractItemCountingItemStreamItemReader.open(org.springframework.batch.item.ExecutionContext)`, however you should set `saveState=false` if used in a multi-threaded environment (no restart available).

  Author:
    Michael Minella

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected org.apache.commons.logging.Log` | `logger`

    - ### Fields inherited from class org.springframework.batch.item.data.AbstractPaginatedDataItemReader

      `page, pageSize, results`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Neo4jItemReader()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `afterPropertiesSet()` Checks mandatory properties
    `protected java.util.Iterator<T>` | `doPageRead()` Method this `ItemStreamReader` delegates to for the actual work of reading a page.
    `void` | `setMatchStatement(java.lang.String matchStatement)` An optional match fragment of the cypher query.
    `void` | `setOrderByStatement(java.lang.String orderByStatement)` A list of properties to order the results by.
    `void` | `setResultConverter(org.springframework.data.neo4j.conversion.ResultConverter<java.util.Map<java.lang.String,java.lang.Object>,T> resultConverter)` Set the converter used to convert node to the targetType.
    `void` | `setReturnStatement(java.lang.String returnStatement)` The return statement of the cypher query.
    `void` | `setStartStatement(java.lang.String startStatement)` The start segment of the cypher query.
    `void` | `setTargetType(java.lang.Class<T> targetType)` The object type to be returned from each call to `AbstractItemCountingItemStreamItemReader.read()`
    `void` | `setTemplate(org.springframework.data.neo4j.template.Neo4jOperations template)` Used to perform operations against the Neo4J database.
    `void` | `setWhereStatement(java.lang.String whereStatement)` An optional where fragment of the cypher query.

    - ### Methods inherited from class org.springframework.batch.item.data.AbstractPaginatedDataItemReader

      `doClose, doOpen, doRead, jumpToItem, setPageSize`

    - ### Methods inherited from class org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader

      `close, getCurrentItemCount, isSaveState, open, read, setCurrentItemCount, setMaxItemCount, setSaveState, update`

    - ### Methods inherited from class org.springframework.batch.item.ItemStreamSupport

      `getExecutionContextKey, setExecutionContextName, setName`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### logger

          protected org.apache.commons.logging.Log logger

  - ### Constructor Detail

    - #### Neo4jItemReader

          public Neo4jItemReader()

  - ### Method Detail

    - #### setStartStatement

          public void setStartStatement(java.lang.String startStatement)

      The start segment of the cypher query. START is prepended to the statement provided and should not be included.
      Parameters:
        `startStatement` - the start fragment of the cypher query.

    - #### setReturnStatement

          public void setReturnStatement(java.lang.String returnStatement)

      The return statement of the cypher query. RETURN is prepended to the statement provided and should not be included
      Parameters:
        `returnStatement` - the return fragment of the cypher query.

    - #### setMatchStatement

          public void setMatchStatement(java.lang.String matchStatement)

      An optional match fragment of the cypher query. MATCH is prepended to the statement provided and should not be included.
      Parameters:
        `matchStatement` - the match fragment of the cypher query

    - #### setWhereStatement

          public void setWhereStatement(java.lang.String whereStatement)

      An optional where fragment of the cypher query. WHERE is prepended to the statement provided and should not be included.
      Parameters:
        `whereStatement` - where fragment of the cypher query

    - #### setOrderByStatement

          public void setOrderByStatement(java.lang.String orderByStatement)

      A list of properties to order the results by. This is required so that subsequent page requests pull back the segment of results correctly. ORDER BY is prepended to the statement provided and should not be included.
      Parameters:
        `orderByStatement` - order by fragment of the cypher query.

    - #### setTemplate

          public void setTemplate(org.springframework.data.neo4j.template.Neo4jOperations template)

      Used to perform operations against the Neo4J database.
      Parameters:
        `template` - the Neo4jOperations instance to use
      See Also:
        `Neo4jOperations`

    - #### setTargetType

          public void setTargetType(java.lang.Class<T> targetType)

      The object type to be returned from each call to `AbstractItemCountingItemStreamItemReader.read()`
      Parameters:
        `targetType` - the type of object to return.

    - #### setResultConverter

          public void setResultConverter(org.springframework.data.neo4j.conversion.ResultConverter<java.util.Map<java.lang.String,java.lang.Object>,T> resultConverter)

      Set the converter used to convert node to the targetType. By default, `DefaultConverter` is used.
      Parameters:
        `resultConverter` - the converter to use.

    - #### doPageRead

          protected java.util.Iterator<T> doPageRead()

      Description copied from class: `AbstractPaginatedDataItemReader`
      Method this `ItemStreamReader` delegates to for the actual work of reading a page. Each time this method is called, the resulting `Iterator` should contain the items read within the next page.
      If the `Iterator` is empty or null when it is returned, this `ItemReader` will assume that the input has been exhausted.
      Specified by:
        `doPageRead` in class `AbstractPaginatedDataItemReader<T>`
      Returns:
        an `Iterator` containing the items within a page.

    - #### afterPropertiesSet

          public void afterPropertiesSet()
                                  throws java.lang.Exception

      Checks mandatory properties
      Specified by:
        `afterPropertiesSet` in interface `org.springframework.beans.factory.InitializingBean`
      Throws:
        `java.lang.Exception`
      See Also:
        `InitializingBean.afterPropertiesSet()`