--- /dev/null
+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
--- /dev/null
+package mir.entity;\r
+\r
+public class QueryBuilder {\r
+\r
+ private String whereClause;\r
+ private String orderByClause;\r
+\r
+ public QueryBuilder(){\r
+ whereClause = new String();\r
+ orderByClause = new String();\r
+ }\r
+\r
+ public void appendDescendingOrder(String anOrder) {\r
+ if (orderByClause.length()==0) {\r
+ orderByClause=anOrder+" desc";\r
+ }\r
+ else {\r
+ orderByClause=orderByClause+","+anOrder+" desc";\r
+ }\r
+ }\r
+\r
+ public void appendAscendingOrder(String anOrder) {\r
+ if (orderByClause.length()==0) {\r
+ orderByClause=anOrder+" asc";\r
+ }\r
+ else {\r
+ orderByClause=orderByClause+","+anOrder+" asc";\r
+ }\r
+ }\r
+\r
+ public void appendAndCondition(String aQualifier) {\r
+ if (whereClause.length()==0) {\r
+ whereClause = aQualifier;\r
+ }\r
+ else {\r
+ whereClause="("+whereClause+") and ("+aQualifier+")";\r
+ }\r
+ }\r
+\r
+ public void appendOrCondition(String aQualifier) {\r
+ if (whereClause.length()==0) {\r
+ whereClause = aQualifier;\r
+ }\r
+ else {\r
+ whereClause="("+whereClause+") or ("+aQualifier+")";\r
+ }\r
+ }\r
+\r
+ public String getWhereClause() {\r
+ return whereClause;\r
+ }\r
+\r
+ public String getOrderByClause() {\r
+ return orderByClause;\r
+ }\r
+}
\ No newline at end of file