KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > uk > org > primrose > pool > core > PoolStatement


1 /**
2 * Library name : Primrose - A Java Database Connection Pool.
3 * Published by Ben Keeping, http://primrose.org.uk .
4 * Copyright (C) 2004 Ben Keeping, primrose.org.uk
5 * Email: Use "Contact Us Form" on website
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */

21
22 package uk.org.primrose.pool.core;
23 import java.sql.*;
24
25 /**
26 * A wrapper for a vendor specific implementation of Statement.
27 * Allows for complete logging of SQL transactions, aswell as identifying
28 * unclosed statements before Connection close() calls.
29 */

30 public class PoolStatement implements Statement {
31     Statement s = null;
32     PoolSqlMonitor poolSqlMonitor = null;
33
34     public PoolStatement(Statement s, PoolSqlMonitor poolSqlMonitor) {
35         this.poolSqlMonitor = poolSqlMonitor;
36         poolSqlMonitor.setStatementClosed(false);
37         poolSqlMonitor.setStatement(this);
38         this.s = s;
39     }
40
41     public PoolStatement(){}
42
43     public void setPoolSqlMonitor(PoolSqlMonitor poolSqlMonitor) {
44         this.poolSqlMonitor = poolSqlMonitor;
45     }
46
47     public PoolSqlMonitor getPoolSqlMonitor() {
48         return poolSqlMonitor;
49     }
50
51     public void close() throws SQLException {
52         if (poolSqlMonitor.isStatementClosed() == false) {
53             poolSqlMonitor.setStatementClosed(true);
54             s.close();
55         }
56     }
57
58     public ResultSet executeQuery(String JavaDoc sql) throws SQLException {
59         PoolResultSet prs = new PoolResultSet(s.executeQuery(sql), this.getPoolSqlMonitor());
60         this.getPoolSqlMonitor().setSql(sql);
61         return prs;
62     }
63
64     public int executeUpdate(String JavaDoc sql) throws SQLException {
65         this.getPoolSqlMonitor().setSql(sql);
66         return s.executeUpdate(sql);
67     }
68
69     public int executeUpdate(String JavaDoc sql, int autoGeneratedKeys) throws SQLException {
70         this.getPoolSqlMonitor().setSql(sql);
71         return s.executeUpdate(sql, autoGeneratedKeys);
72     }
73
74     public int executeUpdate(String JavaDoc sql, int columnIndexes[]) throws SQLException {
75         this.getPoolSqlMonitor().setSql(sql);
76         return s.executeUpdate(sql, columnIndexes);
77     }
78
79     public int executeUpdate(String JavaDoc sql, String JavaDoc columnNames[]) throws SQLException {
80         this.getPoolSqlMonitor().setSql(sql);
81         return s.executeUpdate(sql, columnNames);
82     }
83
84     public boolean execute(String JavaDoc sql, int autoGeneratedKeys) throws SQLException {
85         this.getPoolSqlMonitor().setSql(sql);
86         return s.execute(sql, autoGeneratedKeys);
87     }
88
89     public boolean execute(String JavaDoc sql, int columnIndexes[]) throws SQLException {
90         this.getPoolSqlMonitor().setSql(sql);
91         return s.execute(sql, columnIndexes);
92     }
93
94     public boolean execute(String JavaDoc sql, String JavaDoc columnNames[]) throws SQLException {
95         this.getPoolSqlMonitor().setSql(sql);
96         return s.execute(sql, columnNames);
97     }
98
99     public int[] executeBatch() throws SQLException {
100         return s.executeBatch();
101     }
102
103     public int getMaxFieldSize() throws SQLException {
104         return s.getMaxFieldSize();
105     }
106
107     public void setMaxFieldSize(int max) throws SQLException {
108         s.setMaxFieldSize(max);
109     }
110
111     public int getMaxRows() throws SQLException {
112         return s.getMaxRows();
113     }
114
115     public void setMaxRows(int max) throws SQLException {
116         s.setMaxRows(max);
117     }
118
119     public void setEscapeProcessing(boolean enable) throws SQLException {
120         s.setEscapeProcessing(enable);
121     }
122
123     public int getQueryTimeout() throws SQLException {
124         return s.getQueryTimeout();
125     }
126
127     public void setQueryTimeout(int seconds) throws SQLException {
128         s.setQueryTimeout(seconds);
129     }
130
131     public void cancel() throws SQLException {
132         s.cancel();
133     }
134
135     public SQLWarning getWarnings() throws SQLException {
136         return s.getWarnings();
137     }
138
139     public void clearWarnings() throws SQLException {
140         s.clearWarnings();
141     }
142
143     public void setCursorName(String JavaDoc name) throws SQLException {
144         s.setCursorName(name);
145     }
146
147     public boolean execute(String JavaDoc sql) throws SQLException {
148         this.getPoolSqlMonitor().setSql(sql);
149         return s.execute(sql);
150     }
151
152     public ResultSet getResultSet() throws SQLException {
153         PoolResultSet prs = new PoolResultSet(s.getResultSet(), this.getPoolSqlMonitor());
154         return prs;
155     }
156
157     public int getUpdateCount() throws SQLException {
158         return s.getUpdateCount();
159     }
160
161     public boolean getMoreResults() throws SQLException {
162         return s.getMoreResults();
163     }
164
165     public void setFetchDirection(int direction) throws SQLException {
166         s.setFetchDirection(direction);
167     }
168
169     public int getFetchDirection() throws SQLException {
170         return s.getFetchDirection();
171     }
172
173     public void setFetchSize(int rows) throws SQLException {
174         s.setFetchSize(rows);
175     }
176
177     public int getFetchSize() throws SQLException {
178         return s.getFetchSize();
179     }
180
181     public int getResultSetConcurrency() throws SQLException {
182         return s.getResultSetConcurrency();
183     }
184
185     public int getResultSetType() throws SQLException {
186         return s.getResultSetType();
187     }
188
189     public void addBatch(String JavaDoc sql) throws SQLException {
190         s.addBatch(sql);
191     }
192
193     public void clearBatch() throws SQLException {
194         s.clearBatch();
195     }
196
197     public Connection getConnection() throws SQLException {
198         return s.getConnection();
199     }
200
201     public boolean getMoreResults(int current) throws SQLException {
202         return s.getMoreResults(current);
203     }
204
205     public ResultSet getGeneratedKeys() throws SQLException {
206         PoolResultSet prs = new PoolResultSet(s.getGeneratedKeys(), this.getPoolSqlMonitor());
207         return prs;
208     }
209
210     public int getResultSetHoldability() throws SQLException {
211         return s.getResultSetHoldability();
212     }
213
214 }
Popular Tags