5 import mir.storage.*;
\r
8 public class EntityBrowser implements RewindableIterator {
\r
10 private StorageObject storage;
\r
11 private String whereClause;
\r
12 private String orderByClause;
\r
13 private int batchSize;
\r
14 private int toFetch;
\r
15 private EntityList currentBatch;
\r
20 private int batchPosition;
\r
21 private int positionInBatch;
\r
23 public EntityBrowser(StorageObject aStorage, String aWhereClause, String anOrderByClause,
\r
24 int aBatchSize, int aLimit, int aSkip) throws StorageObjectException {
\r
27 whereClause=aWhereClause;
\r
28 orderByClause=anOrderByClause;
\r
29 batchSize=aBatchSize;
\r
36 public EntityBrowser(StorageObject aStorage,
\r
37 String aWhereClause, String anOrderByClause,
\r
38 int aBatchSize) throws StorageObjectException {
\r
39 this(aStorage, aWhereClause, anOrderByClause, aBatchSize, -1, 0);
\r
42 public void readCurrentBatch(int aSkip) throws StorageObjectException {
\r
43 currentBatch = storage.selectByWhereClause(whereClause, orderByClause, aSkip, batchSize);
\r
44 batchPosition = aSkip;
\r
45 positionInBatch = 0;
\r
48 public void rewind() {
\r
50 readCurrentBatch(skip);
\r
52 catch (Throwable t) {
\r
53 throw new RuntimeException(t.getMessage());
\r
57 public boolean hasNext() {
\r
59 if (limit>-1 && batchPosition+positionInBatch>=skip+limit)
\r
62 if (positionInBatch>=currentBatch.size() && currentBatch.hasNextBatch()) {
\r
63 readCurrentBatch(batchPosition+positionInBatch);
\r
66 return (positionInBatch<currentBatch.size());
\r
68 catch (Throwable t) {
\r
69 throw new RuntimeException(t.getMessage());
\r
73 public Object next() {
\r
76 Entity result = currentBatch.elementAt(positionInBatch);
\r
77 positionInBatch=positionInBatch+1;
\r
85 catch (Throwable t) {
\r
86 throw new RuntimeException(t.getMessage());
\r
90 public void remove() {
\r
91 throw new UnsupportedOperationException();
\r