01: /*
02: * Created on Oct 21, 2004
03: */
04:
05: package net.sourceforge.orbroker.exception;
06:
07: import java.sql.SQLException;
08:
09: /**
10: * The default implementation that uses standard ISO values for SQLState for evaluation.
11: * Can be extended to override methods for more database specific evaluation.
12: * @author Nils Kilden-Pedersen
13: */
14: public class DefaultExceptionEvaluator implements ExceptionEvaluator {
15:
16: /**
17: * Return SQLState.
18: * @param e
19: * @return a SQLState code of length 5 or <code>null</code> if no 5 char state was found.
20: */
21: protected String getState(SQLException e) {
22: String state = e.getSQLState();
23: if (state != null) {
24: state = state.trim().toUpperCase();
25: if (state.length() != 5) {
26: return null;
27: }
28: }
29: return state;
30: }
31:
32: /**
33: * @param source
34: * @return 2 char SQLState class or <code>null</code> if such does not exist.
35: */
36: protected String getStateClass(SQLException source) {
37: String state = getState(source);
38: if (state != null) {
39: return state.substring(0, 2);
40: }
41: return null;
42: }
43:
44: /**
45: * @see net.sourceforge.orbroker.exception.ExceptionEvaluator#isConstraint(java.sql.SQLException)
46: */
47: public boolean isConstraint(SQLException source) {
48: String stateClass = getStateClass(source);
49: return "23".equals(stateClass);
50: }
51:
52: /**
53: * @see net.sourceforge.orbroker.exception.ExceptionEvaluator#isDeadlock(java.sql.SQLException)
54: */
55: public boolean isDeadlock(SQLException source) {
56: String state = getState(source);
57: return ("40001".equals(state) || "57033".equals(state));
58: }
59:
60: /**
61: * @see net.sourceforge.orbroker.exception.ExceptionEvaluator#isStaleConnection(java.sql.SQLException)
62: */
63: public boolean isStaleConnection(SQLException source) {
64: String state = getState(source);
65: return ("08001".equals(state) || "08003".equals(state));
66: }
67: }
|