01: /*
02: Copyright (C) 2002-2007 MySQL AB
03:
04: This program is free software; you can redistribute it and/or modify
05: it under the terms of version 2 of the GNU General Public License as
06: published by the Free Software Foundation.
07:
08: There are special exceptions to the terms and conditions of the GPL
09: as it is applied to this software. View the full text of the
10: exception in file EXCEPTIONS-CONNECTOR-J in the directory of this
11: software distribution.
12:
13: This program is distributed in the hope that it will be useful,
14: but WITHOUT ANY WARRANTY; without even the implied warranty of
15: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16: GNU General Public License for more details.
17:
18: You should have received a copy of the GNU General Public License
19: along with this program; if not, write to the Free Software
20: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21:
22:
23:
24: */
25: package com.mysql.jdbc.exceptions.jdbc4;
26:
27: import java.net.BindException;
28:
29: import java.sql.SQLRecoverableException;
30:
31: import com.mysql.jdbc.ConnectionImpl;
32: import com.mysql.jdbc.SQLError;
33: import com.mysql.jdbc.StreamingNotifiable;
34:
35: /**
36: * An exception to represent communications errors with the database.
37: *
38: * Attempts to provide 'friendler' error messages to end-users, including last
39: * time a packet was sent to the database, what the client-timeout is set to,
40: * and whether the idle time has been exceeded.
41: *
42: * @author Mark Matthews
43: *
44: * @version $Id: CommunicationsException.java,v 1.1.2.1 2005/05/13 18:58:37
45: * mmatthews Exp $
46: */
47: public class CommunicationsException extends SQLRecoverableException
48: implements StreamingNotifiable {
49:
50: private String exceptionMessage;
51:
52: private boolean streamingResultSetInPlay = false;
53:
54: public CommunicationsException(ConnectionImpl conn,
55: long lastPacketSentTimeMs, Exception underlyingException) {
56:
57: this .exceptionMessage = SQLError
58: .createLinkFailureMessageBasedOnHeuristics(conn,
59: lastPacketSentTimeMs, underlyingException,
60: this .streamingResultSetInPlay);
61: }
62:
63: /*
64: * (non-Javadoc)
65: *
66: * @see java.lang.Throwable#getMessage()
67: */
68: public String getMessage() {
69: return this .exceptionMessage;
70: }
71:
72: /*
73: * (non-Javadoc)
74: *
75: * @see java.sql.SQLException#getSQLState()
76: */
77: public String getSQLState() {
78: return SQLError.SQL_STATE_COMMUNICATION_LINK_FAILURE;
79: }
80:
81: public void setWasStreamingResults() {
82: this .streamingResultSetInPlay = true;
83: }
84:
85: }
|