001    package org.apache.ojb.broker.accesslayer;
002    
003    /* Copyright 2002-2005 The Apache Software Foundation
004     *
005     * Licensed under the Apache License, Version 2.0 (the "License");
006     * you may not use this file except in compliance with the License.
007     * You may obtain a copy of the License at
008     *
009     *     http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    
018    import java.sql.ResultSet;
019    import java.sql.Statement;
020    
021    import org.apache.ojb.broker.accesslayer.sql.SelectStatement;
022    
023    /**
024     * Intern used wrapper for {@link Statement} and {@link ResultSet} instances.
025     *
026     * @version $Id: ResultSetAndStatement.java,v 1.1 2007-08-24 22:17:30 ewestfal Exp $
027     */
028    public class ResultSetAndStatement
029    {
030            // private static Logger log = LoggerFactory.getLogger(ResultSetAndStatement.class);
031    
032            private final StatementManagerIF manager;
033        private boolean isClosed;
034        /*
035        arminw: declare final to avoid stmt/rs leaking in use
036        by re-setting these fields.
037        */
038        public final ResultSet m_rs;
039        public final Statement m_stmt;
040        public final SelectStatement m_sql;
041    
042            public ResultSetAndStatement(StatementManagerIF manager, Statement stmt, ResultSet rs, SelectStatement sql)
043        {
044                    this.manager = manager;
045            m_stmt = stmt;
046            m_rs = rs;
047            m_sql = sql;
048            isClosed = false;
049        }
050    
051        /**
052         * do a platform specific resource release.
053         * <br/>
054         * Note: This method must be called after usage
055         * of this class.
056         */
057        public void close()
058        {
059            if(!isClosed)
060            {
061                manager.closeResources(m_stmt, m_rs);
062                isClosed = true;
063            }
064        }
065    
066    // arminw: This class is internaly used, thus we should take care to close all used
067    // resources without this check.
068    //    protected void finalize() throws Throwable
069    //    {
070    //        super.finalize();
071    //        if(!isClosed && (m_stmt != null || m_rs != null))
072    //        {
073    //            log.warn("** Associated resources (Statement/ResultSet) not closed!" +
074    //                    " Try automatic cleanup **");
075    //            try
076    //            {
077    //                close();
078    //            }
079    //            catch (Exception ignore)
080    //            {
081    //                //ignore it
082    //            }
083    //        }
084    //    }
085    }