|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object
|
+--xxl.relational.AbstractResultSet
|
+--xxl.relational.BufferedResultSet
This class decorates a ResultSet by buffering selected tuples with a bag.
One can use a BufferedResultSet as a normal ResultSet.
At first, every requested tuple will directly be retrieved from the underlying ResultSet.
While handling the actual tuple one can call the store() method to store
this tuple in the
bag. For each tuple only the first call of store() has an effect, all further
calls are ignored.
use-case:
After some tuples of the underlying ResultSet have been read, one can call the
reset() method and then all
bufferd tuples
can be reread from the BufferedResultSet. They appear in the same order
as bag.cursor returns them. reset() can be called repeatedly.
Example (1a):
ResultSet r = new BufferedResultSet(resultSet);
while (r.next()) {
"handle the actual tuple" // it is read from the underlying ResultSet
if (willBeNeededAgain(tuple))
r.store(); // stores this tuple in the bag for future use
}
while (!finished) { // handling all stored tuples many times
r.reset();
while (r.next())
"handle stored tuple" // it is read from the bag
}
The store() method is ignored while reading tuples from the bag,
i.e. a tuple is iserted into the Bag at most once.
Example (1b):
ResultSet r = new BufferedResultSet(resultSet);
while (!finished) { // handling many times
while (r.next()) {
"handle tuple" // it is read from whatever
if (willBeNeededAgain(tuple))
r.store(); // stores the tupel (if not already stored)
}
r.reset();
}
While reading tuples from the Bag one can remove these tuples by calling the
remove()
method (if the bag.cursor supports remove()). For each tuple only the first
call of remove() has an effect.
Tuples can not be removed from the underlying ResultSet. If the actual tuple has been read
from the underlying ResultSet (and not from the bag), the call of remove() will be ignored.
Example (2):
ResultSet r = new BufferedResultSet(resultSet);
while (!finished) { // handling many times
while (r.next()) {
"handle tuple" // it is read from whatever
if (willBeNeededAgain(tuple))
r.store(); // stores the tupel (if not already stored)
else
r.remove(); // removes the tupel from the bag (if stored)
}
r.reset();
}
Now in each loop tuples that are not needed anymore can be removed from the bag, i.e. the bag can shrink in each loop.
One can also call the reset() method if next() returned
false.
In this case, the actual tuple is deprecated and a new bag.cursor is generated
from which the next requested tuple is taken.
After the bag cursor is empty, this class proceeds with reading the underlying
ResultSet.
The easiest constructor creates a BufferedResultSet with a main memory Bag and all tuples
are stored as ArrayTuples.
More advanced constructors allow to pass a Bag for storing Tuples and a Tuple factory-method to create new Tuples.
Example (3):
new BufferedResultSet((Bag)Bag.FACTORY_METHOD.invoke(), ListTuple.FACTORY_METHOD, resultSet);
This creates a BufferedResultSet that stores the tuples from resultSet as
ListTuples in the default Bag implementation.
| Field Summary | |
protected boolean |
alreadyRemoved
|
protected boolean |
alreadyStored
|
protected Bag |
bag
|
protected Cursor |
bagCursor
|
protected Function |
createTuple
|
protected boolean |
onBag
|
protected java.sql.ResultSet |
resultSet
|
protected Tuple |
tuple
|
protected boolean |
wasNull
|
| Constructor Summary | |
BufferedResultSet(Bag bag,
Function createTuple,
java.sql.ResultSet resultSet)
|
|
BufferedResultSet(Bag bag,
java.sql.ResultSet resultSet)
|
|
BufferedResultSet(java.sql.ResultSet resultSet)
|
|
| Method Summary | |
void |
close()
|
int |
findColumn(java.lang.String columnName)
|
byte[] |
getBytes(int columnIndex)
|
java.sql.ResultSetMetaData |
getMetaData()
|
java.lang.Object |
getObject(int columnIndex)
|
Tuple |
getTuple()
|
boolean |
next()
|
void |
remove()
|
void |
reset()
|
void |
store()
|
boolean |
wasNull()
|
| Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
| Field Detail |
protected java.sql.ResultSet resultSet
protected Function createTuple
protected Bag bag
protected Cursor bagCursor
protected Tuple tuple
protected boolean onBag
protected boolean wasNull
protected boolean alreadyStored
protected boolean alreadyRemoved
| Constructor Detail |
public BufferedResultSet(Bag bag,
Function createTuple,
java.sql.ResultSet resultSet)
public BufferedResultSet(Bag bag,
java.sql.ResultSet resultSet)
public BufferedResultSet(java.sql.ResultSet resultSet)
| Method Detail |
public void store()
throws java.sql.SQLException
public void reset()
public void remove()
public Tuple getTuple()
throws java.sql.SQLException
public boolean next()
throws java.sql.SQLException
public java.lang.Object getObject(int columnIndex)
throws java.sql.SQLException
public byte[] getBytes(int columnIndex)
throws java.sql.SQLException
public boolean wasNull()
throws java.sql.SQLException
public int findColumn(java.lang.String columnName)
throws java.sql.SQLException
public java.sql.ResultSetMetaData getMetaData()
throws java.sql.SQLException
public void close()
throws java.sql.SQLException
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||