001: /*
002: * Copyright (c) 1998 - 2005 Versant Corporation
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * Versant Corporation - initial API and implementation
010: */
011: package com.versant.core.jdbc.conn;
012:
013: import java.sql.*;
014:
015: /**
016: * A JDBC Statement wrapped so the last executed SQL can be retrieved. This
017: * is useful to generate good error messages from failures. This is used
018: * in non-performance critical areas e.g. when generating the database
019: * schema.
020: */
021: public final class StatementWithLastSQL implements Statement {
022:
023: private String lastSQL = "";
024: private final Statement statement;
025:
026: public StatementWithLastSQL(Statement statement) {
027: this .statement = statement;
028: }
029:
030: /**
031: * Get the last SQL executed on this Statement or "" if none.
032: */
033: public String getLastSQL() {
034: return lastSQL;
035: }
036:
037: public boolean getMoreResults(int current) throws SQLException {
038: return statement.getMoreResults(current);
039: }
040:
041: public ResultSet getGeneratedKeys() throws SQLException {
042: return statement.getGeneratedKeys();
043: }
044:
045: public int executeUpdate(String sql, int autoGeneratedKeys)
046: throws SQLException {
047: return statement
048: .executeUpdate(lastSQL = sql, autoGeneratedKeys);
049: }
050:
051: public int executeUpdate(String sql, int columnIndexes[])
052: throws SQLException {
053: return statement.executeUpdate(lastSQL = sql, columnIndexes);
054: }
055:
056: public int executeUpdate(String sql, String columnNames[])
057: throws SQLException {
058: return statement.executeUpdate(lastSQL = sql, columnNames);
059: }
060:
061: public boolean execute(String sql, int autoGeneratedKeys)
062: throws SQLException {
063: return statement.execute(lastSQL = sql, autoGeneratedKeys);
064: }
065:
066: public boolean execute(String sql, int columnIndexes[])
067: throws SQLException {
068: return statement.execute(lastSQL = sql, columnIndexes);
069: }
070:
071: public boolean execute(String sql, String columnNames[])
072: throws SQLException {
073: return statement.execute(lastSQL = sql, columnNames);
074: }
075:
076: public int getResultSetHoldability() throws SQLException {
077: return statement.getResultSetHoldability();
078: }
079:
080: public ResultSet executeQuery(String sql) throws SQLException {
081: return statement.executeQuery(lastSQL = sql);
082: }
083:
084: public int executeUpdate(String sql) throws SQLException {
085: return statement.executeUpdate(lastSQL = sql);
086: }
087:
088: public void close() throws SQLException {
089: statement.close();
090: }
091:
092: public int getMaxFieldSize() throws SQLException {
093: return statement.getMaxFieldSize();
094: }
095:
096: public void setMaxFieldSize(int max) throws SQLException {
097: statement.setMaxFieldSize(max);
098: }
099:
100: public int getMaxRows() throws SQLException {
101: return statement.getMaxRows();
102: }
103:
104: public void setMaxRows(int max) throws SQLException {
105: statement.setMaxRows(max);
106: }
107:
108: public void setEscapeProcessing(boolean enable) throws SQLException {
109: statement.setEscapeProcessing(enable);
110: }
111:
112: public int getQueryTimeout() throws SQLException {
113: return statement.getQueryTimeout();
114: }
115:
116: public void setQueryTimeout(int seconds) throws SQLException {
117: statement.setQueryTimeout(seconds);
118: }
119:
120: public void cancel() throws SQLException {
121: statement.cancel();
122: }
123:
124: public SQLWarning getWarnings() throws SQLException {
125: return statement.getWarnings();
126: }
127:
128: public void clearWarnings() throws SQLException {
129: statement.clearWarnings();
130: }
131:
132: public void setCursorName(String name) throws SQLException {
133: statement.setCursorName(name);
134: }
135:
136: public boolean execute(String sql) throws SQLException {
137: return statement.execute(lastSQL = sql);
138: }
139:
140: public ResultSet getResultSet() throws SQLException {
141: return statement.getResultSet();
142: }
143:
144: public int getUpdateCount() throws SQLException {
145: return statement.getUpdateCount();
146: }
147:
148: public boolean getMoreResults() throws SQLException {
149: return statement.getMoreResults();
150: }
151:
152: public void setFetchDirection(int direction) throws SQLException {
153: statement.setFetchDirection(direction);
154: }
155:
156: public int getFetchDirection() throws SQLException {
157: return statement.getFetchDirection();
158: }
159:
160: public void setFetchSize(int rows) throws SQLException {
161: statement.setFetchSize(rows);
162: }
163:
164: public int getFetchSize() throws SQLException {
165: return statement.getFetchSize();
166: }
167:
168: public int getResultSetConcurrency() throws SQLException {
169: return statement.getResultSetConcurrency();
170: }
171:
172: public int getResultSetType() throws SQLException {
173: return statement.getResultSetType();
174: }
175:
176: public void addBatch(String sql) throws SQLException {
177: statement.addBatch(sql);
178: }
179:
180: public void clearBatch() throws SQLException {
181: statement.clearBatch();
182: }
183:
184: public int[] executeBatch() throws SQLException {
185: return statement.executeBatch();
186: }
187:
188: public Connection getConnection() throws SQLException {
189: return statement.getConnection();
190: }
191: }
|