Class HibernateCursorItemReader<T>

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

@Deprecated(since="5.0", forRemoval=true) public class HibernateCursorItemReader<T> extends AbstractItemCountingItemStreamItemReader<T> implements org.springframework.beans.factory.InitializingBean
Deprecated, for removal: This API element is subject to removal in a future version.
since 5.0 for removal in 5.2. Use the JpaCursorItemReader instead.
ItemStreamReader for reading database records built on top of Hibernate. It executes the HQL query when initialized iterates over the result set as AbstractItemCountingItemStreamItemReader.read() method is called, returning an object corresponding to current row. The query can be set directly using setQueryString(String), a named query can be used by setQueryName(String), or a query provider strategy can be supplied via setQueryProvider(HibernateQueryProvider).

The reader can be configured to use either StatelessSession sufficient for simple mappings without the need to cascade to associated objects or standard hibernate Session for more advanced mappings or when caching is desired. When stateful session is used it will be cleared in the update(ExecutionContext) method without being flushed (no data modifications are expected).

The implementation is not thread-safe.
Author:
Robert Kasanicky, Dave Syer, Mahmoud Ben Hassine
  • Constructor Summary

    Constructors
    Constructor
    Description
    Deprecated, for removal: This API element is subject to removal in a future version.
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    protected void
    Deprecated, for removal: This API element is subject to removal in a future version.
    Close the cursor and hibernate session.
    protected void
    Deprecated, for removal: This API element is subject to removal in a future version.
    Open hibernate session and create a forward-only cursor for the query.
    protected T
    Deprecated, for removal: This API element is subject to removal in a future version.
    Read next item from input.
    protected void
    jumpToItem(int itemIndex)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Wind forward through the result set to the item requested.
    void
    setFetchSize(int fetchSize)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Fetch size used internally by Hibernate to limit amount of data fetched from database per round trip.
    void
    setParameterValues(Map<String,Object> parameterValues)
    Deprecated, for removal: This API element is subject to removal in a future version.
    The parameter values to apply to a query (map of name:value).
    void
    setQueryName(String queryName)
    Deprecated, for removal: This API element is subject to removal in a future version.
    A query name for an externalized query.
    void
    Deprecated, for removal: This API element is subject to removal in a future version.
    A query provider.
    void
    setQueryString(String queryString)
    Deprecated, for removal: This API element is subject to removal in a future version.
    A query string in HQL.
    void
    setSessionFactory(org.hibernate.SessionFactory sessionFactory)
    Deprecated, for removal: This API element is subject to removal in a future version.
    The Hibernate SessionFactory to use the create a session.
    void
    setUseStatelessSession(boolean useStatelessSession)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Can be set only in uninitialized state.
    void
    update(ExecutionContext executionContext)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Update the context and clear the session if stateful.

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

    getExecutionContextKey, getName, setExecutionContextName, setName

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • HibernateCursorItemReader

      public HibernateCursorItemReader()
      Deprecated, for removal: This API element is subject to removal in a future version.
  • Method Details

    • afterPropertiesSet

      public void afterPropertiesSet() throws Exception
      Deprecated, for removal: This API element is subject to removal in a future version.
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
      Throws:
      Exception
    • setParameterValues

      public void setParameterValues(Map<String,Object> parameterValues)
      Deprecated, for removal: This API element is subject to removal in a future version.
      The parameter values to apply to a query (map of name:value).
      Parameters:
      parameterValues - the parameter values to set
    • setQueryName

      public void setQueryName(String queryName)
      Deprecated, for removal: This API element is subject to removal in a future version.
      A query name for an externalized query. Either this or the { query string or the { query provider should be set.
      Parameters:
      queryName - name of a hibernate named query
    • setFetchSize

      public void setFetchSize(int fetchSize)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Fetch size used internally by Hibernate to limit amount of data fetched from database per round trip.
      Parameters:
      fetchSize - the fetch size to pass down to Hibernate
    • setQueryProvider

      public void setQueryProvider(HibernateQueryProvider<T> queryProvider)
      Deprecated, for removal: This API element is subject to removal in a future version.
      A query provider. Either this or the {query string or the {query name should be set.
      Parameters:
      queryProvider - Hibernate query provider
    • setQueryString

      public void setQueryString(String queryString)
      Deprecated, for removal: This API element is subject to removal in a future version.
      A query string in HQL. Either this or the { query provider or the { query name should be set.
      Parameters:
      queryString - HQL query string
    • setSessionFactory

      public void setSessionFactory(org.hibernate.SessionFactory sessionFactory)
      Deprecated, for removal: This API element is subject to removal in a future version.
      The Hibernate SessionFactory to use the create a session.
      Parameters:
      sessionFactory - the SessionFactory to set
    • setUseStatelessSession

      public void setUseStatelessSession(boolean useStatelessSession)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Can be set only in uninitialized state.
      Parameters:
      useStatelessSession - true to use StatelessSession false to use standard hibernate Session
    • doRead

      @Nullable protected T doRead() throws Exception
      Deprecated, for removal: This API element is subject to removal in a future version.
      Description copied from class: AbstractItemCountingItemStreamItemReader
      Read next item from input.
      Specified by:
      doRead in class AbstractItemCountingItemStreamItemReader<T>
      Returns:
      an item or null if the data source is exhausted
      Throws:
      Exception - Allows subclasses to throw checked exceptions for interpretation by the framework
    • doOpen

      protected void doOpen() throws Exception
      Deprecated, for removal: This API element is subject to removal in a future version.
      Open hibernate session and create a forward-only cursor for the query.
      Specified by:
      doOpen in class AbstractItemCountingItemStreamItemReader<T>
      Throws:
      Exception - Allows subclasses to throw checked exceptions for interpretation by the framework
    • update

      public void update(ExecutionContext executionContext) throws ItemStreamException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Update the context and clear the session if stateful.
      Specified by:
      update in interface ItemStream
      Overrides:
      update in class AbstractItemCountingItemStreamItemReader<T>
      Parameters:
      executionContext - the current ExecutionContext
      Throws:
      ItemStreamException - if there is a problem
      See Also:
    • jumpToItem

      protected void jumpToItem(int itemIndex) throws Exception
      Deprecated, for removal: This API element is subject to removal in a future version.
      Wind forward through the result set to the item requested. Also clears the session every now and then (if stateful) to avoid memory problems. The frequency of session clearing is the larger of the fetch size (if set) and 100.
      Overrides:
      jumpToItem in class AbstractItemCountingItemStreamItemReader<T>
      Parameters:
      itemIndex - the first item to read
      Throws:
      Exception - if there is a problem
      See Also:
    • doClose

      protected void doClose() throws Exception
      Deprecated, for removal: This API element is subject to removal in a future version.
      Close the cursor and hibernate session.
      Specified by:
      doClose in class AbstractItemCountingItemStreamItemReader<T>
      Throws:
      Exception - Allows subclasses to throw checked exceptions for interpretation by the framework