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