org.springframework.batch.item.database
Class DrivingQueryItemReader<T>

java.lang.Object
  extended by org.springframework.batch.item.database.DrivingQueryItemReader<T>
All Implemented Interfaces:
ItemReader<T>, ItemStream, InitializingBean
Direct Known Subclasses:
IbatisDrivingQueryItemReader

Deprecated. The DrivingQueryItemReader approach is not supported going forward, use a PagingItemReader implementation instead. See AbstractPagingItemReader

public class DrivingQueryItemReader<T>
extends Object
implements ItemReader<T>, InitializingBean, ItemStream

Convenience class for driving query item readers. Item readers of this type use a 'driving query' to return back a list of keys. A key can be defined as anything that can uniquely identify a record so that a more detailed record can be retrieved for each object. This allows a much smaller footprint to be stored in memory for processing. The following 'Customer' example table will help illustrate this:

 CREATE TABLE CUSTOMER (
   ID BIGINT IDENTITY PRIMARY KEY,  
   NAME VARCHAR(45),
   CREDIT FLOAT
 );
 

A cursor based solution would simply open up a cursor over ID, NAME, and CREDIT, and move it from one to the next. This can cause issues on databases with pessimistic locking strategies. A 'driving query' approach would be to return only the ID of the customer, then use a separate DAO to retrieve the name and credit for each ID. This means that there will be a call to a separate DAO for each call to ItemReader.read().

Mutability: Because this base class cannot guarantee that the keys returned by subclasses are immutable, care should be taken to not modify a key value. Doing so would cause issues if a rollback occurs. For example, if a call to read() is made, and the returned key is modified, a rollback will cause the next call to read() to return the same object that was originally returned, since there is no way to create a defensive copy, and re-querying the database for all the keys would be too resource intensive.

The implementation is *not* thread-safe.

Author:
Lucas Ward

Constructor Summary
DrivingQueryItemReader()
          Deprecated.  
DrivingQueryItemReader(List<T> keys)
          Deprecated. Initialize the input source with the provided keys list.
 
Method Summary
 void afterPropertiesSet()
          Deprecated.  
 void close(ExecutionContext executionContext)
          Deprecated. Close the resource by setting the list of keys to null, allowing them to be garbage collected.
protected  T getCurrentKey()
          Deprecated. Get the current key.
 void open(ExecutionContext executionContext)
          Deprecated. Initialize the item reader by delegating to the subclass in order to retrieve the keys.
 T read()
          Deprecated. Return the next key in the List.
 void setKeyCollector(KeyCollector<T> keyCollector)
          Deprecated. Set the key generation strategy to use for this input source.
 void setSaveState(boolean saveState)
          Deprecated.  
 void update(ExecutionContext executionContext)
          Deprecated. Indicates that the execution context provided during open is about to be saved.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DrivingQueryItemReader

public DrivingQueryItemReader()
Deprecated. 

DrivingQueryItemReader

public DrivingQueryItemReader(List<T> keys)
Deprecated. 
Initialize the input source with the provided keys list.

Parameters:
keys -
Method Detail

read

public T read()
Deprecated. 
Return the next key in the List.

Specified by:
read in interface ItemReader<T>
Returns:
next key in the list if not index is not at the last element, null otherwise.

getCurrentKey

protected T getCurrentKey()
Deprecated. 
Get the current key. This method will return the same object returned by the last read() method. If no items have been read yet the ItemReader yet, then null will be returned.

Returns:
the current key.

close

public void close(ExecutionContext executionContext)
Deprecated. 
Close the resource by setting the list of keys to null, allowing them to be garbage collected.

Specified by:
close in interface ItemStream
Parameters:
executionContext - the current execution context in case it is needed

open

public void open(ExecutionContext executionContext)
Deprecated. 
Initialize the item reader by delegating to the subclass in order to retrieve the keys.

Specified by:
open in interface ItemStream
Throws:
IllegalStateException - if the keys list is null or initialized is true.

update

public void update(ExecutionContext executionContext)
Deprecated. 
Description copied from interface: ItemStream
Indicates that the execution context provided during open is about to be saved. If any state is remaining, but has not been put in the context, it should be added here.

Specified by:
update in interface ItemStream
Parameters:
executionContext - to be updated

afterPropertiesSet

public void afterPropertiesSet()
                        throws Exception
Deprecated. 
Specified by:
afterPropertiesSet in interface InitializingBean
Throws:
Exception

setKeyCollector

public void setKeyCollector(KeyCollector<T> keyCollector)
Deprecated. 
Set the key generation strategy to use for this input source.

Parameters:
keyCollector -

setSaveState

public void setSaveState(boolean saveState)
Deprecated. 


Copyright © 2008 SpringSource. All Rights Reserved.