01: package com.internetcds.jdbc.tds;
02:
03: import java.sql.SQLException;
04: import java.sql.SQLWarning;
05:
06: /**
07: * Helper class to redruce duplicated code.
08: *
09: * @author Stefan Bodewig <a href="mailto:stefan.bodewig@megabit.net">stefan.bodewig@megabit.net</a>
10: *
11: * @version $Id: SQLWarningChain.java,v 1.2 2007-10-19 13:21:40 sinisa Exp $
12: */
13: class SQLWarningChain {
14: public static final String cvsVersion = "$Id: SQLWarningChain.java,v 1.2 2007-10-19 13:21:40 sinisa Exp $";
15:
16: private SQLWarning warnings;
17:
18: SQLWarningChain() {
19: warnings = null;
20: }
21:
22: /**
23: * The first warning added with {@see #addWarning addWarning}.
24: * Subsequent warnings will be chained to this SQLWarning.
25: */
26: synchronized SQLWarning getWarnings() {
27: return warnings;
28: }
29:
30: /**
31: * After this call {@see #getWarnings getWarnings} returns null
32: * until {@see #addWarning addWarning} has been called again.
33: */
34: synchronized void clearWarnings() {
35: warnings = null;
36: }
37:
38: /**
39: * Adds a SQLWarning to the warning chain.
40: */
41: synchronized void addWarning(SQLWarning warn) {
42: if (warnings == null) {
43: warnings = warn;
44: } else {
45: warnings.setNextWarning(warn);
46: }
47: }
48:
49: /**
50: * Adds the SQLWarning wrapped in the packet if it's not an ErrorResult.
51: * Returns the wrapped SQLException otherwise.
52: */
53: SQLException addOrReturn(PacketMsgResult pack) {
54: if (pack instanceof PacketErrorResult) {
55: return pack.getMsg().toSQLException();
56: } else {
57: addWarning(pack.getMsg().toSQLWarning());
58: return null;
59: }
60: }
61: }
|