Re: Unmodifiable ResultSet wrapper?



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
.



Relevant Pages

  • Unmodifiable ResultSet wrapper?
    ... Is there any standard way to wrap a ResultSet into an unmodifiable ... I need to pass a ResultSet to a callback as I iterate through ... It's a perfectly straightforward exercise to create such a wrapper, ...
    (comp.lang.java.programmer)
  • Re: Unmodifiable ResultSet wrapper?
    ... I need to pass a ResultSet to a callback as I iterate through ... it, and the callback has no business altering its state, ... The method that's iterating through the ResultSet obviously needs to ...
    (comp.lang.java.programmer)
  • Re: Unmodifiable ResultSet wrapper?
    ... I need to pass a ResultSet to a callback as I iterate through ... it, and the callback has no business altering its state, ... The method that's iterating through the ResultSet obviously needs to ...
    (comp.lang.java.programmer)