KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > internetcds > jdbc > tds > SQLWarningChain


1 package com.internetcds.jdbc.tds;
2
3 import java.sql.SQLException JavaDoc;
4 import java.sql.SQLWarning JavaDoc;
5
6 /**
7  * Helper class to redruce duplicated code.
8  *
9  * @author Stefan Bodewig <a HREF="mailto:stefan.bodewig@megabit.net">stefan.bodewig@megabit.net</a>
10  *
11  * @version $Id: SQLWarningChain.java,v 1.1 2006/06/23 10:39:30 sinisa Exp $
12  */

13 class SQLWarningChain {
14    public static final String JavaDoc cvsVersion = "$Id: SQLWarningChain.java,v 1.1 2006/06/23 10:39:30 sinisa Exp $";
15    
16    private SQLWarning JavaDoc warnings;
17    
18    SQLWarningChain ()
19    {
20       warnings = null;
21    }
22    
23    /**
24     * The first warning added with {@see #addWarning addWarning}.
25     * Subsequent warnings will be chained to this SQLWarning.
26     */

27     synchronized SQLWarning JavaDoc getWarnings() {
28         return warnings;
29     }
30
31    /**
32     * After this call {@see #getWarnings getWarnings} returns null
33     * until {@see #addWarning addWarning} has been called again.
34     */

35     synchronized void clearWarnings() {
36         warnings = null;
37     }
38
39     /**
40      * Adds a SQLWarning to the warning chain.
41      */

42     synchronized void addWarning(SQLWarning JavaDoc warn) {
43         if (warnings == null) {
44             warnings = warn;
45         } else {
46             warnings.setNextWarning(warn);
47         }
48     }
49
50     /**
51      * Adds the SQLWarning wrapped in the packet if it's not an ErrorResult.
52      * Returns the wrapped SQLException otherwise.
53      */

54     SQLException JavaDoc addOrReturn(PacketMsgResult pack) {
55         if (pack instanceof PacketErrorResult) {
56             return pack.getMsg().toSQLException();
57         } else {
58             addWarning(pack.getMsg().toSQLWarning());
59             return null;
60         }
61     }
62 }
63
64
Popular Tags