1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.dbforms.conprovider;
25
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28
29 import java.sql.CallableStatement;
30 import java.sql.Connection;
31 import java.sql.DatabaseMetaData;
32 import java.sql.PreparedStatement;
33 import java.sql.SQLException;
34 import java.sql.SQLWarning;
35 import java.sql.Statement;
36
37 import java.util.ArrayList;
38 import java.util.Iterator;
39 import java.util.List;
40 import java.util.Map;
41
42
43
44 /***
45 * DOCUMENT ME!
46 *
47 * @author $author$
48 * @version $Revision: 1.14 $
49 */
50 public class SingleConnectionWrapper implements Connection {
51 private static Log logCat = LogFactory.getLog(SingleConnectionWrapper.class
52 .getName());
53 private Connection _conn;
54 private List list = new ArrayList();
55 private boolean open = true;
56
57 /***
58 * Creates a new SingleConnectionWrapper object.
59 *
60 * @param con DOCUMENT ME!
61 */
62 public SingleConnectionWrapper(Connection con) {
63 _conn = con;
64 }
65
66 /***
67 * DOCUMENT ME!
68 *
69 * @param autoCommit DOCUMENT ME!
70 *
71 * @throws SQLException DOCUMENT ME!
72 */
73 public void setAutoCommit(boolean autoCommit) throws SQLException {
74 synchronized (_conn) {
75 _conn.setAutoCommit(autoCommit);
76 }
77 }
78
79
80 /***
81 * DOCUMENT ME!
82 *
83 * @return DOCUMENT ME!
84 *
85 * @throws SQLException DOCUMENT ME!
86 */
87 public boolean getAutoCommit() throws SQLException {
88 synchronized (_conn) {
89 return _conn.getAutoCommit();
90 }
91 }
92
93
94 /***
95 * DOCUMENT ME!
96 *
97 * @param catalog DOCUMENT ME!
98 *
99 * @throws SQLException DOCUMENT ME!
100 */
101 public void setCatalog(String catalog) throws SQLException {
102 synchronized (_conn) {
103 _conn.setCatalog(catalog);
104 }
105 }
106
107
108 /***
109 * DOCUMENT ME!
110 *
111 * @return DOCUMENT ME!
112 *
113 * @throws SQLException DOCUMENT ME!
114 */
115 public String getCatalog() throws SQLException {
116 synchronized (_conn) {
117 return _conn.getCatalog();
118 }
119 }
120
121
122 /***
123 * DOCUMENT ME!
124 *
125 * @return DOCUMENT ME!
126 *
127 * @throws SQLException DOCUMENT ME!
128 */
129 public boolean isClosed() throws SQLException {
130 synchronized (_conn) {
131 return !open || _conn.isClosed();
132 }
133 }
134
135
136 /***
137 * DOCUMENT ME!
138 *
139 * @param holdability DOCUMENT ME!
140 *
141 * @throws SQLException DOCUMENT ME!
142 */
143 public void setHoldability(int holdability) throws SQLException {
144 synchronized (_conn) {
145 _conn.setHoldability(holdability);
146 }
147 }
148
149
150 /***
151 * DOCUMENT ME!
152 *
153 * @return DOCUMENT ME!
154 *
155 * @throws SQLException DOCUMENT ME!
156 */
157 public int getHoldability() throws SQLException {
158 synchronized (_conn) {
159 return _conn.getHoldability();
160 }
161 }
162
163
164 /***
165 * DOCUMENT ME!
166 *
167 * @return DOCUMENT ME!
168 *
169 * @throws SQLException DOCUMENT ME!
170 */
171 public DatabaseMetaData getMetaData() throws SQLException {
172 synchronized (_conn) {
173 return _conn.getMetaData();
174 }
175 }
176
177
178 /***
179 * DOCUMENT ME!
180 *
181 * @param readOnly DOCUMENT ME!
182 *
183 * @throws SQLException DOCUMENT ME!
184 */
185 public void setReadOnly(boolean readOnly) throws SQLException {
186 synchronized (_conn) {
187 _conn.setReadOnly(readOnly);
188 }
189 }
190
191
192 /***
193 * DOCUMENT ME!
194 *
195 * @return DOCUMENT ME!
196 *
197 * @throws SQLException DOCUMENT ME!
198 */
199 public boolean isReadOnly() throws SQLException {
200 synchronized (_conn) {
201 return _conn.isReadOnly();
202 }
203 }
204
205
206 /***
207 * DOCUMENT ME!
208 *
209 * @return DOCUMENT ME!
210 *
211 * @throws SQLException DOCUMENT ME!
212 */
213 public java.sql.Savepoint setSavepoint() throws SQLException {
214 synchronized (_conn) {
215 return _conn.setSavepoint();
216 }
217 }
218
219
220 /***
221 * DOCUMENT ME!
222 *
223 * @param name DOCUMENT ME!
224 *
225 * @return DOCUMENT ME!
226 *
227 * @throws SQLException DOCUMENT ME!
228 */
229 public java.sql.Savepoint setSavepoint(String name)
230 throws SQLException {
231 synchronized (_conn) {
232 return _conn.setSavepoint(name);
233 }
234 }
235
236
237 /***
238 * DOCUMENT ME!
239 *
240 * @param level DOCUMENT ME!
241 *
242 * @throws SQLException DOCUMENT ME!
243 */
244 public void setTransactionIsolation(int level) throws SQLException {
245 synchronized (_conn) {
246 _conn.setTransactionIsolation(level);
247 }
248 }
249
250
251 /***
252 * DOCUMENT ME!
253 *
254 * @return DOCUMENT ME!
255 *
256 * @throws SQLException DOCUMENT ME!
257 */
258 public int getTransactionIsolation() throws SQLException {
259 synchronized (_conn) {
260 return _conn.getTransactionIsolation();
261 }
262 }
263
264
265 /***
266 * DOCUMENT ME!
267 *
268 * @param map DOCUMENT ME!
269 *
270 * @throws SQLException DOCUMENT ME!
271 */
272 public void setTypeMap(Map map) throws SQLException {
273 synchronized (_conn) {
274 _conn.setTypeMap(map);
275 }
276 }
277
278
279 /***
280 * DOCUMENT ME!
281 *
282 * @return DOCUMENT ME!
283 *
284 * @throws SQLException DOCUMENT ME!
285 */
286 public Map getTypeMap() throws SQLException {
287 synchronized (_conn) {
288 return _conn.getTypeMap();
289 }
290 }
291
292
293 /***
294 * DOCUMENT ME!
295 *
296 * @return DOCUMENT ME!
297 *
298 * @throws SQLException DOCUMENT ME!
299 */
300 public SQLWarning getWarnings() throws SQLException {
301 synchronized (_conn) {
302 return _conn.getWarnings();
303 }
304 }
305
306
307 /***
308 * DOCUMENT ME!
309 *
310 * @throws SQLException DOCUMENT ME!
311 */
312 public void clearWarnings() throws SQLException {
313 synchronized (_conn) {
314 _conn.clearWarnings();
315 }
316 }
317
318
319 /***
320 * Close only statements of this connection! do not close the connection!
321 */
322 public void close() throws SQLException {
323 synchronized (_conn) {
324 Iterator iter = list.iterator();
325
326 while (iter.hasNext()) {
327 Statement stmt = (Statement) iter.next();
328
329 try {
330 stmt.close();
331 } catch (SQLException e) {
332
333 } catch (Exception e) {
334 logCat.error(e);
335 }
336 }
337
338 list.clear();
339 open = false;
340 }
341 }
342
343
344 /***
345 * DOCUMENT ME!
346 *
347 * @throws SQLException DOCUMENT ME!
348 */
349 public void closeReally() throws SQLException {
350 synchronized (_conn) {
351 if (!_conn.isClosed()) {
352 _conn.close();
353 }
354 }
355 }
356
357
358 /***
359 * DOCUMENT ME!
360 *
361 * @throws SQLException DOCUMENT ME!
362 */
363 public void commit() throws SQLException {
364 synchronized (_conn) {
365 _conn.commit();
366 }
367 }
368
369
370 /***
371 * DOCUMENT ME!
372 *
373 * @return DOCUMENT ME!
374 *
375 * @throws SQLException DOCUMENT ME!
376 */
377 public Statement createStatement() throws SQLException {
378 synchronized (_conn) {
379 Statement res = _conn.createStatement();
380 list.add(res);
381
382 return res;
383 }
384 }
385
386
387 /***
388 * DOCUMENT ME!
389 *
390 * @param resultSetType DOCUMENT ME!
391 * @param resultSetConcurrency DOCUMENT ME!
392 *
393 * @return DOCUMENT ME!
394 *
395 * @throws SQLException DOCUMENT ME!
396 */
397 public Statement createStatement(int resultSetType,
398 int resultSetConcurrency)
399 throws SQLException {
400 synchronized (_conn) {
401 Statement res = _conn.createStatement(resultSetType,
402 resultSetConcurrency);
403 list.add(res);
404
405 return res;
406 }
407 }
408
409
410 /***
411 * DOCUMENT ME!
412 *
413 * @param resultSetType DOCUMENT ME!
414 * @param resultSetConcurrency DOCUMENT ME!
415 * @param resultSetHoldability DOCUMENT ME!
416 *
417 * @return DOCUMENT ME!
418 *
419 * @throws SQLException DOCUMENT ME!
420 */
421 public Statement createStatement(int resultSetType,
422 int resultSetConcurrency,
423 int resultSetHoldability)
424 throws SQLException {
425 synchronized (_conn) {
426 Statement res = _conn.createStatement(resultSetType,
427 resultSetConcurrency,
428 resultSetHoldability);
429 list.add(res);
430
431 return res;
432 }
433 }
434
435
436 /***
437 * DOCUMENT ME!
438 *
439 * @param sql DOCUMENT ME!
440 *
441 * @return DOCUMENT ME!
442 *
443 * @throws SQLException DOCUMENT ME!
444 */
445 public String nativeSQL(String sql) throws SQLException {
446 synchronized (_conn) {
447 return _conn.nativeSQL(sql);
448 }
449 }
450
451
452 /***
453 * DOCUMENT ME!
454 *
455 * @param sql DOCUMENT ME!
456 *
457 * @return DOCUMENT ME!
458 *
459 * @throws SQLException DOCUMENT ME!
460 */
461 public CallableStatement prepareCall(String sql) throws SQLException {
462 synchronized (_conn) {
463 CallableStatement res = _conn.prepareCall(sql);
464 list.add(res);
465
466 return res;
467 }
468 }
469
470
471 /***
472 * DOCUMENT ME!
473 *
474 * @param sql DOCUMENT ME!
475 * @param resultSetType DOCUMENT ME!
476 * @param resultSetConcurrency DOCUMENT ME!
477 *
478 * @return DOCUMENT ME!
479 *
480 * @throws SQLException DOCUMENT ME!
481 */
482 public CallableStatement prepareCall(String sql,
483 int resultSetType,
484 int resultSetConcurrency)
485 throws SQLException {
486 synchronized (_conn) {
487 CallableStatement res = _conn.prepareCall(sql, resultSetType,
488 resultSetConcurrency);
489 list.add(res);
490
491 return res;
492 }
493 }
494
495
496 /***
497 * DOCUMENT ME!
498 *
499 * @param sql DOCUMENT ME!
500 * @param resultSetType DOCUMENT ME!
501 * @param resultSetConcurrency DOCUMENT ME!
502 * @param resultSetHoldability DOCUMENT ME!
503 *
504 * @return DOCUMENT ME!
505 *
506 * @throws SQLException DOCUMENT ME!
507 */
508 public CallableStatement prepareCall(String sql,
509 int resultSetType,
510 int resultSetConcurrency,
511 int resultSetHoldability)
512 throws SQLException {
513 synchronized (_conn) {
514 CallableStatement res = _conn.prepareCall(sql, resultSetType,
515 resultSetConcurrency,
516 resultSetHoldability);
517 list.add(res);
518
519 return res;
520 }
521 }
522
523
524 /***
525 * DOCUMENT ME!
526 *
527 * @param sql DOCUMENT ME!
528 *
529 * @return DOCUMENT ME!
530 *
531 * @throws SQLException DOCUMENT ME!
532 */
533 public PreparedStatement prepareStatement(String sql)
534 throws SQLException {
535 synchronized (_conn) {
536 PreparedStatement res = _conn.prepareStatement(sql);
537 list.add(res);
538
539 return res;
540 }
541 }
542
543
544 /***
545 * DOCUMENT ME!
546 *
547 * @param sql DOCUMENT ME!
548 * @param resultSetType DOCUMENT ME!
549 * @param resultSetConcurrency DOCUMENT ME!
550 *
551 * @return DOCUMENT ME!
552 *
553 * @throws SQLException DOCUMENT ME!
554 */
555 public PreparedStatement prepareStatement(String sql,
556 int resultSetType,
557 int resultSetConcurrency)
558 throws SQLException {
559 synchronized (_conn) {
560 PreparedStatement res = _conn.prepareStatement(sql, resultSetType,
561 resultSetConcurrency);
562 list.add(res);
563
564 return res;
565 }
566 }
567
568
569 /***
570 * DOCUMENT ME!
571 *
572 * @param sql DOCUMENT ME!
573 * @param resultSetType DOCUMENT ME!
574 * @param resultSetConcurrency DOCUMENT ME!
575 * @param resultSetHoldability DOCUMENT ME!
576 *
577 * @return DOCUMENT ME!
578 *
579 * @throws SQLException DOCUMENT ME!
580 */
581 public PreparedStatement prepareStatement(String sql,
582 int resultSetType,
583 int resultSetConcurrency,
584 int resultSetHoldability)
585 throws SQLException {
586 synchronized (_conn) {
587 PreparedStatement res = _conn.prepareStatement(sql, resultSetType,
588 resultSetConcurrency,
589 resultSetHoldability);
590 list.add(res);
591
592 return res;
593 }
594 }
595
596
597 /***
598 * DOCUMENT ME!
599 *
600 * @param sql DOCUMENT ME!
601 * @param autoGeneratedKeys DOCUMENT ME!
602 *
603 * @return DOCUMENT ME!
604 *
605 * @throws SQLException DOCUMENT ME!
606 */
607 public PreparedStatement prepareStatement(String sql,
608 int autoGeneratedKeys)
609 throws SQLException {
610 synchronized (_conn) {
611 PreparedStatement res = _conn.prepareStatement(sql, autoGeneratedKeys);
612 list.add(res);
613
614 return res;
615 }
616 }
617
618
619 /***
620 * DOCUMENT ME!
621 *
622 * @param sql DOCUMENT ME!
623 * @param columnIndexes DOCUMENT ME!
624 *
625 * @return DOCUMENT ME!
626 *
627 * @throws SQLException DOCUMENT ME!
628 */
629 public PreparedStatement prepareStatement(String sql,
630 int[] columnIndexes)
631 throws SQLException {
632 synchronized (_conn) {
633 PreparedStatement res = _conn.prepareStatement(sql, columnIndexes);
634 list.add(res);
635
636 return res;
637 }
638 }
639
640
641 /***
642 * DOCUMENT ME!
643 *
644 * @param sql DOCUMENT ME!
645 * @param columnNames DOCUMENT ME!
646 *
647 * @return DOCUMENT ME!
648 *
649 * @throws SQLException DOCUMENT ME!
650 */
651 public PreparedStatement prepareStatement(String sql,
652 String[] columnNames)
653 throws SQLException {
654 synchronized (_conn) {
655 PreparedStatement res = _conn.prepareStatement(sql, columnNames);
656 list.add(res);
657
658 return res;
659 }
660 }
661
662
663 /***
664 * DOCUMENT ME!
665 *
666 * @param savepoint DOCUMENT ME!
667 *
668 * @throws SQLException DOCUMENT ME!
669 */
670 public void releaseSavepoint(java.sql.Savepoint savepoint)
671 throws SQLException {
672 synchronized (_conn) {
673 _conn.releaseSavepoint(savepoint);
674 }
675 }
676
677
678 /***
679 * DOCUMENT ME!
680 *
681 * @throws SQLException DOCUMENT ME!
682 */
683 public void rollback() throws SQLException {
684 synchronized (_conn) {
685 _conn.rollback();
686 }
687 }
688
689
690 /***
691 * DOCUMENT ME!
692 *
693 * @param savepoint DOCUMENT ME!
694 *
695 * @throws SQLException DOCUMENT ME!
696 */
697 public void rollback(java.sql.Savepoint savepoint) throws SQLException {
698 synchronized (_conn) {
699 _conn.rollback(savepoint);
700 }
701 }
702 }