> The magic happens when you use transactionAwareDataSource together with
> transaction interceptor. It cares about closing.

As far as I understand it, this works well with Spring, and might also
work with J2EE, although you may get a warning in Weblogic, for
instance. Maybe there is potential for enhancing the FactoryProxy, in
order to (optionally) handle the connection's lifecycle, in case no
such magic is available?

Maybe the FactoryProxy should contain a flag to indicate whether the
delegate's connection should be closed explicitly, after use. An
example delegate method:

------------------------------------------------------------------------------
    @Override
    public final <R extends Record> Result<R> fetch(Table<R> table) {
        Factory delegate = getDelegate();
        try {
            return delegate.fetch(table);
        }
        finally {
            close(delegate);
        }
    }

    private void close(Factory delegate) {
        if (closeDelegate && delegate != null) {
            try {
                delegate.getConnection().close();
            }
            catch (SQLException e) {
                // Handle this, here
            }
        }
    }
------------------------------------------------------------------------------

Please, share your thoughts

Cheers
Lukas

Reply via email to