|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.springframework.batch.item.database.DrivingQueryItemReader
public class DrivingQueryItemReader
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.
| Constructor Summary | |
|---|---|
DrivingQueryItemReader()
|
|
DrivingQueryItemReader(List keys)
Initialize the input source with the provided keys list. |
|
| Method Summary | |
|---|---|
void |
afterPropertiesSet()
|
void |
close(ExecutionContext executionContext)
Close the resource by setting the list of keys to null, allowing them to be garbage collected. |
protected Object |
getCurrentKey()
Get the current key. |
void |
mark()
Mark is supported as long as this ItemStream is used in a
single-threaded environment. |
void |
open(ExecutionContext executionContext)
Initialize the item reader by delegating to the subclass in order to retrieve the keys. |
Object |
read()
Return the next key in the List. |
void |
reset()
Reset the stream to the last mark. |
void |
setKeyCollector(KeyCollector keyGenerator)
Set the key generation strategy to use for this input source. |
void |
setSaveState(boolean saveState)
|
void |
update(ExecutionContext executionContext)
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 keys)
keys - | Method Detail |
|---|
public Object read()
read in interface ItemReaderprotected Object getCurrentKey()
public void close(ExecutionContext executionContext)
close in interface ItemStreamexecutionContext - TODOpublic 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 keyGenerator)
keyGenerator - public void mark()
ItemStream is used in a
single-threaded environment. The state backing the mark is a single
counter, keeping track of the current position, so multiple threads
cannot be accommodated.
mark in interface ItemReaderItemReader.mark()public void reset()
ItemReader
reset in interface ItemReaderpublic void setSaveState(boolean saveState)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||