|
Came to the realization that I could just re-use the rows() method on the SQL class and just pass in a SQL
string. D**mba@@ to go and cut-and paste code. I uploaded the revised dataset class. The changes still work and the unit tests pass. I think John Carnell's query is an important one here:
"... However, what happens if the user is trying to filter based on a where. Shouldn't the call really return all of the rows for the DataSet." I think the answer to this is yes. Here is some code: def athletes = [
[firstname: 'Paul', lastname:'Tergat', dateOfBirth:'1969-06-17'],
[firstname: 'Khalid', lastname:'Khannouchi', dateOfBirth:'1971-12-22'],
[firstname: 'Ronaldo', lastname:'da Costa', dateOfBirth:'1970-06-07'],
[firstname: 'Paula', lastname:'Radcliffe', dateOfBirth:'1973-12-17']
]
athleteSet = db.dataSet('Athlete')
athletes.each { a -> athleteSet.add(a) }
youngsters = athleteSet.findAll{ it.dateOfBirth > '1970-1-1'}
def rows = []
youngsters.each { rows += it.lastname }
println rows.join(', ') // => Khannouchi, da Costa, Radcliffe
println youngsters.rows().size() // => 4
I would expect rows() for youngsters to return the three youngster rows not the entire original table (4 rows here). do I see it right, that we just need to replace
public List rows() throws SQLException { String sql = "SELECT * FROM " + table; return rows(sql); } with public List rows() throws SQLException { String sql = getSql(); return rows(sql); } in DataSet? |
|||||||||||||||||||||||||||||||||||||||||||||||
and the firstRow() method. I have also updated the SqlCompleteTest class to test these two methods.
However, I do have a question on this open improvement. The way I read the "improvement" is that the rows() method
will return all of the rows on the underlying tableset. To implement this I simply did a SELECT * FROM the table to
build the data. However, what happens if the user is trying to filter based on a where. Shouldn't the call really return all of the rows for the DataSet.
Please let me know how exactly this code should work. I can change the code to behave whatever way needed.