Re: Unmodifiable ResultSet wrapper?
- From: Lew <lewbloch@xxxxxxxxx>
- Date: Mon, 29 Aug 2011 14:08:57 -0700 (PDT)
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
.
- References:
- Unmodifiable ResultSet wrapper?
- From: Ian Pilcher
- Unmodifiable ResultSet wrapper?
- Prev by Date: Re: number conversion
- Next by Date: Re: number conversion
- Previous by thread: Unmodifiable ResultSet wrapper?
- Next by thread: Java Servlet implentation of Storage API v1.1 around?
- Index(es):
Relevant Pages
|