1 package jimm.datavision.test.mock.source; 2 import jimm.datavision.Selectable; 3 import jimm.datavision.source.DataCursor; 4 import jimm.datavision.source.Query; 5 import java.util.List ; 6 import java.util.ArrayList ; 7 8 public class MockDataCursor extends DataCursor { 9 10 protected static final String [] CITIES = { 11 "Chicago", "New Jersey", "New York" 12 }; 13 protected static final String [] SHORT_NAMES = { "CH", "NJ", "NY" }; 14 protected static final String [] SELECTABLES = { 15 "office.name", "2", "jobs.post_date", "jobs.ID", 16 "jobs.title", "jobs.hourly rate" 17 }; 18 19 protected int cityIndex; 20 protected int jobIndex; 21 protected Query query; 22 23 static int indexOfSelectable(Selectable sel) { 24 String selId = sel.getId().toString(); 25 for (int i = 0; i < SELECTABLES.length; ++i) 26 if (selId.equals(SELECTABLES[i])) 27 return i; 28 29 throw new RuntimeException ("can't find selectable \"" + 30 sel.getDisplayName() + "\" with id " + selId); 31 } 32 33 public MockDataCursor(Query q) { 34 jobIndex = cityIndex = -1; 35 query = q; 36 } 37 38 protected List readRowData() { 39 ++jobIndex; 40 if ((jobIndex % 100) == 0) ++cityIndex; 42 if (cityIndex >= CITIES.length) return null; 44 if (query.getEditableWhereClause().startsWith("office.name = ") && 46 cityIndex > 0) 47 return null; 48 49 List row = new ArrayList (); 50 row.add(CITIES[cityIndex]); row.add(SHORT_NAMES[cityIndex]); row.add(new java.util.Date ()); row.add(new Integer (jobIndex)); row.add("This is the short description of job " + jobIndex); row.add(jobIndex == 0 ? null : new Integer (jobIndex * 100)); 57 58 return row; 59 } 60 61 } 62 | Popular Tags |