001: /*
002: * @(#) SmartStatement 1.0 02/08/01
003: */
004:
005: package org.smartlib.pool.core;
006:
007: import java.sql.*;
008:
009: /**
010: * This class encapsulates a Statement.
011: * Dont expect me to document this class, if you want refer Sun's Documentation.
012: *
013: * @author Sachin Shekar Shetty
014: * @version 1.0, 02/08/01
015: */
016:
017: public class SmartStatement implements Statement, Close {
018:
019: private Statement stmt;
020: private boolean isClosed = false;
021: private SmartConnection sConn;
022: private Debugger debug = new Debugger("SmartStatement", true);
023:
024: // default access
025: SmartStatement(Statement stmt, SmartConnection sConn) {
026:
027: this .stmt = stmt;
028: this .sConn = sConn;
029:
030: }
031:
032: private void preProcess() throws SQLException {
033:
034: if (isClosed())
035: throw new SQLException("Statement already closed");
036: sConn.setLastAccessedTime();
037:
038: }
039:
040: public ResultSet executeQuery(String sql) throws SQLException {
041:
042: preProcess();
043: return stmt.executeQuery(sql);
044:
045: }
046:
047: public int executeUpdate(String sql) throws SQLException {
048:
049: preProcess();
050: return stmt.executeUpdate(sql);
051:
052: }
053:
054: public void close() throws SQLException {
055:
056: if (isClosed)
057: throw new SQLException("Statement already closed");
058: stmt.close();
059: debug.print("Statement Closed for:" + sConn.getOwner());
060: isClosed = true;
061:
062: }
063:
064: public boolean isClosed() throws SQLException {
065:
066: return isClosed;
067:
068: }
069:
070: public int getMaxFieldSize() throws SQLException {
071:
072: preProcess();
073: return stmt.getMaxFieldSize();
074:
075: }
076:
077: public void setMaxFieldSize(int max) throws SQLException {
078:
079: preProcess();
080: stmt.setMaxFieldSize(max);
081:
082: }
083:
084: public int getMaxRows() throws SQLException {
085:
086: preProcess();
087: return stmt.getMaxRows();
088:
089: }
090:
091: public void setMaxRows(int max) throws SQLException {
092:
093: preProcess();
094: stmt.setMaxRows(max);
095:
096: }
097:
098: public void setEscapeProcessing(boolean enable) throws SQLException {
099:
100: preProcess();
101: stmt.setEscapeProcessing(enable);
102:
103: }
104:
105: public int getQueryTimeout() throws SQLException {
106:
107: preProcess();
108: return stmt.getQueryTimeout();
109:
110: }
111:
112: public void setQueryTimeout(int seconds) throws SQLException {
113:
114: preProcess();
115: stmt.setQueryTimeout(seconds);
116:
117: }
118:
119: public void cancel() throws SQLException {
120:
121: preProcess();
122: stmt.cancel();
123:
124: }
125:
126: public SQLWarning getWarnings() throws SQLException {
127:
128: preProcess();
129: return stmt.getWarnings();
130:
131: }
132:
133: public void clearWarnings() throws SQLException {
134:
135: preProcess();
136: stmt.clearWarnings();
137:
138: }
139:
140: public void setCursorName(String name) throws SQLException {
141:
142: preProcess();
143: stmt.setCursorName(name);
144:
145: }
146:
147: public boolean execute(String sql) throws SQLException {
148:
149: preProcess();
150: return stmt.execute(sql);
151:
152: }
153:
154: public ResultSet getResultSet() throws SQLException {
155:
156: preProcess();
157: return stmt.getResultSet();
158:
159: }
160:
161: public int getUpdateCount() throws SQLException {
162:
163: preProcess();
164: return stmt.getUpdateCount();
165:
166: }
167:
168: public boolean getMoreResults() throws SQLException {
169:
170: preProcess();
171: return stmt.getMoreResults();
172:
173: }
174:
175: public void setFetchDirection(int direction) throws SQLException {
176:
177: preProcess();
178: stmt.setFetchDirection(direction);
179:
180: }
181:
182: public int getFetchDirection() throws SQLException {
183:
184: preProcess();
185: return stmt.getFetchDirection();
186:
187: }
188:
189: public void setFetchSize(int rows) throws SQLException {
190:
191: preProcess();
192: stmt.setFetchSize(rows);
193:
194: }
195:
196: public int getFetchSize() throws SQLException {
197:
198: preProcess();
199: return stmt.getFetchSize();
200:
201: }
202:
203: public int getResultSetConcurrency() throws SQLException {
204:
205: preProcess();
206: return stmt.getResultSetConcurrency();
207:
208: }
209:
210: public int getResultSetType() throws SQLException {
211:
212: preProcess();
213: return stmt.getResultSetType();
214:
215: }
216:
217: public void addBatch(String sql) throws SQLException {
218:
219: preProcess();
220: stmt.addBatch(sql);
221:
222: }
223:
224: public void clearBatch() throws SQLException {
225:
226: preProcess();
227: stmt.clearBatch();
228:
229: }
230:
231: public int[] executeBatch() throws SQLException {
232:
233: preProcess();
234: return stmt.executeBatch();
235:
236: }
237:
238: public Connection getConnection() throws SQLException {
239:
240: preProcess();
241: return stmt.getConnection();
242:
243: }
244:
245: public boolean getMoreResults(int current) throws SQLException {
246: return false; //To change body of implemented methods use File | Settings | File Templates.
247: }
248:
249: public ResultSet getGeneratedKeys() throws SQLException {
250: return null; //To change body of implemented methods use File | Settings | File Templates.
251: }
252:
253: public int executeUpdate(String sql, int autoGeneratedKeys)
254: throws SQLException {
255: return 0; //To change body of implemented methods use File | Settings | File Templates.
256: }
257:
258: public int executeUpdate(String sql, int columnIndexes[])
259: throws SQLException {
260: return 0; //To change body of implemented methods use File | Settings | File Templates.
261: }
262:
263: public int executeUpdate(String sql, String columnNames[])
264: throws SQLException {
265: return 0; //To change body of implemented methods use File | Settings | File Templates.
266: }
267:
268: public boolean execute(String sql, int autoGeneratedKeys)
269: throws SQLException {
270: return false; //To change body of implemented methods use File | Settings | File Templates.
271: }
272:
273: public boolean execute(String sql, int columnIndexes[])
274: throws SQLException {
275: return false; //To change body of implemented methods use File | Settings | File Templates.
276: }
277:
278: public boolean execute(String sql, String columnNames[])
279: throws SQLException {
280: return false; //To change body of implemented methods use File | Settings | File Templates.
281: }
282:
283: public int getResultSetHoldability() throws SQLException {
284: return 0; //To change body of implemented methods use File | Settings | File Templates.
285: }
286:
287: public String toString() {
288:
289: return stmt.toString();
290:
291: }
292:
293: }
|