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 public class SQLExceptionReader implements ExceptionReader
21 {
22 public String getMessage(Throwable t)
23 {
24 SQLException e = (SQLException) t;
25 return e.getMessage() + "(SQL Code: " + e.getErrorCode() + ", SQL State: + " + e.getSQLState() + ")";
26 }
27
28 public Throwable getCause(Throwable t)
29 {
30 SQLException e = (SQLException) t;
31 Throwable cause = e.getNextException();
32 if (cause == null)
33 {
34 cause = e.getCause();
35 }
36 return cause;
37 }
38
39 public Class<?> getExceptionType()
40 {
41 return SQLException.class;
42 }
43
44
45
46
47
48
49
50 public Map<?, ?> getInfo(Throwable t)
51 {
52 SQLException e = (SQLException) t;
53
54 Map<String, Object> info = new HashMap<String, Object>();
55 if (e.getErrorCode() != 0)
56 {
57 info.put("SQL Code", String.valueOf(e.getErrorCode()));
58 }
59 if (e.getSQLState() != null && !e.getSQLState().equals(StringUtils.EMPTY))
60 {
61 info.put("SQL State", e.getSQLState());
62 }
63 return info;
64 }
65 }