|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.springframework.batch.item.database.DrivingQueryItemReader<T>
AbstractPagingItemReader
public class DrivingQueryItemReader<T>
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.
| 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 |
|---|
public DrivingQueryItemReader()
public DrivingQueryItemReader(List<T> keys)
keys - | Method Detail |
|---|
public T read()
read in interface ItemReader<T>protected T getCurrentKey()
public void close(ExecutionContext executionContext)
close in interface ItemStreamexecutionContext - the current execution context in case it is neededpublic void open(ExecutionContext executionContext)
open in interface ItemStreamIllegalStateException - if the keys list is null or initialized is
true.public void update(ExecutionContext executionContext)
ItemStream
update in interface ItemStreamexecutionContext - to be updated
public void afterPropertiesSet()
throws Exception
afterPropertiesSet in interface InitializingBeanExceptionpublic void setKeyCollector(KeyCollector<T> keyCollector)
keyCollector - public void setSaveState(boolean saveState)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||