KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > module > database > ConnectionWrapper


1 /*
2
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8
9  */

10 package org.mmbase.module.database;
11
12 import java.sql.*;
13 import java.util.Map JavaDoc;
14
15 /**
16  * Wraps a java.sql.Connection object. Extendsing this makes it possible to intercept calls.
17  *
18  * @author Michiel Meeuwissen
19  * @version $Id: ConnectionWrapper.java,v 1.2 2005/12/24 11:35:45 michiel Exp $
20  * @since MMBase-1.8
21  */

22 public abstract class ConnectionWrapper implements Connection {
23     /**
24      * The wrapped connection
25      */

26     protected Connection con;
27
28     public ConnectionWrapper(Connection c) {
29         con = c;
30     }
31
32     /**
33      * Called just before every prepare statement. Can be overridden, because this default implementation is empty.
34      */

35     protected void setLastSQL(String JavaDoc sql) {
36     }
37     /**
38      * {@inheritDoc}
39      */

40     public Statement createStatement() throws SQLException {
41         return con.createStatement();
42     }
43     /**
44      * {@inheritDoc}
45      */

46     public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException {
47         return con.createStatement(resultSetType, resultSetConcurrency);
48     }
49     /**
50      * {@inheritDoc}
51      */

52     public Statement createStatement(int type, int concurrency, int holdability) throws SQLException {
53         return con.createStatement(type, concurrency, holdability);
54     }
55     /**
56      * {@inheritDoc}
57      */

58     public PreparedStatement prepareStatement(String JavaDoc sql) throws SQLException {
59         setLastSQL(sql);
60         return con.prepareStatement(sql);
61     }
62     /**
63      * {@inheritDoc}
64      */

65     public PreparedStatement prepareStatement(String JavaDoc sql, int autoGeneratedKeys) throws SQLException {
66         setLastSQL(sql);
67         return con.prepareStatement(sql, autoGeneratedKeys);
68     }
69
70     /**
71      * {@inheritDoc}
72      */

73     public PreparedStatement prepareStatement(String JavaDoc sql, int[] columnIndexes) throws SQLException {
74         setLastSQL(sql);
75         return con.prepareStatement(sql, columnIndexes);
76     }
77
78     /**
79      * {@inheritDoc}
80      */

81     public PreparedStatement prepareStatement(String JavaDoc sql, String JavaDoc[] columnNames) throws SQLException {
82         setLastSQL(sql);
83         return con.prepareStatement(sql, columnNames);
84     }
85     /**
86      * {@inheritDoc}
87      */

88     public PreparedStatement prepareStatement(String JavaDoc sql, int type, int concurrency, int holdability) throws SQLException {
89         setLastSQL(sql);
90         return con.prepareStatement(sql, type, concurrency, holdability);
91     }
92
93     /**
94      * {@inheritDoc}
95      */

96     public CallableStatement prepareCall(String JavaDoc sql) throws SQLException {
97         setLastSQL(sql);
98         return con.prepareCall(sql);
99     }
100     /**
101      * {@inheritDoc}
102      */

103     public String JavaDoc nativeSQL(String JavaDoc query) throws SQLException {
104         setLastSQL(query);
105         return con.nativeSQL(query);
106     }
107     /**
108      * {@inheritDoc}
109      */

110     public void setAutoCommit(boolean enableAutoCommit) throws SQLException {
111         con.setAutoCommit(enableAutoCommit);
112     }
113     /**
114      * {@inheritDoc}
115      */

116     public boolean getAutoCommit() throws SQLException {
117         return con.getAutoCommit();
118     }
119     /**
120      * {@inheritDoc}
121      */

122     public void commit() throws SQLException {
123         con.commit();
124     }
125
126     /**
127      * {@inheritDoc}
128      */

129     public void rollback() throws SQLException {
130         con.rollback();
131     }
132     /**
133      * {@inheritDoc}
134      */

135     public void close() throws SQLException {
136         con.close();
137     }
138
139     /**
140      * {@inheritDoc}
141      */

142     public boolean isClosed() throws SQLException {
143         return con.isClosed();
144     }
145
146
147     /**
148      * {@inheritDoc}
149      */

150     public DatabaseMetaData getMetaData() throws SQLException {
151         return con.getMetaData();
152     }
153
154
155     /**
156      * {@inheritDoc}
157      */

158     public void setReadOnly(boolean readOnly) throws SQLException {
159         con.setReadOnly(readOnly);
160     }
161
162     /**
163      * {@inheritDoc}
164      */

165     public boolean isReadOnly() throws SQLException {
166         return con.isReadOnly();
167     }
168     /**
169      * {@inheritDoc}
170      */

171     public void setCatalog(String JavaDoc catalog) throws SQLException {
172         con.setCatalog(catalog);
173     }
174
175     /**
176      * {@inheritDoc}
177      */

178     public String JavaDoc getCatalog() throws SQLException {
179         return con.getCatalog();
180     }
181
182     /**
183      * {@inheritDoc}
184      */

185     public void setTransactionIsolation(int level) throws SQLException {
186         con.setTransactionIsolation(level);
187     }
188
189     /**
190      * {@inheritDoc}
191      */

192     public int getTransactionIsolation() throws SQLException {
193         return con.getTransactionIsolation();
194     }
195
196     /**
197      * {@inheritDoc}
198      */

199     public SQLWarning getWarnings() throws SQLException {
200         return con.getWarnings();
201     }
202
203     /**
204      * clear Warnings
205      */

206     /**
207      * {@inheritDoc}
208      */

209     public void clearWarnings() throws SQLException {
210         con.clearWarnings();
211     }
212
213     /**
214      * {@inheritDoc}
215      */

216     public CallableStatement prepareCall(String JavaDoc sql, int i, int y) throws SQLException {
217         setLastSQL(sql);
218         return con.prepareCall(sql,i,y);
219     }
220
221     /**
222      * {@inheritDoc}
223      */

224     public void setTypeMap(Map JavaDoc mp) throws SQLException {
225         con.setTypeMap(mp);
226     }
227
228     /**
229      * {@inheritDoc}
230      */

231     public Map JavaDoc getTypeMap() throws SQLException {
232         return con.getTypeMap();
233     }
234
235
236     /**
237      * {@inheritDoc}
238      */

239     public PreparedStatement prepareStatement(String JavaDoc sql,int i, int y) throws SQLException {
240         setLastSQL(sql);
241         return con.prepareStatement(sql,i,y);
242     }
243
244     /**
245      * {@inheritDoc}
246      */

247     public void setHoldability(int holdability) throws SQLException {
248         con.setHoldability(holdability);
249     }
250     /**
251      * {@inheritDoc}
252      */

253     public int getHoldability() throws SQLException {
254         return con.getHoldability();
255     }
256
257     /**
258      * {@inheritDoc}
259      */

260     public Savepoint setSavepoint() throws SQLException {
261         return con.setSavepoint();
262     }
263
264     /**
265      * {@inheritDoc}
266      */

267     public Savepoint setSavepoint(String JavaDoc name) throws SQLException {
268         return con.setSavepoint(name);
269     }
270
271     /**
272      * {@inheritDoc}
273      */

274     public void rollback(Savepoint savepoint) throws SQLException {
275         con.rollback(savepoint);
276     }
277     /**
278      * {@inheritDoc}
279      */

280     public void releaseSavepoint(Savepoint savepoint) throws SQLException {
281         con.releaseSavepoint(savepoint);
282     }
283
284
285     /**
286      * {@inheritDoc}
287      */

288     public CallableStatement prepareCall(String JavaDoc sql, int type, int concurrency, int holdability) throws SQLException {
289         setLastSQL(sql);
290         return con.prepareCall(sql, type, concurrency, holdability);
291     }
292
293
294 }
295
296
297
Popular Tags