+package mir.entity;\r
+\r
+import mir.storage.*;\r
+import mir.entity.*;\r
+\r
+public class EntityBrowser {\r
+\r
+ private StorageObject storage;\r
+ private String whereClause;\r
+ private String orderByClause;\r
+ private int batchSize;\r
+ private int position=0;\r
+\r
+ private EntityList currentBatch;\r
+\r
+ public EntityBrowser(StorageObject aStorage,\r
+ String aWhereClause, String anOrderByClause,\r
+ int aBatchSize) throws StorageObjectException {\r
+\r
+ storage=aStorage;\r
+ whereClause=aWhereClause;\r
+ orderByClause=anOrderByClause;\r
+ batchSize=aBatchSize;\r
+\r
+ rewind();\r
+ }\r
+\r
+ private void rewind() throws StorageObjectException {\r
+ currentBatch = storage.selectByWhereClause(whereClause, orderByClause,\r
+ 0, batchSize);\r
+\r
+ position=0;\r
+ }\r
+\r
+ private void readNextBatch() throws StorageObjectException {\r
+ if (currentBatch.hasNextBatch()) {\r
+ currentBatch = storage.selectByWhereClause(whereClause, orderByClause,\r
+ currentBatch.getNextBatch(), batchSize);\r
+ position=0;\r
+ }\r
+ }\r
+\r
+\r
+ public boolean hasNext() throws StorageObjectException {\r
+ if (position>=currentBatch.size() && currentBatch.hasNextBatch()) {\r
+ readNextBatch();\r
+ }\r
+\r
+ return (position<currentBatch.size());\r
+ }\r
+\r
+ public Entity next() throws StorageObjectException {\r
+ if (hasNext()) {\r
+ Entity result = currentBatch.elementAt(position);\r
+ position=position+1;\r
+\r
+ return result;\r
+ }\r
+ else {\r
+ return null;\r
+ }\r
+ }\r
+}
\ No newline at end of file