1
2
3
4 package com.github.smokestack.jdbc;
5
6 import static org.hamcrest.MatcherAssert.assertThat;
7
8 import java.io.InputStream;
9 import java.io.Reader;
10 import java.math.BigDecimal;
11 import java.net.URL;
12 import java.sql.Array;
13 import java.sql.Blob;
14 import java.sql.Clob;
15 import java.sql.Date;
16 import java.sql.ParameterMetaData;
17 import java.sql.PreparedStatement;
18 import java.sql.Ref;
19 import java.sql.ResultSet;
20 import java.sql.ResultSetMetaData;
21 import java.sql.SQLException;
22 import java.sql.Time;
23 import java.sql.Timestamp;
24 import java.util.Calendar;
25 import java.util.HashMap;
26 import java.util.Map;
27
28 import org.apache.commons.lang.builder.ReflectionToStringBuilder;
29 import org.apache.commons.lang.builder.ToStringStyle;
30 import org.hamcrest.core.AnyOf;
31 import org.hamcrest.core.IsNot;
32
33 import com.github.smokestack.exception.NotYetImplementedException;
34
35
36
37
38
39 public class MockPreparedStatement extends MockStatement implements PreparedStatement {
40
41 private String sql;
42 private Map<Object,Object> parameters = new HashMap<Object,Object>();
43
44 public MockPreparedStatement(MockConnection connection, String sql) {
45 super(connection);
46 this.sql = sql;
47 }
48
49 public void addBatch() throws SQLException {
50 addBatch("dummy sql");
51 }
52
53 public void clearParameters() throws SQLException {
54 assertThat(mockState, AnyOf.anyOf(IsNot.not(StatementState.CLOSE), IsNot.not(StatementState.AUTOCLOSE)));
55 _clearParameters();
56 parameters.clear();
57 }
58
59 public void _clearParameters() throws SQLException {
60 }
61
62 public boolean execute() throws SQLException {
63 return execute("dummy sql");
64 }
65
66 public ResultSet executeQuery() throws SQLException {
67 return executeQuery("dummy sql");
68 }
69
70 public int executeUpdate() throws SQLException {
71 return executeUpdate("dummy sql");
72 }
73
74 public ResultSetMetaData getMetaData() throws SQLException {
75 assertThat(mockState, AnyOf.anyOf(IsNot.not(StatementState.CLOSE), IsNot.not(StatementState.AUTOCLOSE)));
76 _getMetaData();
77 return null;
78 }
79
80 public ResultSetMetaData _getMetaData() {
81 throw new NotYetImplementedException();
82 }
83
84 public ParameterMetaData getParameterMetaData() throws SQLException {
85 assertThat(mockState, AnyOf.anyOf(IsNot.not(StatementState.CLOSE), IsNot.not(StatementState.AUTOCLOSE)));
86 _getParameterMetaData();
87 return null;
88 }
89
90 public ParameterMetaData _getParameterMetaData() {
91 throw new NotYetImplementedException();
92 }
93
94 public void setArray(int i, Array x) throws SQLException {
95 assertThat(mockState, AnyOf.anyOf(IsNot.not(StatementState.CLOSE), IsNot.not(StatementState.AUTOCLOSE)));
96 _setArray(i, x);
97 this.parameters.put(i, x);
98 }
99
100 public void _setArray(int i, Array x) {
101 }
102
103 public void setAsciiStream(int parameterIndex, InputStream x, int length)
104 throws SQLException {
105 assertThat(mockState, AnyOf.anyOf(IsNot.not(StatementState.CLOSE), IsNot.not(StatementState.AUTOCLOSE)));
106 _setAsciiStream(parameterIndex, x);
107 this.parameters.put(parameterIndex, x);
108 }
109
110 public void _setAsciiStream(int parameterIndex, InputStream x) {
111 }
112
113 public void setBigDecimal(int parameterIndex, BigDecimal x)
114 throws SQLException {
115 assertThat(mockState, AnyOf.anyOf(IsNot.not(StatementState.CLOSE), IsNot.not(StatementState.AUTOCLOSE)));
116 _setBigDecimal(parameterIndex, x);
117 this.parameters.put(parameterIndex, x);
118 }
119
120 public void _setBigDecimal(int parameterIndex, BigDecimal x) {
121 }
122
123 public void setBinaryStream(int parameterIndex, InputStream x, int length)
124 throws SQLException {
125 assertThat(mockState, AnyOf.anyOf(IsNot.not(StatementState.CLOSE), IsNot.not(StatementState.AUTOCLOSE)));
126 throw new NotYetImplementedException();
127 }
128
129 public void setBlob(int i, Blob x) throws SQLException {
130 assertThat(mockState, AnyOf.anyOf(IsNot.not(StatementState.CLOSE), IsNot.not(StatementState.AUTOCLOSE)));
131 _setBlob(i, x);
132 this.parameters.put(i, x);
133 }
134
135 public void _setBlob(int i, Blob x) {
136 }
137
138 public void setBoolean(int parameterIndex, boolean x) throws SQLException {
139 assertThat(mockState, AnyOf.anyOf(IsNot.not(StatementState.CLOSE), IsNot.not(StatementState.AUTOCLOSE)));
140 _setBoolean(parameterIndex, x);
141 this.parameters.put(parameterIndex, x);
142 }
143
144 public void _setBoolean(int parameterIndex, boolean x) {
145 }
146
147 public void setByte(int parameterIndex, byte x) throws SQLException {
148 assertThat(mockState, AnyOf.anyOf(IsNot.not(StatementState.CLOSE), IsNot.not(StatementState.AUTOCLOSE)));
149 _setByte(parameterIndex, x);
150 this.parameters.put(parameterIndex, x);
151 }
152
153 public void _setByte(int parameterIndex, byte x) {
154 }
155
156 public void setBytes(int parameterIndex, byte[] x) throws SQLException {
157 assertThat(mockState, AnyOf.anyOf(IsNot.not(StatementState.CLOSE), IsNot.not(StatementState.AUTOCLOSE)));
158 _setBytes(parameterIndex, x);
159 this.parameters.put(parameterIndex, x);
160 }
161
162 public void _setBytes(int parameterIndex, byte[] x) {
163 }
164
165 public void setCharacterStream(int parameterIndex, Reader reader, int length)
166 throws SQLException {
167 assertThat(mockState, AnyOf.anyOf(IsNot.not(StatementState.CLOSE), IsNot.not(StatementState.AUTOCLOSE)));
168 throw new NotYetImplementedException();
169 }
170
171 public void setClob(int i, Clob x) throws SQLException {
172 assertThat(mockState, AnyOf.anyOf(IsNot.not(StatementState.CLOSE), IsNot.not(StatementState.AUTOCLOSE)));
173 _setClob(i, x);
174 this.parameters.put(i, x);
175 }
176
177 public void _setClob(int i, Clob x) {
178 }
179
180 public void setDate(int parameterIndex, Date x) throws SQLException {
181 assertThat(mockState, AnyOf.anyOf(IsNot.not(StatementState.CLOSE), IsNot.not(StatementState.AUTOCLOSE)));
182 _setDate(parameterIndex, x);
183 this.parameters.put(parameterIndex, x);
184 }
185
186 public void _setDate(int parameterIndex, Date x) {
187 }
188
189 public void setDate(int parameterIndex, Date x, Calendar cal)
190 throws SQLException {
191 assertThat(mockState, AnyOf.anyOf(IsNot.not(StatementState.CLOSE), IsNot.not(StatementState.AUTOCLOSE)));
192 throw new NotYetImplementedException();
193 }
194
195 public void setDouble(int parameterIndex, double x) throws SQLException {
196 assertThat(mockState, AnyOf.anyOf(IsNot.not(StatementState.CLOSE), IsNot.not(StatementState.AUTOCLOSE)));
197 _setDouble(parameterIndex, x);
198 this.parameters.put(parameterIndex, x);
199 }
200
201 public void _setDouble(int parameterIndex, double x) {
202 }
203
204 public void setFloat(int parameterIndex, float x) throws SQLException {
205 assertThat(mockState, AnyOf.anyOf(IsNot.not(StatementState.CLOSE), IsNot.not(StatementState.AUTOCLOSE)));
206 _setFloat(parameterIndex, x);
207 this.parameters.put(parameterIndex, x);
208 }
209
210 public void _setFloat(int parameterIndex, float x) {
211 }
212
213 public void setInt(int parameterIndex, int x) throws SQLException {
214 assertThat(mockState, AnyOf.anyOf(IsNot.not(StatementState.CLOSE), IsNot.not(StatementState.AUTOCLOSE)));
215 _setInt(parameterIndex, x);
216 this.parameters.put(parameterIndex, x);
217 }
218
219 public void _setInt(int parameterIndex, int x) {
220 }
221
222 public void setLong(int parameterIndex, long x) throws SQLException {
223 assertThat(mockState, AnyOf.anyOf(IsNot.not(StatementState.CLOSE), IsNot.not(StatementState.AUTOCLOSE)));
224 _setLong(parameterIndex, x);
225 this.parameters .put(parameterIndex, x);
226 }
227
228 public void _setLong(int parameterIndex, long x) {
229 }
230
231 public void setNull(int parameterIndex, int sqlType) throws SQLException {
232 assertThat(mockState, AnyOf.anyOf(IsNot.not(StatementState.CLOSE), IsNot.not(StatementState.AUTOCLOSE)));
233 _setNull(parameterIndex, sqlType);
234 this.parameters.put(new Integer(parameterIndex), new Integer(sqlType));
235 }
236
237 public void _setNull(int parameterIndex, int sqlType) {
238 }
239
240 public void setNull(int paramIndex, int sqlType, String typeName)
241 throws SQLException {
242 assertThat(mockState, AnyOf.anyOf(IsNot.not(StatementState.CLOSE), IsNot.not(StatementState.AUTOCLOSE)));
243 throw new NotYetImplementedException();
244 }
245
246 public void setObject(int parameterIndex, Object x) throws SQLException {
247 assertThat(mockState, AnyOf.anyOf(IsNot.not(StatementState.CLOSE), IsNot.not(StatementState.AUTOCLOSE)));
248 _setObject(parameterIndex, x);
249 this.parameters .put(new Integer(parameterIndex), x);
250 }
251
252 public void _setObject(int parameterIndex, Object x) {
253 }
254
255 public void setObject(int parameterIndex, Object x, int targetSqlType)
256 throws SQLException {
257 assertThat(mockState, AnyOf.anyOf(IsNot.not(StatementState.CLOSE), IsNot.not(StatementState.AUTOCLOSE)));
258 throw new NotYetImplementedException();
259 }
260
261 public void setObject(int parameterIndex, Object x, int targetSqlType,
262 int scale) throws SQLException {
263 assertThat(mockState, AnyOf.anyOf(IsNot.not(StatementState.CLOSE), IsNot.not(StatementState.AUTOCLOSE)));
264 throw new NotYetImplementedException();
265 }
266
267 public void setRef(int i, Ref x) throws SQLException {
268 assertThat(mockState, AnyOf.anyOf(IsNot.not(StatementState.CLOSE), IsNot.not(StatementState.AUTOCLOSE)));
269 _setRef(i, x);
270 this.parameters.put(i, x);
271 }
272
273 public void _setRef(int i, Ref x) {
274 }
275
276 public void setShort(int parameterIndex, short x) throws SQLException {
277 assertThat(mockState, AnyOf.anyOf(IsNot.not(StatementState.CLOSE), IsNot.not(StatementState.AUTOCLOSE)));
278 _setShort(parameterIndex, x);
279 this.parameters.put(parameterIndex, x);
280 }
281
282 public void _setShort(int parameterIndex, short x) {
283 }
284
285 public void setString(int parameterIndex, String x) throws SQLException {
286 assertThat(mockState, AnyOf.anyOf(IsNot.not(StatementState.CLOSE), IsNot.not(StatementState.AUTOCLOSE)));
287 _setString(parameterIndex, x);
288 this.parameters.put(parameterIndex, x);
289 }
290
291 public void _setString(int parameterIndex, String x) {
292 }
293
294 public void setTime(int parameterIndex, Time x) throws SQLException {
295 assertThat(mockState, AnyOf.anyOf(IsNot.not(StatementState.CLOSE), IsNot.not(StatementState.AUTOCLOSE)));
296 _setTime(parameterIndex, x);
297 this.parameters.put(parameterIndex, x);
298 }
299
300 public void _setTime(int parameterIndex, Time x) {
301 }
302
303 public void setTime(int parameterIndex, Time x, Calendar cal)
304 throws SQLException {
305 assertThat(mockState, AnyOf.anyOf(IsNot.not(StatementState.CLOSE), IsNot.not(StatementState.AUTOCLOSE)));
306 throw new NotYetImplementedException();
307 }
308
309 public void setTimestamp(int parameterIndex, Timestamp x)
310 throws SQLException {
311 assertThat(mockState, AnyOf.anyOf(IsNot.not(StatementState.CLOSE), IsNot.not(StatementState.AUTOCLOSE)));
312 _setTimestamp(parameterIndex, x);
313 this.parameters.put(parameterIndex, x);
314 }
315
316 public void _setTimestamp(int parameterIndex, Timestamp x) {
317 }
318
319 public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal)
320 throws SQLException {
321 assertThat(mockState, AnyOf.anyOf(IsNot.not(StatementState.CLOSE), IsNot.not(StatementState.AUTOCLOSE)));
322 throw new NotYetImplementedException();
323 }
324
325 public void setURL(int parameterIndex, URL x) throws SQLException {
326 assertThat(mockState, AnyOf.anyOf(IsNot.not(StatementState.CLOSE), IsNot.not(StatementState.AUTOCLOSE)));
327 _setURL(parameterIndex, x);
328 this.parameters.put(parameterIndex, x);
329 }
330
331 public void _setURL(int parameterIndex, URL x) {
332 }
333
334 public void setUnicodeStream(int parameterIndex, InputStream x, int length)
335 throws SQLException {
336 assertThat(mockState, AnyOf.anyOf(IsNot.not(StatementState.CLOSE), IsNot.not(StatementState.AUTOCLOSE)));
337 throw new NotYetImplementedException();
338 }
339
340 @Override
341 public String toString(){
342 return ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE);
343 }
344 }