1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.jmonit.support.jdbc;
17
18 import java.io.InputStream;
19 import java.io.Reader;
20 import java.math.BigDecimal;
21 import java.net.URL;
22 import java.sql.Array;
23 import java.sql.Blob;
24 import java.sql.Clob;
25 import java.sql.Connection;
26 import java.sql.Date;
27 import java.sql.NClob;
28 import java.sql.ParameterMetaData;
29 import java.sql.PreparedStatement;
30 import java.sql.Ref;
31 import java.sql.ResultSet;
32 import java.sql.ResultSetMetaData;
33 import java.sql.RowId;
34 import java.sql.SQLException;
35 import java.sql.SQLXML;
36 import java.sql.Time;
37 import java.sql.Timestamp;
38 import java.util.Calendar;
39
40 import org.jmonit.Monitor;
41 import org.jmonit.Stopwatch;
42
43
44
45
46 public class MonitoredPreparedStatement
47 extends MonitoredStatement
48 implements PreparedStatement
49 {
50
51 private PreparedStatement statement;
52
53
54 private Monitor monitor;
55
56
57
58
59
60
61
62 public MonitoredPreparedStatement( PreparedStatement statement, String query,
63 Connection connection, JdbcMonitor monitor )
64 {
65 super( statement, connection, monitor );
66 this.statement = statement;
67 this.monitor = monitor.getPreparedStatementMonitor( query );
68 }
69
70
71
72
73 protected Monitor getMonitor()
74 {
75 return monitor;
76 }
77
78 private Stopwatch getStopwatch()
79 {
80 return Stopwatch.start( getMonitor() );
81 }
82
83
84
85
86
87
88 public final void addBatch()
89 throws SQLException
90 {
91 statement.addBatch();
92 }
93
94
95
96
97
98
99 public final void clearParameters()
100 throws SQLException
101 {
102 statement.clearParameters();
103 }
104
105
106
107
108
109
110 public final boolean execute()
111 throws SQLException
112 {
113 Stopwatch stopwatch = getStopwatch();
114 try
115 {
116 return statement.execute();
117 }
118 catch ( SQLException sqle )
119 {
120 throw handleException( sqle );
121 }
122 finally
123 {
124 stopwatch.stop();
125 }
126 }
127
128
129
130
131
132
133 public final ResultSet executeQuery()
134 throws SQLException
135 {
136 Stopwatch stopwatch = getStopwatch();
137 try
138 {
139 return statement.executeQuery();
140 }
141 catch ( SQLException sqle )
142 {
143 throw handleException( sqle );
144 }
145 finally
146 {
147 stopwatch.stop();
148 }
149 }
150
151
152
153
154
155
156 public final int executeUpdate()
157 throws SQLException
158 {
159 Stopwatch stopwatch = getStopwatch();
160 try
161 {
162 return statement.executeUpdate();
163 }
164 catch ( SQLException sqle )
165 {
166 throw handleException( sqle );
167 }
168 finally
169 {
170 stopwatch.stop();
171 }
172 }
173
174
175
176
177
178
179 public final ResultSetMetaData getMetaData()
180 throws SQLException
181 {
182 return statement.getMetaData();
183 }
184
185
186
187
188
189
190 public final void setArray( int i, Array x )
191 throws SQLException
192 {
193 statement.setArray( i, x );
194 }
195
196
197
198
199
200
201
202 public final void setAsciiStream( int parameterIndex, InputStream x, int length )
203 throws SQLException
204 {
205 statement.setAsciiStream( parameterIndex, x, length );
206 }
207
208
209
210
211
212
213 public final void setBigDecimal( int parameterIndex, BigDecimal x )
214 throws SQLException
215 {
216 statement.setBigDecimal( parameterIndex, x );
217 }
218
219
220
221
222
223
224
225 public final void setBinaryStream( int parameterIndex, InputStream x, int length )
226 throws SQLException
227 {
228 statement.setBinaryStream( parameterIndex, x, length );
229 }
230
231
232
233
234
235
236 public final void setBlob( int i, Blob x )
237 throws SQLException
238 {
239 statement.setBlob( i, x );
240 }
241
242
243
244
245
246
247 public final void setBoolean( int parameterIndex, boolean x )
248 throws SQLException
249 {
250 statement.setBoolean( parameterIndex, x );
251 }
252
253
254
255
256
257
258 public final void setByte( int parameterIndex, byte x )
259 throws SQLException
260 {
261 statement.setByte( parameterIndex, x );
262 }
263
264
265
266
267
268
269 public final void setBytes( int parameterIndex, byte[] x )
270 throws SQLException
271 {
272 statement.setBytes( parameterIndex, x );
273 }
274
275
276
277
278
279
280
281 public final void setCharacterStream( int parameterIndex, Reader reader, int length )
282 throws SQLException
283 {
284 statement.setCharacterStream( parameterIndex, reader, length );
285 }
286
287
288
289
290
291
292 public final void setClob( int i, Clob x )
293 throws SQLException
294 {
295 statement.setClob( i, x );
296 }
297
298
299
300
301
302
303
304 public final void setDate( int parameterIndex, Date x, Calendar cal )
305 throws SQLException
306 {
307 statement.setDate( parameterIndex, x, cal );
308 }
309
310
311
312
313
314
315 public final void setDate( int parameterIndex, Date x )
316 throws SQLException
317 {
318 statement.setDate( parameterIndex, x );
319 }
320
321
322
323
324
325
326 public final void setDouble( int parameterIndex, double x )
327 throws SQLException
328 {
329 statement.setDouble( parameterIndex, x );
330 }
331
332
333
334
335
336
337 public final void setFloat( int parameterIndex, float x )
338 throws SQLException
339 {
340 statement.setFloat( parameterIndex, x );
341 }
342
343
344
345
346
347
348 public final void setInt( int parameterIndex, int x )
349 throws SQLException
350 {
351 statement.setInt( parameterIndex, x );
352 }
353
354
355
356
357
358
359 public final void setLong( int parameterIndex, long x )
360 throws SQLException
361 {
362 statement.setLong( parameterIndex, x );
363 }
364
365
366
367
368
369
370 public final void setNull( int paramIndex, int sqlType, String typeName )
371 throws SQLException
372 {
373 statement.setNull( paramIndex, sqlType, typeName );
374 }
375
376
377
378
379
380
381 public final void setNull( int parameterIndex, int sqlType )
382 throws SQLException
383 {
384 statement.setNull( parameterIndex, sqlType );
385 }
386
387
388
389
390
391
392
393 public final void setObject( int parameterIndex, Object x, int targetSqlType, int scale )
394 throws SQLException
395 {
396 statement.setObject( parameterIndex, x, targetSqlType, scale );
397 }
398
399
400
401
402
403
404 public final void setObject( int parameterIndex, Object x, int targetSqlType )
405 throws SQLException
406 {
407 statement.setObject( parameterIndex, x, targetSqlType );
408 }
409
410
411
412
413
414
415 public final void setObject( int parameterIndex, Object x )
416 throws SQLException
417 {
418 statement.setObject( parameterIndex, x );
419 }
420
421
422
423
424
425
426 public final void setRef( int i, Ref x )
427 throws SQLException
428 {
429 statement.setRef( i, x );
430 }
431
432
433
434
435
436
437 public final void setShort( int parameterIndex, short x )
438 throws SQLException
439 {
440 statement.setShort( parameterIndex, x );
441 }
442
443
444
445
446
447
448 public final void setString( int parameterIndex, String x )
449 throws SQLException
450 {
451 statement.setString( parameterIndex, x );
452 }
453
454
455
456
457
458
459
460 public final void setTime( int parameterIndex, Time x, Calendar cal )
461 throws SQLException
462 {
463 statement.setTime( parameterIndex, x, cal );
464 }
465
466
467
468
469
470
471 public final void setTime( int parameterIndex, Time x )
472 throws SQLException
473 {
474 statement.setTime( parameterIndex, x );
475 }
476
477
478
479
480
481
482
483 public final void setTimestamp( int parameterIndex, Timestamp x, Calendar cal )
484 throws SQLException
485 {
486 statement.setTimestamp( parameterIndex, x, cal );
487 }
488
489
490
491
492
493
494 public final void setTimestamp( int parameterIndex, Timestamp x )
495 throws SQLException
496 {
497 statement.setTimestamp( parameterIndex, x );
498 }
499
500
501
502
503
504
505
506 public final void setUnicodeStream( int parameterIndex, InputStream x, int length )
507 throws SQLException
508 {
509 statement.setUnicodeStream( parameterIndex, x, length );
510 }
511
512
513
514
515
516
517
518
519
520 public final void setAsciiStream( int parameterIndex, InputStream x, long length )
521 throws SQLException
522 {
523 statement.setAsciiStream( parameterIndex, x, length );
524 }
525
526
527
528
529
530
531
532 public final void setAsciiStream( int parameterIndex, InputStream x )
533 throws SQLException
534 {
535 statement.setAsciiStream( parameterIndex, x );
536 }
537
538
539
540
541
542
543
544
545
546 public final void setBinaryStream( int parameterIndex, InputStream x, long length )
547 throws SQLException
548 {
549 statement.setBinaryStream( parameterIndex, x, length );
550 }
551
552
553
554
555
556
557
558 public final void setBinaryStream( int parameterIndex, InputStream x )
559 throws SQLException
560 {
561 statement.setBinaryStream( parameterIndex, x );
562 }
563
564
565
566
567
568
569
570
571 public final void setBlob( int parameterIndex, InputStream inputStream, long length )
572 throws SQLException
573 {
574 statement.setBlob( parameterIndex, inputStream, length );
575 }
576
577
578
579
580
581
582
583 public final void setBlob( int parameterIndex, InputStream inputStream )
584 throws SQLException
585 {
586 statement.setBlob( parameterIndex, inputStream );
587 }
588
589
590
591
592
593
594
595
596
597 public final void setCharacterStream( int parameterIndex, Reader reader, long length )
598 throws SQLException
599 {
600 statement.setCharacterStream( parameterIndex, reader, length );
601 }
602
603
604
605
606
607
608
609 public final void setCharacterStream( int parameterIndex, Reader reader )
610 throws SQLException
611 {
612 statement.setCharacterStream( parameterIndex, reader );
613 }
614
615
616
617
618
619
620
621
622 public final void setClob( int parameterIndex, Reader reader, long length )
623 throws SQLException
624 {
625 statement.setClob( parameterIndex, reader, length );
626 }
627
628
629
630
631
632
633
634 public final void setClob( int parameterIndex, Reader reader )
635 throws SQLException
636 {
637 statement.setClob( parameterIndex, reader );
638 }
639
640
641
642
643
644
645
646
647
648 public final void setNCharacterStream( int parameterIndex, Reader value, long length )
649 throws SQLException
650 {
651 statement.setNCharacterStream( parameterIndex, value, length );
652 }
653
654
655
656
657
658
659
660 public final void setNCharacterStream( int parameterIndex, Reader value )
661 throws SQLException
662 {
663 statement.setNCharacterStream( parameterIndex, value );
664 }
665
666
667
668
669
670
671
672 public final void setNClob( int parameterIndex, NClob value )
673 throws SQLException
674 {
675 statement.setNClob( parameterIndex, value );
676 }
677
678
679
680
681
682
683
684
685 public final void setNClob( int parameterIndex, Reader reader, long length )
686 throws SQLException
687 {
688 statement.setNClob( parameterIndex, reader, length );
689 }
690
691
692
693
694
695
696
697 public final void setNClob( int parameterIndex, Reader reader )
698 throws SQLException
699 {
700 statement.setNClob( parameterIndex, reader );
701 }
702
703
704
705
706
707
708
709 public final void setNString( int parameterIndex, String value )
710 throws SQLException
711 {
712 statement.setNString( parameterIndex, value );
713 }
714
715
716
717
718
719
720
721 public final void setRowId( int parameterIndex, RowId x )
722 throws SQLException
723 {
724 statement.setRowId( parameterIndex, x );
725 }
726
727
728
729
730
731
732
733 public final void setSQLXML( int parameterIndex, SQLXML xmlObject )
734 throws SQLException
735 {
736 statement.setSQLXML( parameterIndex, xmlObject );
737 }
738
739
740
741
742
743
744
745 public final void setURL( int parameterIndex, URL x )
746 throws SQLException
747 {
748 statement.setURL( parameterIndex, x );
749 }
750
751
752
753
754
755
756 public final ParameterMetaData getParameterMetaData()
757 throws SQLException
758 {
759 return statement.getParameterMetaData();
760 }
761
762 }