KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > jdbc > core > CoreStatement


1 /*
2  * XAPool: Open Source XA JDBC Pool
3  * Copyright (C) 2003 Objectweb.org
4  * Initial Developer: Lutris Technologies Inc.
5  * Contact: xapool-public@lists.debian-sf.objectweb.org
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 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
20  * USA
21  */

22 package org.enhydra.jdbc.core;
23
24 import org.enhydra.jdbc.util.JdbcUtil;
25
26 import java.sql.Connection JavaDoc;
27 import java.sql.ResultSet JavaDoc;
28 import java.sql.SQLException JavaDoc;
29 import java.sql.SQLWarning JavaDoc;
30 import java.sql.Statement JavaDoc;
31
32 /**
33  * A very simple implementation of Statement. When created
34  * it is supplied with another Statement to which all
35  * of this class' methods delegate their work.
36  */

37 public abstract class CoreStatement extends JdbcUtil implements Statement JavaDoc {
38
39     protected Statement JavaDoc statement;
40     // the Statement which does most of the work.
41

42     public void addBatch(String JavaDoc s) throws SQLException JavaDoc {
43         //preInvoke();
44
try {
45             statement.addBatch(s);
46         } catch (SQLException JavaDoc e) {
47             catchInvoke(e);
48         }
49     }
50
51     public void cancel() throws SQLException JavaDoc {
52         //preInvoke();
53
try {
54             statement.cancel();
55         } catch (SQLException JavaDoc e) {
56             catchInvoke(e);
57         }
58     }
59
60     public void clearBatch() throws SQLException JavaDoc {
61         //preInvoke();
62
try {
63             statement.clearBatch();
64         } catch (SQLException JavaDoc e) {
65             catchInvoke(e);
66         }
67     }
68
69     public void clearWarnings() throws SQLException JavaDoc {
70         //preInvoke();
71
try {
72             statement.clearWarnings();
73         } catch (SQLException JavaDoc e) {
74             catchInvoke(e);
75         }
76     }
77
78     public void close() throws SQLException JavaDoc {
79         if (statement != null) {
80             statement.close();
81         }
82     }
83
84     public boolean execute(String JavaDoc s) throws SQLException JavaDoc {
85         //preInvoke();
86
try {
87             return statement.execute(s);
88         } catch (SQLException JavaDoc e) {
89             catchInvoke(e);
90         }
91         return false;
92     }
93
94     public int[] executeBatch() throws SQLException JavaDoc {
95         //preInvoke();
96
try {
97             return statement.executeBatch();
98         } catch (SQLException JavaDoc e) {
99             catchInvoke(e);
100         }
101         return null;
102     }
103
104     public ResultSet JavaDoc executeQuery(String JavaDoc s) throws SQLException JavaDoc {
105         //preInvoke();
106
try {
107             return statement.executeQuery(s);
108         } catch (SQLException JavaDoc e) {
109             catchInvoke(e);
110         }
111         return null;
112     }
113
114     public int executeUpdate(String JavaDoc s) throws SQLException JavaDoc {
115         //preInvoke();
116
try {
117             return statement.executeUpdate(s);
118         } catch (SQLException JavaDoc e) {
119             catchInvoke(e);
120         }
121         return 0;
122     }
123
124     public Connection JavaDoc getConnection() throws SQLException JavaDoc {
125         //preInvoke();
126
try {
127             return statement.getConnection();
128         } catch (SQLException JavaDoc e) {
129             catchInvoke(e);
130         }
131         return null;
132     }
133
134     public int getFetchDirection() throws SQLException JavaDoc {
135         //preInvoke();
136
try {
137             return statement.getFetchDirection();
138         } catch (SQLException JavaDoc e) {
139             catchInvoke(e);
140         }
141         return 0;
142     }
143
144     public int getFetchSize() throws SQLException JavaDoc {
145         //preInvoke();
146
try {
147             return statement.getFetchSize();
148         } catch (SQLException JavaDoc e) {
149             catchInvoke(e);
150         }
151         return 0;
152     }
153
154     public ResultSet JavaDoc getGeneratedKeys() throws SQLException JavaDoc {
155         //preInvoke();
156
try {
157             return statement.getGeneratedKeys();
158         } catch (SQLException JavaDoc e) {
159             catchInvoke(e);
160         }
161                 return null;
162     }
163
164     public int getMaxFieldSize() throws SQLException JavaDoc {
165         //preInvoke();
166
try {
167             return statement.getMaxFieldSize();
168         } catch (SQLException JavaDoc e) {
169             catchInvoke(e);
170         }
171         return 0;
172     }
173
174     public int getMaxRows() throws SQLException JavaDoc {
175         //preInvoke();
176
try {
177             return statement.getMaxRows();
178         } catch (SQLException JavaDoc e) {
179             catchInvoke(e);
180         }
181         return 0;
182     }
183
184     public boolean getMoreResults() throws SQLException JavaDoc {
185         //preInvoke();
186
try {
187             return statement.getMoreResults();
188         } catch (SQLException JavaDoc e) {
189             catchInvoke(e);
190         }
191         return false;
192     }
193
194     public int getQueryTimeout() throws SQLException JavaDoc {
195         //preInvoke();
196
try {
197             return statement.getQueryTimeout();
198         } catch (SQLException JavaDoc e) {
199             catchInvoke(e);
200         }
201         return 0;
202     }
203
204     public ResultSet JavaDoc getResultSet() throws SQLException JavaDoc {
205         //preInvoke();
206
try {
207             return statement.getResultSet();
208         } catch (SQLException JavaDoc e) {
209             catchInvoke(e);
210         }
211         return null;
212     }
213
214     public int getResultSetConcurrency() throws SQLException JavaDoc {
215         //preInvoke();
216
try {
217             return statement.getResultSetConcurrency();
218         } catch (SQLException JavaDoc e) {
219             catchInvoke(e);
220         }
221         return 0;
222     }
223
224     public int getResultSetType() throws SQLException JavaDoc {
225         //preInvoke();
226
try {
227             return statement.getResultSetType();
228         } catch (SQLException JavaDoc e) {
229             catchInvoke(e);
230         }
231         return 0;
232     }
233
234     public int getUpdateCount() throws SQLException JavaDoc {
235         //preInvoke();
236
try {
237             return statement.getUpdateCount();
238         } catch (SQLException JavaDoc e) {
239             catchInvoke(e);
240         }
241         return 0;
242     }
243
244     public SQLWarning JavaDoc getWarnings() throws SQLException JavaDoc {
245         //preInvoke();
246
try {
247             return statement.getWarnings();
248         } catch (SQLException JavaDoc e) {
249             catchInvoke(e);
250         }
251         return null;
252     }
253
254     public void setCursorName(String JavaDoc name) throws SQLException JavaDoc {
255         //preInvoke();
256
try {
257             statement.setCursorName(name);
258         } catch (SQLException JavaDoc e) {
259             catchInvoke(e);
260         }
261     }
262
263     public void setEscapeProcessing(boolean enable) throws SQLException JavaDoc {
264         //preInvoke();
265
try {
266             statement.setEscapeProcessing(enable);
267         } catch (SQLException JavaDoc e) {
268             catchInvoke(e);
269         }
270     }
271
272     public void setFetchDirection(int direction) throws SQLException JavaDoc {
273         //preInvoke();
274
try {
275             statement.setFetchDirection(direction);
276         } catch (SQLException JavaDoc e) {
277             catchInvoke(e);
278         }
279     }
280
281     public void setFetchSize(int rows) throws SQLException JavaDoc {
282         //preInvoke();
283
try {
284             statement.setFetchSize(rows);
285         } catch (SQLException JavaDoc e) {
286             catchInvoke(e);
287         }
288     }
289
290     public void setMaxFieldSize(int max) throws SQLException JavaDoc {
291         //preInvoke();
292
try {
293             statement.setMaxFieldSize(max);
294         } catch (SQLException JavaDoc e) {
295             catchInvoke(e);
296         }
297     }
298
299     public void setMaxRows(int max) throws SQLException JavaDoc {
300         //preInvoke();
301
try {
302             statement.setMaxRows(max);
303         } catch (SQLException JavaDoc e) {
304             catchInvoke(e);
305         }
306     }
307
308     public void setQueryTimeout(int seconds) throws SQLException JavaDoc {
309         //preInvoke();
310
try {
311             statement.setQueryTimeout(seconds);
312         } catch (SQLException JavaDoc e) {
313             catchInvoke(e);
314         }
315     }
316
317     /*
318     * Add those following methods to compile on JDK 1.4.
319     * Instead those methods are defined in the java.sql.Statement interface
320     * only since JDK 1.4.
321     */

322     public boolean execute(String JavaDoc sql, int autoGeneratedKeys)
323         throws SQLException JavaDoc {
324         try {
325             return statement.execute(sql, autoGeneratedKeys);
326         } catch (SQLException JavaDoc e) {
327             catchInvoke(e);
328         }
329                 return false;
330     }
331     public boolean execute(String JavaDoc sql, int[] columnIndexes)
332         throws SQLException JavaDoc {
333         try {
334             return statement.execute(sql, columnIndexes);
335         } catch (SQLException JavaDoc e) {
336             catchInvoke(e);
337         }
338                 return false;
339     }
340     public boolean execute(String JavaDoc sql, String JavaDoc[] columnNames)
341         throws SQLException JavaDoc {
342         try {
343             return statement.execute(sql, columnNames);
344         } catch (SQLException JavaDoc e) {
345             catchInvoke(e);
346         }
347                 return false;
348         }
349     public int executeUpdate(String JavaDoc sql, int autoGeneratedKeys)
350         throws SQLException JavaDoc {
351         try {
352             return statement.executeUpdate(sql, autoGeneratedKeys);
353         } catch (SQLException JavaDoc e) {
354             catchInvoke(e);
355         }
356                 return 0;
357     }
358     public int executeUpdate(String JavaDoc sql, int[] columnIndexes)
359         throws SQLException JavaDoc {
360         try {
361             return statement.executeUpdate(sql, columnIndexes);
362         } catch (SQLException JavaDoc e) {
363             catchInvoke(e);
364         }
365                 return 0;
366     }
367     public int executeUpdate(String JavaDoc sql, String JavaDoc[] columnNames)
368         throws SQLException JavaDoc {
369         try {
370             return statement.executeUpdate(sql, columnNames);
371         } catch (SQLException JavaDoc e) {
372             catchInvoke(e);
373         }
374                 return 0;
375     }
376     public boolean getMoreResults(int current)
377         throws SQLException JavaDoc {
378         try {
379             return statement.getMoreResults(current);
380         } catch (SQLException JavaDoc e) {
381             catchInvoke(e);
382         }
383                 return false;
384     }
385     public int getResultSetHoldability()
386         throws SQLException JavaDoc {
387         try {
388             return statement.getResultSetHoldability();
389         } catch (SQLException JavaDoc e) {
390             catchInvoke(e);
391         }
392                 return 0;
393     }
394
395     /**
396      * Methods used to do some works before and during the catch
397      * clause, to prevent the pool that a connection is broken.
398      */

399     //abstract public void preInvoke() throws SQLException;
400
abstract public void catchInvoke(SQLException JavaDoc e) throws SQLException JavaDoc;
401
402 }
Popular Tags