- made a producer for startpages per topic
[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   public boolean hasNext() throws StorageObjectException {\r
44     if (position>=currentBatch.size() && currentBatch.hasNextBatch()) {\r
45       readNextBatch();\r
46     }\r
47 \r
48     return (position<currentBatch.size());\r
49   }\r
50 \r
51   public Entity next() throws StorageObjectException {\r
52     if (hasNext()) {\r
53       Entity result = currentBatch.elementAt(position);\r
54       position=position+1;\r
55 \r
56       return result;\r
57     }\r
58     else {\r
59       return null;\r
60     }\r
61   }\r
62 }