1 21 22 package org.apache.derby.impl.jdbc; 23 24 import org.apache.derby.iapi.error.StandardException; 25 26 import java.sql.SQLException ; 27 import java.io.PrintStream ; 28 import java.io.PrintWriter ; 29 30 40 public class EmbedSQLException extends SQLException { 41 42 private transient Object [] arguments; 43 private String messageId; 44 45 48 private transient Throwable javaException; 52 53 59 EmbedSQLException(String message, String messageId, 60 SQLException nextException, int severity, Object [] args) { 61 62 super(message, StandardException.getSQLStateFromIdentifier(messageId), severity); 63 this.messageId = messageId; 64 arguments = args; 65 if (nextException !=null) 66 this.setNextException(nextException); 67 } 68 69 public EmbedSQLException(String message, String messageId, 70 SQLException nextException, int severity, Throwable t, Object [] args) { 71 72 super(message, StandardException.getSQLStateFromIdentifier(messageId), severity); 73 this.messageId = messageId; 74 arguments = args; 75 if (nextException !=null) 76 this.setNextException(nextException); 77 javaException = t; 78 } 79 80 public Throwable getJavaException() { 81 return javaException; 82 } 83 84 public String getMessageId() { 85 return messageId; 86 } 87 88 public Object [] getArguments() { 89 return arguments; 90 } 91 92 98 public void printStackTrace() { 99 Throwable je = getJavaException(); 100 if (je != null) 101 je.printStackTrace(); 102 else 103 super.printStackTrace(); 104 } 105 111 public void printStackTrace(PrintStream s) { 112 Throwable je = getJavaException(); 113 if (je != null) 114 je.printStackTrace(s); 115 else 116 super.printStackTrace(s); 117 } 118 124 public void printStackTrace(PrintWriter s) { 125 Throwable je = getJavaException(); 126 if (je != null) 127 je.printStackTrace(s); 128 else 129 super.printStackTrace(s); 130 } 131 132 135 136 140 public String toString() { 141 return "java.sql.SQLException: " + getMessage(); 147 } 148 149 153 private transient boolean simpleWrapper; 154 public static SQLException wrapStandardException(String message, String messageId, int code, Throwable se) { 155 EmbedSQLException csqle = new EmbedSQLException(message, messageId, (SQLException ) null, code, se, (se instanceof StandardException) ? ((StandardException)se).getArguments() : null); 156 csqle.simpleWrapper = true; 157 return csqle; 158 } 159 public boolean isSimpleWrapper() { 160 return simpleWrapper; 161 } 162 } 163 | Popular Tags |