X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=source%2Fmir%2Fentity%2FEntityBrowser.java;h=a320ddee919bd2ac1e267a4b1c4f5ae426aa4fa4;hb=3389d56d4d82089033fd83f9c8758126ffd7da44;hp=5a05e18ecc949ac755d8a4c6d64ee4866ba51b6f;hpb=f9a7655d20e23418320dd552f257893f25268d16;p=mir.git diff --git a/source/mir/entity/EntityBrowser.java b/source/mir/entity/EntityBrowser.java index 5a05e18e..a320ddee 100755 --- a/source/mir/entity/EntityBrowser.java +++ b/source/mir/entity/EntityBrowser.java @@ -11,47 +11,59 @@ public class EntityBrowser implements RewindableIterator { private String whereClause; private String orderByClause; private int batchSize; - private int position=0; - + private int toFetch; private EntityList currentBatch; - public EntityBrowser(StorageObject aStorage, - String aWhereClause, String anOrderByClause, - int aBatchSize) throws StorageObjectException { + private int skip; + private int limit; + + private int batchPosition; + private int positionInBatch; + + public EntityBrowser(StorageObject aStorage, String aWhereClause, String anOrderByClause, + int aBatchSize, int aLimit, int aSkip) throws StorageObjectException { storage=aStorage; whereClause=aWhereClause; orderByClause=anOrderByClause; batchSize=aBatchSize; + skip=aSkip; + limit=aLimit; rewind(); } + public EntityBrowser(StorageObject aStorage, + String aWhereClause, String anOrderByClause, + int aBatchSize) throws StorageObjectException { + this(aStorage, aWhereClause, anOrderByClause, aBatchSize, -1, 0); + } + + public void readCurrentBatch(int aSkip) throws StorageObjectException { + currentBatch = storage.selectByWhereClause(whereClause, orderByClause, aSkip, batchSize); + batchPosition = aSkip; + positionInBatch = 0; + } + public void rewind() { try { - currentBatch = storage.selectByWhereClause(whereClause, orderByClause, 0, batchSize); - position=0; + readCurrentBatch(skip); } catch (Throwable t) { throw new RuntimeException(t.getMessage()); } } - private void readNextBatch() throws StorageObjectException { - if (currentBatch.hasNextBatch()) { - currentBatch = storage.selectByWhereClause(whereClause, orderByClause, - currentBatch.getNextBatch(), batchSize); - position=0; - } - } - public boolean hasNext() { try { - if (position>=currentBatch.size() && currentBatch.hasNextBatch()) { - readNextBatch(); + if (limit>-1 && batchPosition+positionInBatch>=skip+limit) + return false; + + if (positionInBatch>=currentBatch.size() && currentBatch.hasNextBatch()) { + readCurrentBatch(batchPosition+positionInBatch); } - return (position