01: package jimm.datavision.test.mock.source;
02:
03: import jimm.datavision.Selectable;
04: import jimm.datavision.source.DataCursor;
05: import jimm.datavision.source.Query;
06: import java.util.List;
07: import java.util.ArrayList;
08:
09: public class MockDataCursor extends DataCursor {
10:
11: protected static final String[] CITIES = { "Chicago", "New Jersey",
12: "New York" };
13: protected static final String[] SHORT_NAMES = { "CH", "NJ", "NY" };
14: protected static final String[] SELECTABLES = { "office.name", "2",
15: "jobs.post_date", "jobs.ID", "jobs.title",
16: "jobs.hourly rate" };
17:
18: protected int cityIndex;
19: protected int jobIndex;
20: protected Query query;
21:
22: static int indexOfSelectable(Selectable sel) {
23: String selId = sel.getId().toString();
24: for (int i = 0; i < SELECTABLES.length; ++i)
25: if (selId.equals(SELECTABLES[i]))
26: return i;
27:
28: throw new RuntimeException("can't find selectable \""
29: + sel.getDisplayName() + "\" with id " + selId);
30: }
31:
32: public MockDataCursor(Query q) {
33: jobIndex = cityIndex = -1;
34: query = q;
35: }
36:
37: protected List readRowData() {
38: ++jobIndex;
39: if ((jobIndex % 100) == 0) // 100 jobs per city
40: ++cityIndex;
41: if (cityIndex >= CITIES.length) // no more cities; report is done
42: return null;
43: // When using parameter, stop after Chicago
44: if (query.getEditableWhereClause().startsWith("office.name = ")
45: && cityIndex > 0)
46: return null;
47:
48: List row = new ArrayList();
49: row.add(CITIES[cityIndex]); // office.name
50: row.add(SHORT_NAMES[cityIndex]); // Short Office Name (id "2")
51: row.add(new java.util.Date()); // jobs.post_date
52: row.add(new Integer(jobIndex)); // jobs.ID
53: row.add("This is the short description of job " + jobIndex); // jobs.title
54: row.add(jobIndex == 0 ? null // jobs."hourly rate"
55: : new Integer(jobIndex * 100));
56:
57: return row;
58: }
59:
60: }
|