Clover coverage report - brownies library - 1.0-beta-1 Coverage timestamp: 月 8 16 2004 17:14:42 GMT+09:00 FRAMES NO FRAMES |
file stats: | LOC: | 474 |  | Methods: | 42
| NCLOC: | 217 |  | Classes: | 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
Source file | Conditionals | Statements | Methods | TOTAL
LogPreparedStatement.java | - | 0% | 0% | 0% |

1 |  |
     /*
2 |  |
      * Joey and its relative products are published under the terms
3 |  |
      * of the Apache Software License.
4 |  |
      */
5 |  |
     /*
6 |  |
      * Created on 2004/03/01
7 |  |
      */
8 |  |
     package org.asyrinx.brownie.jdbc.logger;
9 |  |
10 |  |
     import java.io.InputStream;
11 |  |
     import java.io.Reader;
12 |  |
     import java.math.BigDecimal;
13 |  |
     import java.net.URL;
14 |  |
     import java.sql.Array;
15 |  |
     import java.sql.Blob;
16 |  |
     import java.sql.Clob;
17 |  |
     import java.sql.Date;
18 |  |
     import java.sql.ParameterMetaData;
19 |  |
     import java.sql.PreparedStatement;
20 |  |
     import java.sql.Ref;
21 |  |
     import java.sql.ResultSet;
22 |  |
     import java.sql.ResultSetMetaData;
23 |  |
     import java.sql.SQLException;
24 |  |
     import java.sql.Time;
25 |  |
     import java.sql.Timestamp;
26 |  |
     import java.util.Calendar;
27 |  |
     import java.util.HashMap;
28 |  |
29 |  |
     import org.asyrinx.brownie.core.collection.IntegerKeyMap;
30 |  |
     import org.asyrinx.brownie.core.collection.MapUtils;
31 |  |
     import org.asyrinx.brownie.core.log.CascadeNamedLog;
32 |  |
     import org.asyrinx.brownie.core.sql.SqlReplacer;
33 |  |
34 |  |
     /**
35 |  |
      * @author akima
36 |  |
      */
37 |  |
     public class LogPreparedStatement extends LogStatement implements
