001: /*
002: DBPool - JDBC Connection Pool Manager
003: Copyright (c) Giles Winstanley
004: */
005: package snaq.db;
006:
007: import java.math.*;
008: import java.net.*;
009: import java.sql.*;
010: import java.util.Calendar;
011: import java.io.InputStream;
012: import java.io.Reader;
013:
014: /**
015: * PreparedStatement wrapper that provides caching support.
016: * @author Giles Winstanley
017: */
018: public class CachedPreparedStatement extends CachedStatement implements
019: PreparedStatement {
020: protected String sql;
021:
022: /**
023: * Creates a new CachedPreparedStatement object, using the supplied PreparedStatement.
024: */
025: public CachedPreparedStatement(String sql, PreparedStatement st) {
026: super (st);
027: this .sql = sql;
028: }
029:
030: String getSQLString() {
031: return sql;
032: }
033:
034: public String toString() {
035: StringBuffer sb = new StringBuffer();
036: sb.append(super .toString());
037: sb.append(" [");
038: sb.append(sql);
039: sb.append(',');
040: sb.append(getParametersString());
041: sb.append("]");
042: return sb.toString();
043: }
044:
045: /**
046: * Overridden to add PreparedStatement specific code.
047: */
048: public void recycle() throws SQLException {
049: super .recycle();
050: PreparedStatement ps = (PreparedStatement) st;
051:
052: try {
053: ps.clearParameters();
054: } catch (NullPointerException npe) {
055: } // Catch clearParameters() bug in Java when no parameters
056: catch (SQLException sqle) {
057: } // Caught to fix bug in some drivers
058: }
059:
060: /**
061: * Overridden to provide caching support.
062: */
063: public void release() throws SQLException {
064: st.close();
065: }
066:
067: //*************************************
068: // PreparedStatement interface methods
069: //*************************************
070:
071: public ResultSet executeQuery() throws SQLException {
072: return ((PreparedStatement) st).executeQuery();
073: }
074:
075: public int executeUpdate() throws SQLException {
076: return ((PreparedStatement) st).executeUpdate();
077: }
078:
079: public void setNull(int parameterIndex, int sqlType)
080: throws SQLException {
081: ((PreparedStatement) st).setNull(parameterIndex, sqlType);
082: }
083:
084: public void setBoolean(int parameterIndex, boolean x)
085: throws SQLException {
086: ((PreparedStatement) st).setBoolean(parameterIndex, x);
087: }
088:
089: public void setByte(int parameterIndex, byte x) throws SQLException {
090: ((PreparedStatement) st).setByte(parameterIndex, x);
091: }
092:
093: public void setShort(int parameterIndex, short x)
094: throws SQLException {
095: ((PreparedStatement) st).setShort(parameterIndex, x);
096: }
097:
098: public void setInt(int parameterIndex, int x) throws SQLException {
099: ((PreparedStatement) st).setInt(parameterIndex, x);
100: }
101:
102: public void setLong(int parameterIndex, long x) throws SQLException {
103: ((PreparedStatement) st).setLong(parameterIndex, x);
104: }
105:
106: public void setFloat(int parameterIndex, float x)
107: throws SQLException {
108: ((PreparedStatement) st).setFloat(parameterIndex, x);
109: }
110:
111: public void setDouble(int parameterIndex, double x)
112: throws SQLException {
113: ((PreparedStatement) st).setDouble(parameterIndex, x);
114: }
115:
116: public void setBigDecimal(int parameterIndex, BigDecimal x)
117: throws SQLException {
118: ((PreparedStatement) st).setBigDecimal(parameterIndex, x);
119: }
120:
121: public void setString(int parameterIndex, String x)
122: throws SQLException {
123: ((PreparedStatement) st).setString(parameterIndex, x);
124: }
125:
126: public void setBytes(int parameterIndex, byte[] x)
127: throws SQLException {
128: ((PreparedStatement) st).setBytes(parameterIndex, x);
129: }
130:
131: public void setDate(int parameterIndex, Date x) throws SQLException {
132: ((PreparedStatement) st).setDate(parameterIndex, x);
133: }
134:
135: public void setTime(int parameterIndex, Time x) throws SQLException {
136: ((PreparedStatement) st).setTime(parameterIndex, x);
137: }
138:
139: public void setTimestamp(int parameterIndex, Timestamp x)
140: throws SQLException {
141: ((PreparedStatement) st).setTimestamp(parameterIndex, x);
142: }
143:
144: public void setAsciiStream(int parameterIndex, InputStream x,
145: int length) throws SQLException {
146: ((PreparedStatement) st).setAsciiStream(parameterIndex, x,
147: length);
148: }
149:
150: public void setUnicodeStream(int parameterIndex, InputStream x,
151: int length) throws SQLException {
152: ((PreparedStatement) st).setUnicodeStream(parameterIndex, x,
153: length);
154: }
155:
156: public void setBinaryStream(int parameterIndex, InputStream x,
157: int length) throws SQLException {
158: ((PreparedStatement) st).setBinaryStream(parameterIndex, x,
159: length);
160: }
161:
162: public void clearParameters() throws SQLException {
163: ((PreparedStatement) st).clearParameters();
164: }
165:
166: public void setObject(int parameterIndex, Object x,
167: int targetSqlType, int scale) throws SQLException {
168: ((PreparedStatement) st).setObject(parameterIndex, x,
169: targetSqlType, scale);
170: }
171:
172: public void setObject(int parameterIndex, Object x,
173: int targetSqlType) throws SQLException {
174: ((PreparedStatement) st).setObject(parameterIndex, x,
175: targetSqlType);
176: }
177:
178: public void setObject(int parameterIndex, Object x)
179: throws SQLException {
180: ((PreparedStatement) st).setObject(parameterIndex, x);
181: }
182:
183: public boolean execute() throws SQLException {
184: return ((PreparedStatement) st).execute();
185: }
186:
187: public void addBatch() throws SQLException {
188: ((PreparedStatement) st).addBatch();
189: }
190:
191: public void setCharacterStream(int parameterIndex, Reader reader,
192: int length) throws SQLException {
193: ((PreparedStatement) st).setCharacterStream(parameterIndex,
194: reader, length);
195: }
196:
197: public void setRef(int i, Ref x) throws SQLException {
198: ((PreparedStatement) st).setRef(i, x);
199: }
200:
201: public void setBlob(int i, Blob x) throws SQLException {
202: ((PreparedStatement) st).setBlob(i, x);
203: }
204:
205: public void setClob(int i, Clob x) throws SQLException {
206: ((PreparedStatement) st).setClob(i, x);
207: }
208:
209: public void setArray(int i, Array x) throws SQLException {
210: ((PreparedStatement) st).setArray(i, x);
211: }
212:
213: public ResultSetMetaData getMetaData() throws SQLException {
214: return ((PreparedStatement) st).getMetaData();
215: }
216:
217: public void setDate(int parameterIndex, Date x, Calendar cal)
218: throws SQLException {
219: ((PreparedStatement) st).setDate(parameterIndex, x, cal);
220: }
221:
222: public void setTime(int parameterIndex, Time x, Calendar cal)
223: throws SQLException {
224: ((PreparedStatement) st).setTime(parameterIndex, x, cal);
225: }
226:
227: public void setTimestamp(int parameterIndex, Timestamp x,
228: Calendar cal) throws SQLException {
229: ((PreparedStatement) st).setTimestamp(parameterIndex, x, cal);
230: }
231:
232: public void setNull(int paramIndex, int sqlType, String typeName)
233: throws SQLException {
234: ((PreparedStatement) st).setNull(paramIndex, sqlType, typeName);
235: }
236:
237: //**********************************
238: // Interface methods from JDBC 3.0
239: //**********************************
240:
241: public ParameterMetaData getParameterMetaData() throws SQLException {
242: return ((PreparedStatement) st).getParameterMetaData();
243: }
244:
245: public void setURL(int parameterIndex, URL x) throws SQLException {
246: ((PreparedStatement) st).setURL(parameterIndex, x);
247: }
248: }
|