Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #7480
| From | Lew <lewbloch@gmail.com> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Unmodifiable ResultSet wrapper? |
| Date | 2011-08-29 14:08 -0700 |
| Organization | http://groups.google.com |
| Message-ID | <87879b14-d65c-4f0b-9d7c-0efb203dc922@glegroupsg2000goo.googlegroups.com> (permalink) |
| References | <XYR6q.1475$Ld7.24@newsfe21.iad> |
Ian Pilcher wrote: > Is there any standard way to wrap a ResultSet into an unmodifiable > wrapper? I need to pass a ResultSet to a callback as I iterate through > it, and the callback has no business altering its state (calling next(), > etc.) > > It's a perfectly straightforward exercise to create such a wrapper, but > that's a ton of boilerplate code ... There is no standard way to pass an unmodifiable ResultSet back, perhaps because it's a really bad idea. ResultSets carry all sorts of database connection and Statement state with them, so exposing that through a callback is a layer violation and a flat-out request for disaster. Don't do it. Also, the _raison d'etre_ for ResultSet is to perform 'next()' and other such calls. Asking for a ResultSet on which you don't wish to do the fundamental operations is a red flag that you're heading the wrong way down Fubar Path. The standard approach is to unwrap the data from the ResultSet into an object within your domain model and pass that back. The object with the callback almost certainly doesn't want the relational model but a domain model anyway. You should consider JPA. And perhaps take a course in object-oriented design. -- Lew
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar
Unmodifiable ResultSet wrapper? Ian Pilcher <arequipeno@gmail.com> - 2011-08-29 14:42 -0500
Re: Unmodifiable ResultSet wrapper? Lew <lewbloch@gmail.com> - 2011-08-29 14:08 -0700
Re: Unmodifiable ResultSet wrapper? Ian Pilcher <arequipeno@gmail.com> - 2011-09-02 09:30 -0500
Re: Unmodifiable ResultSet wrapper? Lew <lewbloch@gmail.com> - 2011-09-03 00:59 -0700
csiph-web