38 |  |
             PreparedStatement {
39 |  |
         /**
40 |  |
          * @param wrapped
41 |  |
          */
42 | 0 |
         public LogPreparedStatement(PreparedStatement wrapped, String sql,
43 |  |
                 CascadeNamedLog parentLog) {
44 | 0 |
             super(wrapped, parentLog);
45 | 0 |
             this.wrapped = wrapped;
46 | 0 |
             this.sql = sql;
47 |  |
         }
48 |  |
49 |  |
         private final PreparedStatement wrapped;
50 |  |
51 |  |
         private final IntegerKeyMap parameters = MapUtils
52 |  |
                 .toIntegerKeyMap(new HashMap());
53 |  |
54 |  |
         protected final String sql;
55 |  |
56 |  |
         protected final SqlReplacer replacer = new SqlReplacer();
57 |  |
58 | 0 |
         protected final void addParam(int paramIndex, Object value) {
59 | 0 |
             parameters.put(paramIndex, value);
60 |  |
         }
61 |  |
62 | 0 |
         protected void log() {
63 | 0 |
             this.log.log(formatSql());
64 |  |
         }
65 |  |
66 | 0 |
         protected void log(SQLException e) {
67 | 0 |
             this.log.log((Object) formatSql(), e);
68 |  |
         }
69 |  |
70 | 0 |
         protected String formatSql() {
71 | 0 |
             return replacer.execute(this.sql, this.parameters);
72 |  |
         }
73 |  |
74 |  |
         /**
75 |  |
          * @throws java.sql.SQLException
76 |  |
          */
77 | 0 |
         public void addBatch() throws SQLException {
78 | 0 |
             wrapped.addBatch();
79 | 0 |
             batches.add(formatSql());
80 |  |
         }
81 |  |
82 |  |
         /**
83 |  |
          * @throws java.sql.SQLException
84 |  |
          */
85 | 0 |
         public void clearParameters() throws SQLException {
86 | 0 |
             wrapped.clearParameters();
87 | 0 |
             parameters.clear();
88 |  |
         }
89 |  |
90 |  |
         /**
91 |  |
          * @return @throws
92 |  |
          *         java.sql.SQLException
93 |  |
          */
94 | 0 |
         public boolean execute() throws SQLException {
95 | 0 |
             try {
96 | 0 |
                 final boolean reasult = wrapped.execute();
97 | 0 |
                 log();
98 | 0 |
                 return reasult;
99 |  |
             } catch (SQLException e) {
100 | 0 |
                 log(e);
101 | 0 |
                 throw e;
102 |  |
             }
103 |  |
         }
104 |  |
105 |  |
         /**
106 |  |
          * @return @throws
107 |  |
          *         java.sql.SQLException
108 |  |
          */
109 | 0 |
         public ResultSet executeQuery() throws SQLException {
110 | 0 |
             try {
111 | 0 |
                 final ResultSet result = wrapped.executeQuery();
112 | 0 |
                 log();
113 | 0 |
                 return result;
114 |  |
             } catch (SQLException e) {
115 | 0 |
                 log(e);
116 | 0 |
                 throw e;
117 |  |
             }
118 |  |
         }
119 |  |
120 |  |
         /**
121 |  |
          * @return @throws
122 |  |
          *         java.sql.SQLException
123 |  |
          */
124 | 0 |
         public int executeUpdate() throws SQLException {
125 | 0 |
             try {
126 | 0 |
                 final int result = wrapped.executeUpdate();
127 | 0 |
                 log();
128 | 0 |
                 return result;
129 |  |
             } catch (SQLException e) {
130 | 0 |
                 log(e);
131 | 0 |
                 throw e;
132 |  |
             }
133 |  |
         }
134 |  |
135 |  |
         /**
136 |  |
          * @return @throws
137 |  |
          *         java.sql.SQLException
138 |  |
          */
139 | 0 |
         public ResultSetMetaData getMetaData() throws SQLException {
140 | 0 |
             return wrapped.getMetaData();
141 |  |
         }
142 |  |
143 |  |
         /**
144 |  |
          * @return @throws
145 |  |
          *         java.sql.SQLException
146 |  |
          */
147 | 0 |
         public ParameterMetaData getParameterMetaData() throws SQLException {
148 | 0 |
             return wrapped.getParameterMetaData();
149 |  |
         }
150 |  |
151 |  |
         /**
152 |  |
          * @param i
153 |  |
          * @param x
154 |  |
          * @throws java.sql.SQLException
155 |  |
          */
156 | 0 |
         public void setArray(int parameterIndex, Array x) throws SQLException {
157 | 0 |
             wrapped.setArray(parameterIndex, x);
158 | 0 |
             addParam(parameterIndex, x);
159 |  |
         }
160 |  |
161 |  |
         /**
162 |  |
          * @param parameterIndex
163 |  |
          * @param x
164 |  |
          * @param length
165 |  |
          * @throws java.sql.SQLException
166 |  |
          */
167 | 0 |
         public void setAsciiStream(int parameterIndex, InputStream x, int length)
168 |  |
                 throws SQLException {
169 | 0 |
             wrapped.setAsciiStream(parameterIndex, x, length);
170 |  |
             //addParam(parameterIndex, x);
171 |  |
         }
172 |  |
173 |  |
         /**
174 |  |
          * @param parameterIndex
175 |  |
          * @param x
176 |  |
          * @throws java.sql.SQLException
177 |  |
          */
178 | 0 |
         public void setBigDecimal(int parameterIndex, BigDecimal x)
179 |  |
                 throws SQLException {
180 | 0 |
             wrapped.setBigDecimal(parameterIndex, x);
181 | 0 |
             addParam(parameterIndex, x);
182 |  |
         }
183 |  |
184 |  |
         /**
185 |  |
          * @param parameterIndex
186 |  |
          * @param x
187 |  |
          * @param length
188 |  |
          * @throws java.sql.SQLException
189 |  |
          */
190 | 0 |
         public void setBinaryStream(int parameterIndex, InputStream x, int length)
191 |  |
                 throws SQLException {
192 | 0 |
             wrapped.setBinaryStream(parameterIndex, x, length);
193 |  |
             //addParam(parameterIndex, x);
194 |  |
         }
195 |  |
196 |  |
         /**
197 |  |
          * @param i
198 |  |
          * @param x
199 |  |
          * @throws java.sql.SQLException
200 |  |
          */
201 | 0 |
         public void setBlob(int parameterIndex, Blob x) throws SQLException {
202 | 0 |
             wrapped.setBlob(parameterIndex, x);
203 | 0 |
             addParam(parameterIndex, x);
204 |  |
         }
205 |  |
206 |  |
         /**
207 |  |
          * @param parameterIndex
208 |  |
          * @param x
209 |  |
          * @throws java.sql.SQLException
210 |  |
          */
211 | 0 |
         public void setBoolean(int parameterIndex, boolean x) throws SQLException {
212 | 0 |
             wrapped.setBoolean(parameterIndex, x);
213 | 0 |
             addParam(parameterIndex, new Boolean(x));
214 |  |
         }
215 |  |
216 |  |
         /**
217 |  |
          * @param parameterIndex
218 |  |
          * @param x
219 |  |
          * @throws java.sql.SQLException
220 |  |
          */
221 | 0 |
         public void setByte(int parameterIndex, byte x) throws SQLException {
222 | 0 |
             wrapped.setByte(parameterIndex, x);
223 | 0 |
             addParam(parameterIndex, new Byte(x));
224 |  |
         }
225 |  |
226 |  |
         /**
227 |  |
          * @param parameterIndex
228 |  |
          * @param x
229 |  |
          * @throws java.sql.SQLException
230 |  |
          */
231 | 0 |
         public void setBytes(int parameterIndex, byte[] x) throws SQLException {
232 | 0 |
             wrapped.setBytes(parameterIndex, x);
233 | 0 |
             addParam(parameterIndex, x);
234 |  |
         }
235 |  |
236 |  |
         /**
237 |  |
          * @param parameterIndex
238 |  |
          * @param reader
239 |  |
          * @param length
240 |  |
          * @throws java.sql.SQLException
241 |  |
          */
242 | 0 |
         public void setCharacterStream(int parameterIndex, Reader reader, int length)
243 |  |
                 throws SQLException {
244 | 0 |
             wrapped.setCharacterStream(parameterIndex, reader, length);
245 |  |
             //addParam(parameterIndex, reader);
246 |  |
         }
247 |  |
248 |  |
         /**
249 |  |
          * @param i
250 |  |
          * @param x
251 |  |
          * @throws java.sql.SQLException
252 |  |
          */
253 | 0 |
         public void setClob(int parameterIndex, Clob x) throws SQLException {
254 | 0 |
             wrapped.setClob(parameterIndex, x);
255 | 0 |
             addParam(parameterIndex, x);
256 |  |
         }
257 |  |
258 |  |
         /**
259 |  |
          * @param parameterIndex
260 |  |
          * @param x
261 |  |
          * @throws java.sql.SQLException
262 |  |
          */
263 | 0 |
         public void setDate(int parameterIndex, Date x) throws SQLException {
264 | 0 |
             wrapped.setDate(parameterIndex, x);
265 | 0 |
             addParam(parameterIndex, x);
266 |  |
         }
267 |  |
268 |  |
         /**
269 |  |
          * @param parameterIndex
270 |  |
          * @param x
271 |  |
          * @param cal
272 |  |
          * @throws java.sql.SQLException
273 |  |
          */
274 | 0 |
         public void setDate(int parameterIndex, Date x, Calendar cal)
275 |  |
                 throws SQLException {
276 | 0 |
             wrapped.setDate(parameterIndex, x, cal);
277 | 0 |
             addParam(parameterIndex, x);
278 |  |
         }
279 |  |
280 |  |
         /**
281 |  |
          * @param parameterIndex
282 |  |
          * @param x
283 |  |
          * @throws java.sql.SQLException
284 |  |
          */
285 | 0 |
         public void setDouble(int parameterIndex, double x) throws SQLException {
286 | 0 |
             wrapped.setDouble(parameterIndex, x);
287 | 0 |
             addParam(parameterIndex, new Double(x));
288 |  |
         }
289 |  |
290 |  |
         /**
291 |  |
          * @param parameterIndex
292 |  |
          * @param x
293 |  |
          * @throws java.sql.SQLException
294 |  |
          */
295 | 0 |
         public void setFloat(int parameterIndex, float x) throws SQLException {
296 | 0 |
             wrapped.setFloat(parameterIndex, x);
297 | 0 |
             addParam(parameterIndex, new Float(x));
298 |  |
         }
299 |  |
300 |  |
         /**
301 |  |
          * @param parameterIndex
302 |  |
          * @param x
303 |  |
          * @throws java.sql.SQLException
304 |  |
          */
305 | 0 |
         public void setInt(int parameterIndex, int x) throws SQLException {
306 | 0 |
             wrapped.setInt(parameterIndex, x);
307 | 0 |
             addParam(parameterIndex, new Integer(x));
308 |  |
         }
309 |  |
310 |  |
         /**
311 |  |
          * @param parameterIndex
312 |  |
          * @param x
313 |  |
          * @throws java.sql.SQLException
314 |  |
          */
315 | 0 |
         public void setLong(int parameterIndex, long x) throws SQLException {
316 | 0 |
             wrapped.setLong(parameterIndex, x);
317 | 0 |
             addParam(parameterIndex, new Long(x));
318 |  |
         }
319 |  |
320 |  |
         /**
321 |  |
          * @param parameterIndex
322 |  |
          * @param sqlType
323 |  |
          * @throws java.sql.SQLException
324 |  |
          */
325 | 0 |
         public void setNull(int parameterIndex, int sqlType) throws SQLException {
326 | 0 |
             wrapped.setNull(parameterIndex, sqlType);
327 |  |
             //addParam(parameterIndex, null);
328 |  |
         }
329 |  |
330 |  |
         /**
331 |  |
          * @param paramIndex
332 |  |
          * @param sqlType
333 |  |
          * @param typeName
334 |  |
          * @throws java.sql.SQLException
335 |  |
          */
336 | 0 |
         public void setNull(int parameterIndex, int sqlType, String typeName)
337 |  |
                 throws SQLException {
338 | 0 |
             wrapped.setNull(parameterIndex, sqlType, typeName);
339 |  |
             //addParam(parameterIndex, null);
340 |  |
         }
341 |  |
342 |  |
         /**
343 |  |
          * @param parameterIndex
344 |  |
          * @param x
345 |  |
          * @throws java.sql.SQLException
346 |  |
          */
347 | 0 |
         public void setObject(int parameterIndex, Object x) throws SQLException {
348 | 0 |
             wrapped.setObject(parameterIndex, x);
349 |  |
         }
350 |  |
351 |  |
         /**
352 |  |
          * @param parameterIndex
353 |  |
          * @param x
354 |  |
          * @param targetSqlType
355 |  |
          * @throws java.sql.SQLException
356 |  |
          */
357 | 0 |
         public void setObject(int parameterIndex, Object x, int targetSqlType)
358 |  |
                 throws SQLException {
359 | 0 |
             wrapped.setObject(parameterIndex, x, targetSqlType);
360 | 0 |
             addParam(parameterIndex, x);
361 |  |
         }
362 |  |
363 |  |
         /**
364 |  |
          * @param parameterIndex
365 |  |
          * @param x
366 |  |
          * @param targetSqlType
367 |  |
          * @param scale
368 |  |
          * @throws java.sql.SQLException
369 |  |
          */
370 | 0 |
         public void setObject(int parameterIndex, Object x, int targetSqlType,
371 |  |
                 int scale) throws SQLException {
372 | 0 |
             wrapped.setObject(parameterIndex, x, targetSqlType, scale);
373 | 0 |
             addParam(parameterIndex, x);
374 |  |
         }
375 |  |
376 |  |
         /**
377 |  |
          * @param i
378 |  |
          * @param x
379 |  |
          * @throws java.sql.SQLException
380 |  |
          */
381 | 0 |
         public void setRef(int parameterIndex, Ref x) throws SQLException {
382 | 0 |
             wrapped.setRef(parameterIndex, x);
383 | 0 |
             addParam(parameterIndex, x);
384 |  |
         }
385 |  |
386 |  |
         /**
387 |  |
          * @param parameterIndex
388 |  |
          * @param x
389 |  |
          * @throws java.sql.SQLException
390 |  |
          */
391 | 0 |
         public void setShort(int parameterIndex, short x) throws SQLException {
392 | 0 |
             wrapped.setShort(parameterIndex, x);
393 | 0 |
             addParam(parameterIndex, new Short(x));
394 |  |
         }
395 |  |
396 |  |
         /**
397 |  |
          * @param parameterIndex
398 |  |
          * @param x
399 |  |
          * @throws java.sql.SQLException
400 |  |
          */
401 | 0 |
         public void setString(int parameterIndex, String x) throws SQLException {
402 | 0 |
             wrapped.setString(parameterIndex, x);
403 | 0 |
             addParam(parameterIndex, x);
404 |  |
         }
405 |  |
406 |  |
         /**
407 |  |
          * @param parameterIndex
408 |  |
          * @param x
409 |  |
          * @throws java.sql.SQLException
410 |  |
          */
411 | 0 |
         public void setTime(int parameterIndex, Time x) throws SQLException {
412 | 0 |
             wrapped.setTime(parameterIndex, x);
413 | 0 |
             addParam(parameterIndex, x);
414 |  |
         }
415 |  |
416 |  |
         /**
417 |  |
          * @param parameterIndex
418 |  |
          * @param x
419 |  |
          * @param cal
420 |  |
          * @throws java.sql.SQLException
421 |  |
          */
422 | 0 |
         public void setTime(int parameterIndex, Time x, Calendar cal)
423 |  |
                 throws SQLException {
424 | 0 |
             wrapped.setTime(parameterIndex, x, cal);
425 | 0 |
             addParam(parameterIndex, x);
426 |  |
         }
427 |  |
428 |  |
         /**
429 |  |
          * @param parameterIndex
430 |  |
          * @param x
431 |  |
          * @throws java.sql.SQLException
432 |  |
          */
433 | 0 |
         public void setTimestamp(int parameterIndex, Timestamp x)
434 |  |
                 throws SQLException {
435 | 0 |
             wrapped.setTimestamp(parameterIndex, x);
436 | 0 |
             addParam(parameterIndex, x);
437 |  |
         }
438 |  |
439 |  |
         /**
440 |  |
          * @param parameterIndex
441 |  |
          * @param x
442 |  |
          * @param cal
443 |  |
          * @throws java.sql.SQLException
444 |  |
          */
445 | 0 |
         public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal)
446 |  |
                 throws SQLException {
447 | 0 |
             wrapped.setTimestamp(parameterIndex, x, cal);
448 | 0 |
             addParam(parameterIndex, x);
449 |  |
         }
450 |  |
451 |  |
         /**
452 |  |
          * @param parameterIndex
453 |  |
          * @param x
454 |  |
          * @param length
455 |  |
          * @throws java.sql.SQLException
456 |  |
          * @deprecated
457 |  |
          */
458 | 0 |
         public void setUnicodeStream(int parameterIndex, InputStream x, int length)
459 |  |
                 throws SQLException {
460 | 0 |
             wrapped.setUnicodeStream(parameterIndex, x, length);
461 |  |
             //addParam(parameterIndex, x);
462 |  |
         }
463 |  |
464 |  |
         /**
465 |  |
          * @param parameterIndex
466 |  |
          * @param x
467 |  |
          * @throws java.sql.SQLException
468 |  |
          */
469 | 0 |
         public void setURL(int parameterIndex, URL x) throws SQLException {
470 | 0 |
             wrapped.setURL(parameterIndex, x);
471 | 0 |
             addParam(parameterIndex, x);
472 |  |
         }
473 |  |
474 |  |
     }