Debian Codegraph @

src/main/org/h2/jdbc/JdbcSQLTimeoutException.java

raw
1 /*
2 * Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0,
3 * and the EPL 1.0 (https://h2database.com/html/license.html).
4 * Initial Developer: H2 Group
5 */
6 package org.h2.jdbc;
7
8 import java.io.PrintStream;
9 import java.io.PrintWriter;
10 import java.sql.SQLTimeoutException;
11
12 import org.h2.message.DbException;
13
14 /**
15 * Represents a database exception.
16 */
17 public final class JdbcSQLTimeoutException extends SQLTimeoutException implements JdbcException {
18
19 private static final long serialVersionUID = 1L;
20
21 private final String originalMessage;
22 private final String stackTrace;
23 private String message;
24 private String sql;
25
26 /**
27 * Creates a SQLTimeoutException.
28 *
29 * @param message the reason
30 * @param sql the SQL statement
31 * @param state the SQL state
32 * @param errorCode the error code
33 * @param cause the exception that was the reason for this exception
34 * @param stackTrace the stack trace
35 */
36 public JdbcSQLTimeoutException(String message, String sql, String state,
37 int errorCode, Throwable cause, String stackTrace) {
38 super(message, state, errorCode);
39 this.originalMessage = message;
40 this.stackTrace = stackTrace;
41 // setSQL() also generates message
42 setSQL(sql);
43 initCause(cause);
44 }
45
46 @Override
47 public String getMessage() {
48 return message;
49 }
50
51 @Override
52 public String getOriginalMessage() {
53 return originalMessage;
54 }
55
56 @Override
57 public void printStackTrace(PrintWriter s) {
58 super.printStackTrace(s);
59 DbException.printNextExceptions(this, s);
60 }
61
62 @Override
63 public void printStackTrace(PrintStream s) {
64 super.printStackTrace(s);
65 DbException.printNextExceptions(this, s);
66 }
67
68 @Override
69 public String getSQL() {
70 return sql;
71 }
72
73 @Override
74 public void setSQL(String sql) {
75 this.sql = sql;
76 message = DbException.buildMessageForException(this);
77 }
78
79 @Override
80 public String toString() {
81 if (stackTrace == null) {
82 return super.toString();
83 }
84 return stackTrace;
85 }
86
87 }