01: package org.apache.ojb.broker.accesslayer;
02:
03: /* Copyright 2002-2005 The Apache Software Foundation
04: *
05: * Licensed under the Apache License, Version 2.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: import java.sql.ResultSet;
19: import java.sql.Statement;
20:
21: import org.apache.ojb.broker.accesslayer.sql.SelectStatement;
22:
23: /**
24: * Intern used wrapper for {@link Statement} and {@link ResultSet} instances.
25: *
26: * @version $Id: ResultSetAndStatement.java,v 1.13.2.4 2005/12/21 22:22:58 tomdz Exp $
27: */
28: public class ResultSetAndStatement {
29: // private static Logger log = LoggerFactory.getLogger(ResultSetAndStatement.class);
30:
31: private final StatementManagerIF manager;
32: private boolean isClosed;
33: /*
34: arminw: declare final to avoid stmt/rs leaking in use
35: by re-setting these fields.
36: */
37: public final ResultSet m_rs;
38: public final Statement m_stmt;
39: public final SelectStatement m_sql;
40:
41: public ResultSetAndStatement(StatementManagerIF manager,
42: Statement stmt, ResultSet rs, SelectStatement sql) {
43: this .manager = manager;
44: m_stmt = stmt;
45: m_rs = rs;
46: m_sql = sql;
47: isClosed = false;
48: }
49:
50: /**
51: * do a platform specific resource release.
52: * <br/>
53: * Note: This method must be called after usage
54: * of this class.
55: */
56: public void close() {
57: if (!isClosed) {
58: manager.closeResources(m_stmt, m_rs);
59: isClosed = true;
60: }
61: }
62:
63: // arminw: This class is internaly used, thus we should take care to close all used
64: // resources without this check.
65: // protected void finalize() throws Throwable
66: // {
67: // super.finalize();
68: // if(!isClosed && (m_stmt != null || m_rs != null))
69: // {
70: // log.warn("** Associated resources (Statement/ResultSet) not closed!" +
71: // " Try automatic cleanup **");
72: // try
73: // {
74: // close();
75: // }
76: // catch (Exception ignore)
77: // {
78: // //ignore it
79: // }
80: // }
81: // }
82: }
|