jastrachan | 25 Mar 09:58 2004

Re: GroovyResultSet modifications

Just reposting as my yahoo account seems to take 24 hours to actually 
send mail these days... :)

On 25 Mar 2004, at 07:16, James Strachan wrote:
> On 24 Mar 2004, at 20:12, Ivan Z. Ganza wrote:
>> Greetings,
>> Been playing around with groovy and so far I'm loving it.  I've run
>> into something I belive may need to be addressed.
>> For example I have a class Foo which has a method
>> 	build(java.sql.ResultSet)
>> I would expect the following code to work:
>> 	sql.eachRow("SELECT * FROM foo_list"){ result |
>> 		foo = Foo.build(result)
>> 	}
>> This won't work however since GroovyResultSet it not actually an
>> instance of java.sql.ResultSet -- also the ResultSet inside is
>> private.
>> I have a host of objects which work the same way via a
>> build(java.sql.ResultSet) method.
>> This could be solved in a number of ways, however, in the ideal case I
>> should not have to modify any of my source files to give them special
>> knowledge of groovy in order for this to work.  By adding a
>> build(groovy.sql.GroovyResultSet) this could be made to work but I do
>> not belive that is a good way to fix it.
>> The ideal case would seem to be having GroovyResultSet extend
>> java.sql.ResultSet therefore implementing the interface.  This would
>> be most elegant as you could provide a GroovyResultSet wherever a
>> java.sql.ResultSet was used previously.  I'm strongly having the sense
>> this would be the correct thing to do.
>> Internally it could delegate the method calls to the actual ResultSet
>> instance.  previous() and next() currently in that class may be a
>> problem though...for backwards compatibility.
>> Another much simpler solution would be to provide a getResultSet()
>> method so one could get their hands on the underlying ResultSet (this
>> should probably be added anyway in the interm so we could access that
>> )
>> I'm willing to help and could make the changes to GroovyResultSet, 
>> let me know.
> Good point. How about we implement the ResultSet interface and 
> delegate all methods to the private instance? Then you can just pass 
> it straight into any method expecting a ResultSet?
> By all means experiment with this and see if it works for you & submit 
> a patch. Patches are always most welcome :)