some new files for the localization factory / producer rewrite
[mir.git] / source / mir / entity / EntityBrowser.java
1 package mir.entity;\r
2 \r
3 import mir.storage.*;\r
4 import mir.entity.*;\r
5 \r
6 public class EntityBrowser {\r
7 \r
8   private StorageObject storage;\r
9   private String whereClause;\r
10   private String orderByClause;\r
11   private int batchSize;\r
12   private int position=0;\r
13 \r
14   private EntityList currentBatch;\r
15 \r
16   public EntityBrowser(StorageObject aStorage,\r
17           String aWhereClause, String anOrderByClause,\r
18           int aBatchSize) throws StorageObjectException {\r
19 \r
20     storage=aStorage;\r
21     whereClause=aWhereClause;\r
22     orderByClause=anOrderByClause;\r
23     batchSize=aBatchSize;\r
24 \r
25     rewind();\r
26   }\r
27 \r
28   private void rewind() throws StorageObjectException {\r
29     currentBatch = storage.selectByWhereClause(whereClause, orderByClause,\r
30             0, batchSize);\r
31 \r
32     position=0;\r
33   }\r
34 \r
35   private void readNextBatch() throws StorageObjectException  {\r
36     if (currentBatch.hasNextBatch()) {\r
37       currentBatch = storage.selectByWhereClause(whereClause, orderByClause,\r
38             currentBatch.getNextBatch(), batchSize);\r
39       position=0;\r
40     }\r
41   }\r
42 \r
43 \r
44   public boolean hasNext() throws StorageObjectException {\r
45     if (position>=currentBatch.size() && currentBatch.hasNextBatch()) {\r
46       readNextBatch();\r
47     }\r
48 \r
49     return (position<currentBatch.size());\r
50   }\r
51 \r
52   public Entity next() throws StorageObjectException {\r
53     if (hasNext()) {\r
54       Entity result = currentBatch.elementAt(position);\r
55       position=position+1;\r
56 \r
57       return result;\r
58     }\r
59     else {\r
60       return null;\r
61     }\r
62   }\r
63 }