some new files for the localization factory / producer rewrite
authorzapata <zapata>
Mon, 22 Apr 2002 18:16:29 +0000 (18:16 +0000)
committerzapata <zapata>
Mon, 22 Apr 2002 18:16:29 +0000 (18:16 +0000)
source/mir/entity/EntityBrowser.java [new file with mode: 0755]
source/mir/entity/QueryBuilder.java [new file with mode: 0755]

diff --git a/source/mir/entity/EntityBrowser.java b/source/mir/entity/EntityBrowser.java
new file mode 100755 (executable)
index 0000000..192ee14
--- /dev/null
@@ -0,0 +1,63 @@
+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
diff --git a/source/mir/entity/QueryBuilder.java b/source/mir/entity/QueryBuilder.java
new file mode 100755 (executable)
index 0000000..2e18511
--- /dev/null
@@ -0,0 +1,56 @@
+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