KickJava   Java API By Example, From Geeks To Geeks.

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


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.CallableStatement JavaDoc;
27 import java.sql.Connection JavaDoc;
28 import java.sql.DatabaseMetaData JavaDoc;
29 import java.sql.PreparedStatement JavaDoc;
30 import java.sql.SQLException JavaDoc;
31 import java.sql.SQLWarning JavaDoc;
32 import java.sql.Statement JavaDoc;
33 import java.util.Map JavaDoc;
34
35 /**
36  * This is an implementation of java.sql.Connection which simply
37  * delegates everything to an underlying physical implemention
38  * of the same interface.
39  */

40 public abstract class CoreConnection extends JdbcUtil implements Connection JavaDoc {
41     public Connection JavaDoc con; // the physical database connection
42

43     /**
44      * Constructor
45      */

46     public CoreConnection(Connection JavaDoc con) {
47         this.con = con;
48     }
49
50     public CoreConnection() {
51     }
52
53     public void clearWarnings() throws SQLException JavaDoc {
54         preInvoke();
55         try {
56             con.clearWarnings();
57         } catch (SQLException JavaDoc e) {
58             catchInvoke(e);
59         }
60     }
61
62     public void close() throws SQLException JavaDoc {
63         preInvoke();
64         try {
65             con.close();
66         } catch (SQLException JavaDoc e) {
67             catchInvoke(e);
68         }
69     }
70
71     public void commit() throws SQLException JavaDoc {
72         preInvoke();
73         try {
74             con.commit();
75         } catch (SQLException JavaDoc e) {
76             catchInvoke(e);
77         }
78     }
79
80     public Statement JavaDoc createStatement() throws SQLException JavaDoc {
81         preInvoke();
82         try {
83             return con.createStatement();
84         } catch (SQLException JavaDoc e) {
85             catchInvoke(e);
86         }
87         return null;
88     }
89
90     public Statement JavaDoc createStatement(
91         int resultSetType,
92         int resultSetConcurrency)
93         throws SQLException JavaDoc {
94         preInvoke();
95         try {
96             return con.createStatement(resultSetType, resultSetConcurrency);
97         } catch (SQLException JavaDoc e) {
98             catchInvoke(e);
99         }
100         return null;
101     }
102
103     public boolean getAutoCommit() throws SQLException JavaDoc {
104         preInvoke();
105         try {
106             return con.getAutoCommit();
107         } catch (SQLException JavaDoc e) {
108             catchInvoke(e);
109         }
110         return false;
111     }
112
113     public String JavaDoc getCatalog() throws SQLException JavaDoc {
114         preInvoke();
115         try {
116             return con.getCatalog();
117         } catch (SQLException JavaDoc e) {
118             catchInvoke(e);
119         }
120         return null;
121     }
122
123     public DatabaseMetaData JavaDoc getMetaData() throws SQLException JavaDoc {
124         preInvoke();
125         try {
126             return con.getMetaData();
127         } catch (SQLException JavaDoc e) {
128             catchInvoke(e);
129         }
130         return null;
131     }
132
133     public int getTransactionIsolation() throws SQLException JavaDoc {
134         preInvoke();
135         try {
136             return con.getTransactionIsolation();
137         } catch (SQLException JavaDoc e) {
138             catchInvoke(e);
139         }
140         return 0;
141     }
142
143     public Map JavaDoc getTypeMap() throws SQLException JavaDoc {
144         preInvoke();
145         try {
146             return con.getTypeMap();
147         } catch (SQLException JavaDoc e) {
148             catchInvoke(e);
149         }
150         return null;
151     }
152
153     public SQLWarning JavaDoc getWarnings() throws SQLException JavaDoc {
154         preInvoke();
155         try {
156             return con.getWarnings();
157         } catch (SQLException JavaDoc e) {
158             catchInvoke(e);
159         }
160         return null;
161     }
162
163     public boolean isReadOnly() throws SQLException JavaDoc {
164         preInvoke();
165         try {
166             return con.isReadOnly();
167         } catch (SQLException JavaDoc e) {
168             catchInvoke(e);
169         }
170         return false;
171     }
172
173     public String JavaDoc nativeSQL(String JavaDoc sql) throws SQLException JavaDoc {
174         preInvoke();
175         try {
176             return con.nativeSQL(sql);
177         } catch (SQLException JavaDoc e) {
178             catchInvoke(e);
179         }
180         return null;
181     }
182
183     public CallableStatement JavaDoc prepareCall(String JavaDoc sql) throws SQLException JavaDoc {
184         preInvoke();
185         try {
186             return con.prepareCall(sql);
187         } catch (SQLException JavaDoc e) {
188             catchInvoke(e);
189         }
190         return null;
191     }
192
193     public PreparedStatement JavaDoc prepareStatement(String JavaDoc sql) throws SQLException JavaDoc {
194         preInvoke();
195         try {
196             return con.prepareStatement(sql);
197         } catch (SQLException JavaDoc e) {
198             catchInvoke(e);
199         }
200         return null;
201     }
202
203     public PreparedStatement JavaDoc prepareStatement(
204         String JavaDoc sql,
205         int resultSetType,
206         int resultSetConcurrency)
207         throws SQLException JavaDoc {
208         preInvoke();
209         try {
210             return con.prepareStatement(
211                 sql,
212                 resultSetType,
213                 resultSetConcurrency);
214         } catch (SQLException JavaDoc e) {
215             catchInvoke(e);
216         }
217         return null;
218     }
219
220     public void rollback() throws SQLException JavaDoc {
221         preInvoke();
222         try {
223             con.rollback();
224         } catch (SQLException JavaDoc e) {
225             catchInvoke(e);
226         }
227     }
228
229     public void setAutoCommit(boolean autoCommit) throws SQLException JavaDoc {
230         log.debug("CoreConnection:Setautocommit autoCommit was = " + con.getAutoCommit());
231         log.debug("CoreConnection:Setautocommit = " + autoCommit);
232         preInvoke();
233         try {
234             con.setAutoCommit(autoCommit);
235         } catch (SQLException JavaDoc e) {
236             catchInvoke(e);
237         }
238     }
239
240     public void setCatalog(String JavaDoc catalog) throws SQLException JavaDoc {
241         preInvoke();
242         try {
243             con.setCatalog(catalog);
244         } catch (SQLException JavaDoc e) {
245             catchInvoke(e);
246         }
247     }
248
249     public void setReadOnly(boolean readOnly) throws SQLException JavaDoc {
250         preInvoke();
251         try {
252             con.setReadOnly(readOnly);
253         } catch (SQLException JavaDoc e) {
254             catchInvoke(e);
255         }
256     }
257
258     public void setTransactionIsolation(int level) throws SQLException JavaDoc {
259         preInvoke();
260         try {
261             con.setTransactionIsolation(level);
262         } catch (SQLException JavaDoc e) {
263             catchInvoke(e);
264         }
265     }
266
267     public void setTypeMap(Map JavaDoc map) throws SQLException JavaDoc {
268         preInvoke();
269         try {
270             con.setTypeMap(map);
271         } catch (SQLException JavaDoc e) {
272             catchInvoke(e);
273         }
274     }
275
276     /*
277     * Add those following methods to compile on JDK 1.4.
278     * Instead those methods are defined in the java.sql.Connection interface
279     * only since JDK 1.4.
280     */

281     public Statement JavaDoc createStatement(
282         int resultSetType,
283         int resultSetConcurrency,
284         int resultSetHoldability)
285         throws SQLException JavaDoc {
286         preInvoke();
287         try {
288          return con.createStatement(resultSetType,resultSetConcurrency,resultSetHoldability);
289         } catch (SQLException JavaDoc e) {
290             catchInvoke(e);
291         }
292       return null;
293     }
294     public int getHoldability() throws SQLException JavaDoc {
295         preInvoke();
296         try {
297             return con.getHoldability();
298         } catch (SQLException JavaDoc e) {
299             catchInvoke(e);
300         }
301       return 0;
302     }
303     public CallableStatement JavaDoc prepareCall(
304         String JavaDoc sql,
305         int resultSetType,
306         int resultSetConcurrency,
307         int resultSetHoldability)
308         throws SQLException JavaDoc {
309         preInvoke();
310         try {
311          return con.prepareCall(sql,resultSetType,resultSetConcurrency,resultSetHoldability);
312         } catch (SQLException JavaDoc e) {
313             catchInvoke(e);
314         }
315       return null;
316     }
317     public PreparedStatement JavaDoc prepareStatement(
318         String JavaDoc sql,
319         int autoGeneratedKeys)
320         throws SQLException JavaDoc {
321         preInvoke();
322         try {
323             return con.prepareStatement(sql,autoGeneratedKeys);
324         } catch (SQLException JavaDoc e) {
325             catchInvoke(e);
326         }
327       return null;
328     }
329     public PreparedStatement JavaDoc prepareStatement(
330         String JavaDoc sql,
331         int resultSetType,
332         int resultSetConcurrency,
333         int resultSetHoldability)
334         throws SQLException JavaDoc {
335       preInvoke();
336         try {
337          return prepareStatement(sql,resultSetType,resultSetConcurrency,resultSetHoldability);
338         } catch (SQLException JavaDoc e) {
339             catchInvoke(e);
340         }
341       return null;
342     }
343     public PreparedStatement JavaDoc prepareStatement(String JavaDoc sql, int[] columnIndexes)
344         throws SQLException JavaDoc {
345         preInvoke();
346         try {
347          return con.prepareStatement(sql,columnIndexes);
348         } catch (SQLException JavaDoc e) {
349             catchInvoke(e);
350         }
351       return null;
352     }
353     public PreparedStatement JavaDoc prepareStatement(String JavaDoc sql, String JavaDoc[] columnNames)
354         throws SQLException JavaDoc {
355         preInvoke();
356         try {
357          return con.prepareStatement(sql,columnNames);
358         } catch (SQLException JavaDoc e) {
359             catchInvoke(e);
360         }
361       return null;
362     }
363     public void releaseSavepoint(java.sql.Savepoint JavaDoc savepoint)
364         throws SQLException JavaDoc {
365         preInvoke();
366         try {
367          con.releaseSavepoint(savepoint);
368         } catch (SQLException JavaDoc e) {
369             catchInvoke(e);
370         }
371          
372     }
373     public void rollback(java.sql.Savepoint JavaDoc savepoint) throws SQLException JavaDoc {
374         preInvoke();
375         try {
376          con.rollback(savepoint);
377         } catch (SQLException JavaDoc e) {
378             catchInvoke(e);
379         }
380     }
381     public void setHoldability(int holdability) throws SQLException JavaDoc {
382         preInvoke();
383         try {
384          con.setHoldability(holdability);
385         } catch (SQLException JavaDoc e) {
386             catchInvoke(e);
387         }
388       
389     }
390     public java.sql.Savepoint JavaDoc setSavepoint() throws SQLException JavaDoc {
391         preInvoke();
392         try {
393          return con.setSavepoint();
394         } catch (SQLException JavaDoc e) {
395             catchInvoke(e);
396         }
397       return null;
398     }
399     public java.sql.Savepoint JavaDoc setSavepoint(String JavaDoc name) throws SQLException JavaDoc {
400         preInvoke();
401         try {
402          return con.setSavepoint(name);
403         } catch (SQLException JavaDoc e) {
404             catchInvoke(e);
405         }
406       return null;
407     }
408
409     /**
410      * Methods used to do some works before and during the catch
411      * clause, to prevent the pool that a connection is broken.
412      */

413     abstract public void preInvoke() throws SQLException JavaDoc;
414     abstract public void catchInvoke(SQLException JavaDoc e) throws SQLException JavaDoc;
415
416 }
417
Popular Tags