001: /*
002:
003: This software is OSI Certified Open Source Software.
004: OSI Certified is a certification mark of the Open Source Initiative.
005:
006: The license (Mozilla version 1.0) can be read at the MMBase site.
007: See http://www.MMBase.org/license
008:
009: */
010: package org.mmbase.module.database;
011:
012: import java.sql.*;
013: import java.util.*;
014:
015: /**
016: * Wraps a java.sql.Connection object. Extending this makes it possible to intercept calls.
017: *
018: * @author Michiel Meeuwissen
019: * @version $Id: ConnectionWrapper.java,v 1.3 2007/06/11 12:29:03 michiel Exp $
020: * @since MMBase-1.8
021: */
022: public abstract class ConnectionWrapper { //implements Connection {
023: /**
024: * The wrapped connection
025: */
026: protected Connection con;
027:
028: public ConnectionWrapper(Connection c) {
029: con = c;
030: }
031:
032: /**
033: * Called just before every prepare statement. Can be overridden, because this default implementation is empty.
034: */
035: protected void setLastSQL(String sql) {
036: }
037:
038: /**
039: * {@inheritDoc}
040: */
041: public Statement createStatement() throws SQLException {
042: return con.createStatement();
043: }
044:
045: /**
046: * {@inheritDoc}
047: */
048: public Statement createStatement(int resultSetType,
049: int resultSetConcurrency) throws SQLException {
050: return con.createStatement(resultSetType, resultSetConcurrency);
051: }
052:
053: /**
054: * {@inheritDoc}
055: */
056: public Statement createStatement(int type, int concurrency,
057: int holdability) throws SQLException {
058: return con.createStatement(type, concurrency, holdability);
059: }
060:
061: /**
062: * {@inheritDoc}
063: */
064: public PreparedStatement prepareStatement(String sql)
065: throws SQLException {
066: setLastSQL(sql);
067: return con.prepareStatement(sql);
068: }
069:
070: /**
071: * {@inheritDoc}
072: */
073: public PreparedStatement prepareStatement(String sql,
074: int autoGeneratedKeys) throws SQLException {
075: setLastSQL(sql);
076: return con.prepareStatement(sql, autoGeneratedKeys);
077: }
078:
079: /**
080: * {@inheritDoc}
081: */
082: public PreparedStatement prepareStatement(String sql,
083: int[] columnIndexes) throws SQLException {
084: setLastSQL(sql);
085: return con.prepareStatement(sql, columnIndexes);
086: }
087:
088: /**
089: * {@inheritDoc}
090: */
091: public PreparedStatement prepareStatement(String sql,
092: String[] columnNames) throws SQLException {
093: setLastSQL(sql);
094: return con.prepareStatement(sql, columnNames);
095: }
096:
097: /**
098: * {@inheritDoc}
099: */
100: public PreparedStatement prepareStatement(String sql, int type,
101: int concurrency, int holdability) throws SQLException {
102: setLastSQL(sql);
103: return con
104: .prepareStatement(sql, type, concurrency, holdability);
105: }
106:
107: /**
108: * {@inheritDoc}
109: */
110: public CallableStatement prepareCall(String sql)
111: throws SQLException {
112: setLastSQL(sql);
113: return con.prepareCall(sql);
114: }
115:
116: /**
117: * {@inheritDoc}
118: */
119: public String nativeSQL(String query) throws SQLException {
120: setLastSQL(query);
121: return con.nativeSQL(query);
122: }
123:
124: /**
125: * {@inheritDoc}
126: */
127: public void setAutoCommit(boolean enableAutoCommit)
128: throws SQLException {
129: con.setAutoCommit(enableAutoCommit);
130: }
131:
132: /**
133: * {@inheritDoc}
134: */
135: public boolean getAutoCommit() throws SQLException {
136: return con.getAutoCommit();
137: }
138:
139: /**
140: * {@inheritDoc}
141: */
142: public void commit() throws SQLException {
143: con.commit();
144: }
145:
146: /**
147: * {@inheritDoc}
148: */
149: public void rollback() throws SQLException {
150: con.rollback();
151: }
152:
153: /**
154: * {@inheritDoc}
155: */
156: public void close() throws SQLException {
157: con.close();
158: }
159:
160: /**
161: * {@inheritDoc}
162: */
163: public boolean isClosed() throws SQLException {
164: return con.isClosed();
165: }
166:
167: /**
168: * {@inheritDoc}
169: */
170: public DatabaseMetaData getMetaData() throws SQLException {
171: return con.getMetaData();
172: }
173:
174: /**
175: * {@inheritDoc}
176: */
177: public void setReadOnly(boolean readOnly) throws SQLException {
178: con.setReadOnly(readOnly);
179: }
180:
181: /**
182: * {@inheritDoc}
183: */
184: public boolean isReadOnly() throws SQLException {
185: return con.isReadOnly();
186: }
187:
188: /**
189: * {@inheritDoc}
190: */
191: public void setCatalog(String catalog) throws SQLException {
192: con.setCatalog(catalog);
193: }
194:
195: /**
196: * {@inheritDoc}
197: */
198: public String getCatalog() throws SQLException {
199: return con.getCatalog();
200: }
201:
202: /**
203: * {@inheritDoc}
204: */
205: public void setTransactionIsolation(int level) throws SQLException {
206: con.setTransactionIsolation(level);
207: }
208:
209: /**
210: * {@inheritDoc}
211: */
212: public int getTransactionIsolation() throws SQLException {
213: return con.getTransactionIsolation();
214: }
215:
216: /**
217: * {@inheritDoc}
218: */
219: public SQLWarning getWarnings() throws SQLException {
220: return con.getWarnings();
221: }
222:
223: /**
224: * clear Warnings
225: */
226: /**
227: * {@inheritDoc}
228: */
229: public void clearWarnings() throws SQLException {
230: con.clearWarnings();
231: }
232:
233: /**
234: * {@inheritDoc}
235: */
236: public CallableStatement prepareCall(String sql, int i, int y)
237: throws SQLException {
238: setLastSQL(sql);
239: return con.prepareCall(sql, i, y);
240: }
241:
242: /**
243: * {@inheritDoc}
244: */
245: public void setTypeMap(Map mp) throws SQLException {
246: con.setTypeMap(mp);
247: }
248:
249: /**
250: * {@inheritDoc}
251: */
252: public Map getTypeMap() throws SQLException {
253: return con.getTypeMap();
254: }
255:
256: /**
257: * {@inheritDoc}
258: */
259: public PreparedStatement prepareStatement(String sql, int i, int y)
260: throws SQLException {
261: setLastSQL(sql);
262: return con.prepareStatement(sql, i, y);
263: }
264:
265: /**
266: * {@inheritDoc}
267: */
268: public void setHoldability(int holdability) throws SQLException {
269: con.setHoldability(holdability);
270: }
271:
272: /**
273: * {@inheritDoc}
274: */
275: public int getHoldability() throws SQLException {
276: return con.getHoldability();
277: }
278:
279: /**
280: * {@inheritDoc}
281: */
282: public Savepoint setSavepoint() throws SQLException {
283: return con.setSavepoint();
284: }
285:
286: /**
287: * {@inheritDoc}
288: */
289: public Savepoint setSavepoint(String name) throws SQLException {
290: return con.setSavepoint(name);
291: }
292:
293: /**
294: * {@inheritDoc}
295: */
296: public void rollback(Savepoint savepoint) throws SQLException {
297: con.rollback(savepoint);
298: }
299:
300: /**
301: * {@inheritDoc}
302: */
303: public void releaseSavepoint(Savepoint savepoint)
304: throws SQLException {
305: con.releaseSavepoint(savepoint);
306: }
307:
308: /**
309: * {@inheritDoc}
310: */
311: public CallableStatement prepareCall(String sql, int type,
312: int concurrency, int holdability) throws SQLException {
313: setLastSQL(sql);
314: return con.prepareCall(sql, type, concurrency, holdability);
315: }
316:
317: /*
318: public Clob createClob() throws SQLException {
319: throw new UnsupportedOperationException();
320: }
321: public Blob createBlob() throws SQLException {
322: throw new UnsupportedOperationException();
323: }
324: public NClob createNClob() throws SQLException {
325: throw new UnsupportedOperationException();
326: }
327: public SQLXML createSQLXML() throws SQLException {
328: throw new UnsupportedOperationException();
329: }
330: */
331: public boolean isValid(int i) throws SQLException {
332: throw new UnsupportedOperationException();
333: }
334:
335: /*
336: public void setClientInfo(String name, String value) throws SQLClientInfoException {
337: throw new UnsupportedOperationException();
338: }
339: public void setClientInfo(Properties properties) throws SQLClientInfoException {
340: throw new UnsupportedOperationException();
341: }
342: */
343:
344: public String getClientInfo(String name) throws SQLException {
345: throw new UnsupportedOperationException();
346: }
347:
348: public Properties getClientInfo() throws SQLException {
349: throw new UnsupportedOperationException();
350: }
351:
352: public Array createArrayOf(String typeName, Object[] elements)
353: throws SQLException {
354: throw new UnsupportedOperationException();
355: }
356:
357: public Struct createStruct(String typeName, Object[] attributes)
358: throws SQLException {
359: throw new UnsupportedOperationException();
360: }
361:
362: public <T> T unwrap(Class<T> iface) {
363: return (T) con;
364: }
365:
366: public boolean isWrapperFor(Class<?> iface) {
367: return iface.isAssignableFrom(con.getClass());
368: }
369:
370: }
|