1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.providers.jdbc; |
12 | |
|
13 | |
import org.mule.config.ExceptionReader; |
14 | |
import org.mule.util.StringUtils; |
15 | |
|
16 | |
import java.sql.SQLException; |
17 | |
import java.util.HashMap; |
18 | |
import java.util.Map; |
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | 4 | public class SQLExceptionReader implements ExceptionReader |
25 | |
{ |
26 | |
public String getMessage(Throwable t) |
27 | |
{ |
28 | 0 | SQLException e = (SQLException)t; |
29 | 0 | return e.getMessage() + "(SQL Code: " + e.getErrorCode() + ", SQL State: + " + e.getSQLState() + ")"; |
30 | |
} |
31 | |
|
32 | |
public Throwable getCause(Throwable t) |
33 | |
{ |
34 | 16 | SQLException e = (SQLException)t; |
35 | 16 | Throwable cause = e.getNextException(); |
36 | 16 | if (cause == null) |
37 | |
{ |
38 | 8 | cause = e.getCause(); |
39 | |
} |
40 | 16 | return cause; |
41 | |
} |
42 | |
|
43 | |
public Class getExceptionType() |
44 | |
{ |
45 | 22 | return SQLException.class; |
46 | |
} |
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
public Map getInfo(Throwable t) |
55 | |
{ |
56 | 4 | SQLException e = (SQLException)t; |
57 | 4 | Map info = new HashMap(); |
58 | 4 | if (e.getErrorCode() != 0) |
59 | |
{ |
60 | 2 | info.put("SQL Code", String.valueOf(e.getErrorCode())); |
61 | |
} |
62 | 4 | if (e.getSQLState() != null && !e.getSQLState().equals(StringUtils.EMPTY)) |
63 | |
{ |
64 | 2 | info.put("SQL State", e.getSQLState()); |
65 | |
} |
66 | 4 | return info; |
67 | |
} |
68 | |
} |