001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.visualweb.dataconnectivity.sql;
042:
043: import java.sql.Array;
044: import java.sql.Blob;
045: import java.sql.Clob;
046: import java.sql.CallableStatement;
047: import java.sql.Connection;
048: import java.sql.DatabaseMetaData;
049: import java.sql.PreparedStatement;
050: import java.sql.Savepoint;
051: import java.sql.Statement;
052: import java.sql.SQLException;
053: import java.sql.SQLWarning;
054: import java.sql.Struct;
055:
056: import java.util.Locale;
057: import java.util.Map;
058: import java.util.Properties;
059: import java.util.ResourceBundle;
060:
061: // Added in Java 1.6
062: import java.sql.NClob;
063: import java.sql.SQLXML;
064: import java.sql.SQLClientInfoException;
065:
066: /**
067: * A design time only wrapper class for Connection objects. Used to
068: * facilitate logging and to make design time connection pooling
069: * possible in the future. Use getWrappedConnection() to get the
070: * underlying Connection object.
071: *
072: * @author John Kline
073: */
074: public class DesignTimeConnection implements Connection {
075:
076: protected static ResourceBundle rb = ResourceBundle
077: .getBundle(
078: "org.netbeans.modules.visualweb.dataconnectivity.sql.Bundle", //NOI18N
079: Locale.getDefault());
080:
081: static private int nextId = 0;
082:
083: private int id;
084: private Connection wrappedConnection;
085: private String url;
086: private String driverClassName;
087: private String username;
088:
089: public DesignTimeConnection(DesignTimeDataSource dataSource,
090: Connection wrappedConnection) {
091: id = getNextId();
092: Log.getLogger().entering(getClass().getName(),
093: "DesignTimeConnection(" + id + ")",//NOI18N
094: new Object[] { dataSource, wrappedConnection });
095: // if (Log.getLogger().getLevel() == java.util.logging.Level.FINEST) {
096: // Thread.currentThread().dumpStack();
097: // }
098: this .wrappedConnection = wrappedConnection;
099: driverClassName = dataSource.getDriverClassName();
100: url = dataSource.getUrl();
101: username = dataSource.getUsername();
102: }
103:
104: public Connection getWrappedConnection() {
105: return wrappedConnection;
106: }
107:
108: private synchronized int getNextId() {
109: return nextId++;
110: }
111:
112: public String toString() {
113: StringBuffer s = new StringBuffer();
114: s.append("DesignTimeConnection("); //NOI18N
115: s.append(id);
116: s.append(',');
117: s.append(wrappedConnection);
118: s.append(',');
119: s.append(driverClassName);
120: s.append(',');
121: s.append(url);
122: s.append(',');
123: s.append(username);
124: s.append(')');
125: return s.toString();
126: }
127:
128: public void clearWarnings() throws SQLException {
129: Log.getLogger().entering(getClass().getName(),
130: toString() + ".clearWarnings()"); //NOI18N
131: wrappedConnection.clearWarnings();
132: }
133:
134: public void close() throws SQLException {
135: Log.getLogger().entering(getClass().getName(),
136: toString() + ".close()"); //NOI18N
137: wrappedConnection.close();
138: }
139:
140: public void commit() throws SQLException {
141: Log.getLogger().entering(getClass().getName(),
142: toString() + ".commit()"); //NOI18N
143: wrappedConnection.commit();
144: }
145:
146: public Statement createStatement() throws SQLException {
147: Log.getLogger().entering(getClass().getName(),
148: toString() + ".createStatement()"); //NOI18N
149: return wrappedConnection.createStatement();
150: }
151:
152: public Statement createStatement(int resultSetType,
153: int resultSetConcurrency) throws SQLException {
154:
155: Log.getLogger().entering(
156: getClass().getName(),
157: toString() + ".createStatement()", //NOI18N
158: new Object[] { new Integer(resultSetType),
159: new Integer(resultSetConcurrency) });
160: return wrappedConnection.createStatement(resultSetType,
161: resultSetConcurrency);
162: }
163:
164: public Statement createStatement(int resultSetType,
165: int resultSetConcurrency, int resultSetHoldability)
166: throws SQLException {
167:
168: Log.getLogger().entering(
169: getClass().getName(),
170: toString() + ".createStatement()", //NOI18N
171: new Object[] { new Integer(resultSetType),
172: new Integer(resultSetConcurrency),
173: new Integer(resultSetHoldability) });
174: return wrappedConnection.createStatement(resultSetType,
175: resultSetConcurrency, resultSetHoldability);
176: }
177:
178: public boolean getAutoCommit() throws SQLException {
179: Log.getLogger().entering(getClass().getName(),
180: toString() + ".getAutoCommit()"); //NOI18N
181: return wrappedConnection.getAutoCommit();
182: }
183:
184: public String getCatalog() throws SQLException {
185: Log.getLogger().entering(getClass().getName(),
186: toString() + ".getCatalog()"); //NOI18N
187: return wrappedConnection.getCatalog();
188: }
189:
190: public int getHoldability() throws SQLException {
191: Log.getLogger().entering(getClass().getName(),
192: toString() + ".getHoldability()"); //NOI18N
193: return wrappedConnection.getHoldability();
194: }
195:
196: public DatabaseMetaData getMetaData() throws SQLException {
197: Log.getLogger().entering(getClass().getName(),
198: toString() + ".getMetaData()"); //NOI18N
199: return wrappedConnection.getMetaData();
200: }
201:
202: public int getTransactionIsolation() throws SQLException {
203: Log.getLogger().entering(getClass().getName(),
204: toString() + ".getTransactionIsolation()"); //NOI18N
205: return wrappedConnection.getTransactionIsolation();
206: }
207:
208: public Map getTypeMap() throws SQLException {
209: Log.getLogger().entering(getClass().getName(),
210: toString() + ".getTypeMap()"); //NOI18N
211: return wrappedConnection.getTypeMap();
212: }
213:
214: public SQLWarning getWarnings() throws SQLException {
215: Log.getLogger().entering(getClass().getName(),
216: toString() + ".getWarnings()"); //NOI18N
217: return wrappedConnection.getWarnings();
218: }
219:
220: public boolean isClosed() throws SQLException {
221: Log.getLogger().entering(getClass().getName(),
222: toString() + ".isClosed()"); //NOI18N
223: return wrappedConnection.isClosed();
224: }
225:
226: public boolean isReadOnly() throws SQLException {
227: Log.getLogger().entering(getClass().getName(),
228: toString() + ".isReadOnly()"); //NOI18N
229: return wrappedConnection.isReadOnly();
230: }
231:
232: public String nativeSQL(String sql) throws SQLException {
233: Log.getLogger().entering(getClass().getName(),
234: toString() + ".nativeSQL()", sql); //NOI18N
235: return wrappedConnection.nativeSQL(sql);
236: }
237:
238: public CallableStatement prepareCall(String sql)
239: throws SQLException {
240: Log.getLogger().entering(getClass().getName(),
241: toString() + ".prepareCall()", sql); //NOI18N
242: return wrappedConnection.prepareCall(sql);
243: }
244:
245: public CallableStatement prepareCall(String sql, int resultSetType,
246: int resultSetConcurrency) throws SQLException {
247:
248: Log.getLogger().entering(
249: getClass().getName(),
250: toString() + ".prepareCall()",
251: new Object[] //NOI18N
252: { sql, new Integer(resultSetType),
253: new Integer(resultSetConcurrency) });
254: return wrappedConnection.prepareCall(sql, resultSetType,
255: resultSetConcurrency);
256: }
257:
258: public CallableStatement prepareCall(String sql, int resultSetType,
259: int resultSetConcurrency, int resultSetHoldability)
260: throws SQLException {
261:
262: Log.getLogger().entering(
263: getClass().getName(),
264: toString() + ".prepareCall()",
265: new Object[] //NOI18N
266: { sql, new Integer(resultSetType),
267: new Integer(resultSetConcurrency),
268: new Integer(resultSetHoldability) });
269: return wrappedConnection.prepareCall(sql, resultSetType,
270: resultSetConcurrency, resultSetHoldability);
271: }
272:
273: public PreparedStatement prepareStatement(String sql)
274: throws SQLException {
275: Log.getLogger().entering(getClass().getName(),
276: toString() + ".prepareStatement()", sql); //NOI18N
277: return wrappedConnection.prepareStatement(sql);
278: }
279:
280: public PreparedStatement prepareStatement(String sql,
281: int autoGeneratedKeys) throws SQLException {
282:
283: Log.getLogger().entering(getClass().getName(),
284: toString() + ".prepareStatement()", //NOI18N
285: new Object[] { sql, new Integer(autoGeneratedKeys) });
286: return wrappedConnection.prepareStatement(sql,
287: autoGeneratedKeys);
288: }
289:
290: public PreparedStatement prepareStatement(String sql,
291: int[] columnIndexes) throws SQLException {
292: Log.getLogger().entering(getClass().getName(),
293: toString() + ".prepareStatement()", //NOI18N
294: new Object[] { sql, columnIndexes });
295: return wrappedConnection.prepareStatement(sql, columnIndexes);
296: }
297:
298: public PreparedStatement prepareStatement(String sql,
299: int resultSetType, int resultSetConcurrency)
300: throws SQLException {
301:
302: Log.getLogger().entering(
303: getClass().getName(),
304: toString() + ".prepareStatement()", //NOI18N
305: new Object[] { sql, new Integer(resultSetType),
306: new Integer(resultSetConcurrency) });
307: return wrappedConnection.prepareStatement(sql, resultSetType,
308: resultSetConcurrency);
309: }
310:
311: public PreparedStatement prepareStatement(String sql,
312: int resultSetType, int resultSetConcurrency,
313: int resultSetHoldability) throws SQLException {
314:
315: Log.getLogger().entering(
316: getClass().getName(),
317: toString() + ".prepareStatement()", //NOI18N
318: new Object[] { sql, new Integer(resultSetType),
319: new Integer(resultSetConcurrency),
320: new Integer(resultSetHoldability) });
321: return wrappedConnection.prepareStatement(sql, resultSetType,
322: resultSetConcurrency, resultSetHoldability);
323: }
324:
325: public PreparedStatement prepareStatement(String sql,
326: String[] columnNames) throws SQLException {
327:
328: Log.getLogger().entering(getClass().getName(),
329: toString() + ".prepareStatement()", //NOI18N
330: new Object[] { sql, columnNames });
331: return wrappedConnection.prepareStatement(sql, columnNames);
332: }
333:
334: public void releaseSavepoint(Savepoint savepoint)
335: throws SQLException {
336: Log.getLogger().entering(getClass().getName(),
337: toString() + ".releaseSavepoint()", savepoint); //NOI18N
338: wrappedConnection.releaseSavepoint(savepoint);
339: }
340:
341: public void rollback() throws SQLException {
342: Log.getLogger().entering(getClass().getName(),
343: toString() + ".rollback()"); //NOI18N
344: wrappedConnection.rollback();
345: }
346:
347: public void rollback(Savepoint savepoint) throws SQLException {
348: Log.getLogger().entering(getClass().getName(),
349: toString() + ".rollback()", savepoint); //NOI18N
350: wrappedConnection.rollback(savepoint);
351: }
352:
353: public void setAutoCommit(boolean autoCommit) throws SQLException {
354: Log.getLogger().entering(getClass().getName(),
355: toString() + ".setAutoCommit()", //NOI18N
356: new Boolean(autoCommit));
357: wrappedConnection.setAutoCommit(autoCommit);
358: }
359:
360: public void setCatalog(String catalog) throws SQLException {
361: Log.getLogger().entering(getClass().getName(),
362: toString() + ".setCatalog()", catalog); //NOI18N
363: wrappedConnection.setCatalog(catalog);
364: }
365:
366: public void setHoldability(int holdability) throws SQLException {
367: Log.getLogger().entering(getClass().getName(),
368: toString() + ".setHoldability()", //NOI18N
369: new Integer(holdability));
370: wrappedConnection.setHoldability(holdability);
371: }
372:
373: public void setReadOnly(boolean readOnly) throws SQLException {
374: Log.getLogger().entering(getClass().getName(),
375: toString() + ".setReadOnly()", //NOI18N
376: new Boolean(readOnly));
377: wrappedConnection.setReadOnly(readOnly);
378: }
379:
380: public Savepoint setSavepoint() throws SQLException {
381: Log.getLogger().entering(getClass().getName(),
382: toString() + ".setSavepoint()"); //NOI18N
383: return wrappedConnection.setSavepoint();
384: }
385:
386: public Savepoint setSavepoint(String name) throws SQLException {
387: Log.getLogger().entering(getClass().getName(),
388: toString() + ".setSavepoint()", name); //NOI18N
389: return wrappedConnection.setSavepoint(name);
390: }
391:
392: public void setTransactionIsolation(int level) throws SQLException {
393: Log.getLogger().entering(getClass().getName(),
394: toString() + ".setTransactionIsolation()", //NOI18N
395: new Integer(level));
396: wrappedConnection.setTransactionIsolation(level);
397: }
398:
399: public void setTypeMap(Map map) throws SQLException {
400: Log.getLogger().entering(getClass().getName(),
401: toString() + ".setTypeMap()", map); //NOI18N
402: wrappedConnection.setTypeMap(map);
403: }
404:
405: // Methods added for compliance with Java 1.6
406:
407: public Clob createClob() throws SQLException {
408: Log.getLogger().entering(getClass().getName(),
409: toString() + ".createClob()"); //NOI18N
410: throw new RuntimeException(rb.getString("NOT_IMPLEMENTED"));
411: }
412:
413: public Blob createBlob() throws SQLException {
414: Log.getLogger().entering(getClass().getName(),
415: toString() + ".createBlob()"); //NOI18N
416: throw new RuntimeException(rb.getString("NOT_IMPLEMENTED"));
417: }
418:
419: public NClob createNClob() throws SQLException {
420: Log.getLogger().entering(getClass().getName(),
421: toString() + ".createNClob()"); //NOI18N
422: throw new RuntimeException(rb.getString("NOT_IMPLEMENTED"));
423: }
424:
425: public SQLXML createSQLXML() throws SQLException {
426: Log.getLogger().entering(getClass().getName(),
427: toString() + ".createSQLXML()"); //NOI18N
428: throw new RuntimeException(rb.getString("NOT_IMPLEMENTED"));
429: }
430:
431: public boolean isValid(int timeout) throws SQLException {
432: Log.getLogger().entering(getClass().getName(),
433: toString() + ".isValid()", timeout); //NOI18N
434: throw new RuntimeException(rb.getString("NOT_IMPLEMENTED"));
435: }
436:
437: public void setClientInfo(String name, String value)
438: throws SQLClientInfoException {
439: Log.getLogger().entering(getClass().getName(),
440: toString() + ".setClientInfo()",
441: new Object[] { name, value }); //NOI18N
442: throw new RuntimeException(rb.getString("NOT_IMPLEMENTED"));
443: }
444:
445: public void setClientInfo(Properties properties)
446: throws SQLClientInfoException {
447: Log.getLogger().entering(getClass().getName(),
448: toString() + ".setClientInfo()", properties); //NOI18N
449: throw new RuntimeException(rb.getString("NOT_IMPLEMENTED"));
450: }
451:
452: public String getClientInfo(String name) throws SQLException {
453: Log.getLogger().entering(getClass().getName(),
454: toString() + ".getClientInfo()", name); //NOI18N
455: throw new RuntimeException(rb.getString("NOT_IMPLEMENTED"));
456: }
457:
458: public Properties getClientInfo() throws SQLException {
459: Log.getLogger().entering(getClass().getName(),
460: toString() + ".getClientInfo()"); //NOI18N
461: throw new RuntimeException(rb.getString("NOT_IMPLEMENTED"));
462: }
463:
464: public Array createArrayOf(String typeName, Object[] elements)
465: throws SQLException {
466: Log.getLogger().entering(getClass().getName(),
467: toString() + ".createArrayOf()",
468: new Object[] { typeName, elements }); //NOI18N
469: throw new RuntimeException(rb.getString("NOT_IMPLEMENTED"));
470: }
471:
472: public Struct createStruct(String typeName, Object[] attributes)
473: throws SQLException {
474: Log.getLogger().entering(getClass().getName(),
475: toString() + ".createStruct()",
476: new Object[] { typeName, attributes }); //NOI18N
477: throw new RuntimeException(rb.getString("NOT_IMPLEMENTED"));
478: }
479:
480: public boolean isWrapperFor(Class iface) throws SQLException {
481: Log.getLogger().entering(getClass().getName(),
482: toString() + ".isWrapperFor()", iface); //NOI18N
483: throw new RuntimeException(rb.getString("NOT_IMPLEMENTED"));
484: }
485:
486: public Object unwrap(Class iface) throws SQLException {
487: Log.getLogger().entering(getClass().getName(),
488: toString() + ".unwrap()", iface); //NOI18N
489: throw new RuntimeException(rb.getString("NOT_IMPLEMENTED"));
490: }
491: }
|