View Javadoc

1   package org.skife.jdbi.v2.exceptions;
2   
3   import org.skife.jdbi.v2.StatementContext;
4   
5   /**
6    *
7    */
8   public abstract class StatementException extends DBIException
9   {
10      private final StatementContext statementContext;
11  
12      public StatementException(String string, Throwable throwable, StatementContext ctx) {
13          super(string, throwable);
14          this.statementContext = ctx;
15      }
16  
17      public StatementException(Throwable cause, StatementContext ctx) {
18          super(cause);
19          this.statementContext = ctx;
20      }
21  
22      public StatementException(String message, StatementContext ctx) {
23          super(message);
24          this.statementContext = ctx;
25      }
26  
27      /**
28       * @deprecated
29       */
30      public StatementException(String string, Throwable throwable) {
31          super(string, throwable);
32          this.statementContext = null;
33      }
34  
35      /**
36       * @deprecated
37       */
38      public StatementException(Throwable cause) {
39          super(cause);
40          this.statementContext = null;
41      }
42  
43      /**
44       * @deprecated
45       */
46      public StatementException(String message) {
47          super(message);
48          this.statementContext = null;
49      }
50  
51      public StatementContext getStatementContext() {
52          return statementContext;
53      }
54  
55      @Override
56      public String getMessage() {
57          String base = super.getMessage();
58          StatementContext ctx = getStatementContext();
59          if (ctx == null) {
60              return base;
61          }
62          else {
63              return String.format("%s [statement:\"%s\", located:\"%s\", rewritten:\"%s\", arguments:%s]",
64                                   base,
65                                   ctx.getRawSql(),
66                                   ctx.getLocatedSql(),
67                                   ctx.getRewrittenSql(),
68                                   ctx.getBinding());
69          }
70      }
71  }