KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > broker > accesslayer > ResultSetAndStatement


1 package org.apache.ojb.broker.accesslayer;
2
3 /* Copyright 2002-2005 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * 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 JavaDoc;
19 import java.sql.Statement JavaDoc;
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 {
30     // private static Logger log = LoggerFactory.getLogger(ResultSetAndStatement.class);
31

32     private final StatementManagerIF manager;
33     private boolean isClosed;
34     /*
35     arminw: declare final to avoid stmt/rs leaking in use
36     by re-setting these fields.
37     */

38     public final ResultSet JavaDoc m_rs;
39     public final Statement JavaDoc m_stmt;
40     public final SelectStatement m_sql;
41
42     public ResultSetAndStatement(StatementManagerIF manager, Statement JavaDoc stmt, ResultSet JavaDoc rs, SelectStatement sql)
43     {
44         this.manager = manager;
45         m_stmt = stmt;
46         m_rs = rs;
47         m_sql = sql;
48         isClosed = false;
49     }
50
51     /**
52      * do a platform specific resource release.
53      * <br/>
54      * Note: This method must be called after usage
55      * of this class.
56      */

57     public void close()
58     {
59         if(!isClosed)
60         {
61             manager.closeResources(m_stmt, m_rs);
62             isClosed = true;
63         }
64     }
65
66 // arminw: This class is internaly used, thus we should take care to close all used
67
// resources without this check.
68
// protected void finalize() throws Throwable
69
// {
70
// super.finalize();
71
// if(!isClosed && (m_stmt != null || m_rs != null))
72
// {
73
// log.warn("** Associated resources (Statement/ResultSet) not closed!" +
74
// " Try automatic cleanup **");
75
// try
76
// {
77
// close();
78
// }
79
// catch (Exception ignore)
80
// {
81
// //ignore it
82
// }
83
// }
84
// }
85
}
86
Popular Tags