View Javadoc

1   /*
2    * $Source: /usr/cvsroot/melati/throwing-jdbc/src/main/java/org/melati/poem/dbms/test/sql/ThrowingStatementJdbc3.java,v $
3    * $Revision: 1.4 $
4    *
5    * Copyright (C) 2008 Tim Pizey
6    *
7    * Part of Melati (http://melati.org), a framework for the rapid
8    * development of clean, maintainable web applications.
9    *
10   * Melati is free software; Permission is granted to copy, distribute
11   * and/or modify this software under the terms either:
12   *
13   * a) the GNU General Public License as published by the Free Software
14   *    Foundation; either version 2 of the License, or (at your option)
15   *    any later version,
16   *
17   *    or
18   *
19   * b) any version of the Melati Software License, as published
20   *    at http://melati.org
21   *
22   * You should have received a copy of the GNU General Public License and
23   * the Melati Software License along with this program;
24   * if not, write to the Free Software Foundation, Inc.,
25   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA to obtain the
26   * GNU General Public License and visit http://melati.org to obtain the
27   * Melati Software License.
28   *
29   * Feel free to contact the Developers of Melati (http://melati.org),
30   * if you would like to work out a different arrangement than the options
31   * outlined here.  It is our intention to allow Melati to be used by as
32   * wide an audience as possible.
33   *
34   * This program is distributed in the hope that it will be useful,
35   * but WITHOUT ANY WARRANTY; without even the implied warranty of
36   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
37   * GNU General Public License for more details.
38   *
39   * Contact details for copyright holder:
40   *
41   *     Tim Pizey <timp At paneris.org>
42   *     http://paneris.org/~timp
43   */
44  
45  package org.melati.poem.dbms.test.sql;
46  
47  import java.sql.Connection;
48  import java.sql.ResultSet;
49  import java.sql.SQLException;
50  import java.sql.SQLWarning;
51  import java.sql.Statement;
52  
53  /**
54   *  The JDBC3 members of a {@link Statement}, decorated to throw SQLException on command.
55   *  
56   * @author timp
57   * @since  5 Feb 2008
58   *
59   */
60  public abstract class ThrowingStatementJdbc3 
61      extends Thrower 
62      implements Statement{
63  
64    Statement it = null;
65    
66    /**
67     * {@inheritDoc}
68     * 
69     * @see java.sql.Statement#addBatch(java.lang.String)
70     */
71    public void addBatch(String sql) throws SQLException {
72      if (shouldThrow(this.getClass().getInterfaces()[0], "addBatch"))
73        throw new SQLException("Statement bombed");
74      it.addBatch(sql);
75    }
76  
77    /**
78     * {@inheritDoc}
79     * 
80     * @see java.sql.Statement#cancel()
81     */
82    public void cancel() throws SQLException {
83      if (shouldThrow(this.getClass().getInterfaces()[0], "cancel"))
84        throw new SQLException("Statement bombed");
85      it.cancel();
86  
87    }
88  
89    /**
90     * {@inheritDoc}
91     * 
92     * @see java.sql.Statement#clearBatch()
93     */
94    public void clearBatch() throws SQLException {
95      if (shouldThrow(this.getClass().getInterfaces()[0], "clearBatch"))
96        throw new SQLException("Statement bombed");
97      it.clearBatch();
98    }
99  
100   /**
101    * {@inheritDoc}
102    * 
103    * @see java.sql.Statement#clearWarnings()
104    */
105   public void clearWarnings() throws SQLException {
106     if (shouldThrow(this.getClass().getInterfaces()[0], "clearWarnings"))
107       throw new SQLException("Statement bombed");
108     it.clearWarnings();
109   }
110 
111   /**
112    * {@inheritDoc}
113    * 
114    * @see java.sql.Statement#close()
115    */
116   public void close() throws SQLException {
117     if (shouldThrow(this.getClass().getInterfaces()[0], "close"))
118       throw new SQLException("Statement bombed");
119     it.close();
120   }
121 
122   /**
123    * {@inheritDoc}
124    * 
125    * @see java.sql.Statement#execute(java.lang.String)
126    */
127   public boolean execute(String sql) throws SQLException {
128     if (shouldThrow(this.getClass().getInterfaces()[0], "execute"))
129       throw new SQLException("Statement bombed");
130 
131     return it.execute(sql);
132   }
133 
134   /**
135    * {@inheritDoc}
136    * 
137    * @see java.sql.Statement#execute(java.lang.String, int)
138    */
139   public boolean execute(String sql, int autoGeneratedKeys) throws SQLException {
140     if (shouldThrow(this.getClass().getInterfaces()[0], "execute"))
141       throw new SQLException("Statement bombed");
142 
143     return it.execute(sql, autoGeneratedKeys);
144   }
145 
146   /**
147    * {@inheritDoc}
148    * 
149    * @see java.sql.Statement#execute(java.lang.String, int[])
150    */
151   public boolean execute(String sql, int[] columnIndexes) throws SQLException {
152     if (shouldThrow(this.getClass().getInterfaces()[0], "execute"))
153       throw new SQLException("Statement bombed");
154 
155     return it.execute(sql, columnIndexes);
156   }
157 
158   /**
159    * {@inheritDoc}
160    * 
161    * @see java.sql.Statement#execute(java.lang.String, java.lang.String[])
162    */
163   public boolean execute(String sql, String[] columnNames) throws SQLException {
164     if (shouldThrow(this.getClass().getInterfaces()[0], "execute"))
165       throw new SQLException("Statement bombed");
166 
167     return it.execute(sql, columnNames);
168   }
169 
170   /**
171    * {@inheritDoc}
172    * 
173    * @see java.sql.Statement#executeBatch()
174    */
175   public int[] executeBatch() throws SQLException {
176     if (shouldThrow(this.getClass().getInterfaces()[0], "executeBatch"))
177       throw new SQLException("Statement bombed");
178 
179     return it.executeBatch();
180   }
181 
182   /**
183    * {@inheritDoc}
184    * 
185    * @see java.sql.Statement#executeQuery(java.lang.String)
186    */
187   public ResultSet executeQuery(String sql) throws SQLException {
188     if (shouldThrow(this.getClass().getInterfaces()[0], "executeQuery"))
189       throw new SQLException("Statement bombed");
190 
191     return new ThrowingResultSet(it.executeQuery(sql));
192   }
193 
194   /**
195    * {@inheritDoc}
196    * 
197    * @see java.sql.Statement#executeUpdate(java.lang.String)
198    */
199   public int executeUpdate(String sql) throws SQLException {
200     if (shouldThrow(this.getClass().getInterfaces()[0], "executeUpdate"))
201       throw new SQLException("Statement bombed");
202 
203     return it.executeUpdate(sql);
204   }
205 
206   /**
207    * {@inheritDoc}
208    * 
209    * @see java.sql.Statement#executeUpdate(java.lang.String, int)
210    */
211   public int executeUpdate(String sql, int autoGeneratedKeys)
212       throws SQLException {
213     if (shouldThrow(this.getClass().getInterfaces()[0], "executeUpdate"))
214       throw new SQLException("Statement bombed");
215 
216     return it.executeUpdate(sql);
217   }
218 
219   /**
220    * {@inheritDoc}
221    * 
222    * @see java.sql.Statement#executeUpdate(java.lang.String, int[])
223    */
224   public int executeUpdate(String sql, int[] columnIndexes) throws SQLException {
225     if (shouldThrow(this.getClass().getInterfaces()[0], "executeUpdate"))
226       throw new SQLException("Statement bombed");
227 
228     return it.executeUpdate(sql);
229   }
230 
231   /**
232    * {@inheritDoc}
233    * 
234    * @see java.sql.Statement#executeUpdate(java.lang.String, java.lang.String[])
235    */
236   public int executeUpdate(String sql, String[] columnNames)
237       throws SQLException {
238     if (shouldThrow(this.getClass().getInterfaces()[0], "executeUpdate"))
239       throw new SQLException("Statement bombed");
240 
241     return it.executeUpdate(sql,columnNames);
242   }
243 
244   /**
245    * {@inheritDoc}
246    * 
247    * @see java.sql.Statement#getConnection()
248    */
249   public Connection getConnection() throws SQLException {
250     if (shouldThrow(this.getClass().getInterfaces()[0], "getConnection"))
251       throw new SQLException("Statement bombed");
252 
253     return new ThrowingConnection(it.getConnection());
254   }
255 
256   /**
257    * {@inheritDoc}
258    * 
259    * @see java.sql.Statement#getFetchDirection()
260    */
261   public int getFetchDirection() throws SQLException {
262     if (shouldThrow(this.getClass().getInterfaces()[0], "getFetchDirection"))
263       throw new SQLException("Statement bombed");
264 
265     return it.getFetchDirection();
266   }
267 
268   /**
269    * {@inheritDoc}
270    * 
271    * @see java.sql.Statement#getFetchSize()
272    */
273   public int getFetchSize() throws SQLException {
274     if (shouldThrow(this.getClass().getInterfaces()[0], "getFetchSize"))
275       throw new SQLException("Statement bombed");
276 
277     return it.getFetchSize();
278   }
279 
280   /**
281    * {@inheritDoc}
282    * 
283    * @see java.sql.Statement#getGeneratedKeys()
284    */
285   public ResultSet getGeneratedKeys() throws SQLException {
286     if (shouldThrow(this.getClass().getInterfaces()[0], "getGeneratedKeys"))
287       throw new SQLException("Statement bombed");
288 
289     return new ThrowingResultSet(it.getGeneratedKeys());
290   }
291 
292   /**
293    * {@inheritDoc}
294    * 
295    * @see java.sql.Statement#getMaxFieldSize()
296    */
297   public int getMaxFieldSize() throws SQLException {
298     if (shouldThrow(this.getClass().getInterfaces()[0], "getMaxFieldSize"))
299       throw new SQLException("Statement bombed");
300 
301     return it.getMaxFieldSize();
302   }
303 
304   /**
305    * {@inheritDoc}
306    * 
307    * @see java.sql.Statement#getMaxRows()
308    */
309   public int getMaxRows() throws SQLException {
310     if (shouldThrow(this.getClass().getInterfaces()[0], "getMaxRows"))
311       throw new SQLException("Statement bombed");
312 
313     return it.getMaxRows();
314   }
315 
316   /**
317    * {@inheritDoc}
318    * 
319    * @see java.sql.Statement#getMoreResults()
320    */
321   public boolean getMoreResults() throws SQLException {
322     if (shouldThrow(this.getClass().getInterfaces()[0], "getMoreResults"))
323       throw new SQLException("Statement bombed");
324 
325     return it.getMoreResults();
326   }
327 
328   /**
329    * {@inheritDoc}
330    * 
331    * @see java.sql.Statement#getMoreResults(int)
332    */
333   public boolean getMoreResults(int current) throws SQLException {
334     if (shouldThrow(this.getClass().getInterfaces()[0], "getMoreResults"))
335       throw new SQLException("Statement bombed");
336 
337     return it.getMoreResults(current);
338   }
339 
340   /**
341    * {@inheritDoc}
342    * 
343    * @see java.sql.Statement#getQueryTimeout()
344    */
345   public int getQueryTimeout() throws SQLException {
346     if (shouldThrow(this.getClass().getInterfaces()[0], "getQueryTimeout"))
347       throw new SQLException("Statement bombed");
348 
349     return it.getQueryTimeout();
350   }
351 
352   /**
353    * {@inheritDoc}
354    * 
355    * @see java.sql.Statement#getResultSet()
356    */
357   public ResultSet getResultSet() throws SQLException {
358     if (shouldThrow(this.getClass().getInterfaces()[0], "getResultSet"))
359       throw new SQLException("Statement bombed");
360 
361     return new ThrowingResultSet(it.getResultSet());
362   }
363 
364   /**
365    * {@inheritDoc}
366    * 
367    * @see java.sql.Statement#getResultSetConcurrency()
368    */
369   public int getResultSetConcurrency() throws SQLException {
370     if (shouldThrow(this.getClass().getInterfaces()[0], "getResultSetConcurrency"))
371       throw new SQLException("Statement bombed");
372 
373     return it.getResultSetConcurrency();
374   }
375 
376   /**
377    * {@inheritDoc}
378    * 
379    * @see java.sql.Statement#getResultSetHoldability()
380    */
381   public int getResultSetHoldability() throws SQLException {
382     if (shouldThrow(this.getClass().getInterfaces()[0], "getResultSetHoldability"))
383       throw new SQLException("Statement bombed");
384 
385     return it.getResultSetHoldability();
386   }
387 
388   /**
389    * {@inheritDoc}
390    * 
391    * @see java.sql.Statement#getResultSetType()
392    */
393   public int getResultSetType() throws SQLException {
394     if (shouldThrow(this.getClass().getInterfaces()[0], "getResultSetType"))
395       throw new SQLException("Statement bombed");
396 
397     return it.getResultSetType();
398   }
399 
400   /**
401    * {@inheritDoc}
402    * 
403    * @see java.sql.Statement#getUpdateCount()
404    */
405   public int getUpdateCount() throws SQLException {
406     if (shouldThrow(this.getClass().getInterfaces()[0], "getUpdateCount"))
407       throw new SQLException("Statement bombed");
408 
409     return it.getUpdateCount();
410   }
411 
412   /**
413    * {@inheritDoc}
414    * 
415    * @see java.sql.Statement#getWarnings()
416    */
417   public SQLWarning getWarnings() throws SQLException {
418     if (shouldThrow(this.getClass().getInterfaces()[0], "getWarnings"))
419       throw new SQLException("Statement bombed");
420 
421     return it.getWarnings();
422   }
423 
424   /**
425    * {@inheritDoc}
426    * 
427    * @see java.sql.Statement#setCursorName(java.lang.String)
428    */
429   public void setCursorName(String name) throws SQLException {
430     if (shouldThrow(this.getClass().getInterfaces()[0], "setCursorName"))
431       throw new SQLException("Statement bombed");
432     it.setCursorName(name);
433   }
434 
435   /**
436    * {@inheritDoc}
437    * 
438    * @see java.sql.Statement#setEscapeProcessing(boolean)
439    */
440   public void setEscapeProcessing(boolean enable) throws SQLException {
441     if (shouldThrow(this.getClass().getInterfaces()[0], "setEscapeProcessing"))
442       throw new SQLException("Statement bombed");
443     it.setEscapeProcessing(enable);
444   }
445 
446   /**
447    * {@inheritDoc}
448    * 
449    * @see java.sql.Statement#setFetchDirection(int)
450    */
451   public void setFetchDirection(int direction) throws SQLException {
452     if (shouldThrow(this.getClass().getInterfaces()[0], "setFetchDirection"))
453       throw new SQLException("Statement bombed");
454     it.setFetchDirection(direction);
455   }
456 
457   /**
458    * {@inheritDoc}
459    * 
460    * @see java.sql.Statement#setFetchSize(int)
461    */
462   public void setFetchSize(int rows) throws SQLException {
463     if (shouldThrow(this.getClass().getInterfaces()[0], "setFetchSize"))
464       throw new SQLException("Statement bombed");
465     it.setFetchSize(rows);
466   }
467 
468   /**
469    * {@inheritDoc}
470    * 
471    * @see java.sql.Statement#setMaxFieldSize(int)
472    */
473   public void setMaxFieldSize(int max) throws SQLException {
474     if (shouldThrow(this.getClass().getInterfaces()[0], "setMaxFieldSize"))
475       throw new SQLException("Statement bombed");
476     it.setMaxFieldSize(max);
477   }
478 
479   /**
480    * {@inheritDoc}
481    * 
482    * @see java.sql.Statement#setMaxRows(int)
483    */
484   public void setMaxRows(int max) throws SQLException {
485     if (shouldThrow(this.getClass().getInterfaces()[0], "setMaxRows"))
486       throw new SQLException("Statement bombed");
487     it.setMaxRows(max);
488   }
489 
490   /**
491    * {@inheritDoc}
492    * 
493    * @see java.sql.Statement#setQueryTimeout(int)
494    */
495   public void setQueryTimeout(int seconds) throws SQLException {
496     if (shouldThrow(this.getClass().getInterfaces()[0], "setQueryTimeout"))
497       throw new SQLException("Statement bombed");
498     it.setQueryTimeout(seconds);
499   }
500 
501 
502 }