You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by James Strachan <ja...@yahoo.co.uk> on 2002/09/13 19:52:19 UTC

[beanutils] ResultSetDynaClass and closing down connections, statements, result sets

I really like the ResultSetDynaClass and ResultSetIterator for using
DynaBeans to access arbitrary relational data. I used them in the simple
DynaSql class I added to commons-sql.

However one downside with the classes as they stand right now is they keep a
ResultSet object and don't close it. Plus neither would the Connection or
Statement that created the ResultSet, since they don't know then the
iterator finishes. So how about we attach the Connection and Statement to
the ResultSetDynaClass so that when the iterator is finished they can be
closed?

Then when the iteration stops, it can close the connection, statement, and
result set if need be.

Also we could have a close() method on the ResultSetIterator so that if
there is a failure, folks can close it down also.

ResultSetIterator iter = ...;
try {
    while (iter.next() ) {
        DynaBean bean = (DynaBean) iter.next();
        ...
    }
    // iterator will now be closed
}
catch (Exception e) {
    iter.close();
}


Thoughts?

James
-------
http://radio.weblogs.com/0112098/

__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [beanutils] ResultSetDynaClass and closing down connections, statements, result sets

Posted by Joe Germuska <Jo...@Germuska.com>.
>So how about we attach the Connection and Statement to
>the ResultSetDynaClass so that when the iterator is finished they can be
>closed?
>
>Then when the iteration stops, it can close the connection, statement, and
>result set if need be.

Would it be too much trouble to set up a event-based mechanism, 
perhaps with a simple listener implementation that responds by 
closing the connection, etc?

I'm just getting acquainted with OJB, and I've recently learned that 
in the cases where I need to use a java.sql.Connection directly, the 
"cleanup" process is different -- you aren't supposed to close the 
connection, you're supposed to close the PersistenceBroker that gave 
it to you.

Maybe collections could use a general IteratorListener and 
accompanying event model?  Off hand, I can't think of other use cases 
for knowing when an iterator finishes (or any cases at all for 
knowing when an iterator.next() is called, etc) but it's worth 
floating for discussion...

Joe

-- 
--
* Joe Germuska    { joe@germuska.com }
"It's pitiful, sometimes, if they've got it bad. Their eyes get 
glazed, they go white, their hands tremble.... As I watch them I 
often feel that a dope peddler is a gentleman compared with the man 
who sells records."
	--Sam Goody, 1956

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>