Method from org.apache.derby.iapi.error.StandardException Detail: |
public static StandardException closeException() {
StandardException se = newException(SQLState.CLOSE_REQUEST);
se.setReport(REPORT_NEVER);
return se;
}
A special exception to close a session. |
public static SQLException getArgumentFerry(SQLException se) {
if (se instanceof DerbySQLException) {
/*
* Cater for pre-JDBC4 scenario.
*/
return se;
}
/*
* See DERBY-1178 for background information.
* In JDBC4, the DerbySQLException may be wrapped by a SQLException.
*/
Throwable cause = se.getCause();
if ( (cause == null) || !(cause instanceof DerbySQLException )) { return se; }
else { return (SQLException) cause; }
}
Unpack the exception, looking for an DerbySQLException, which carries
the Derby messageID and arguments. |
public final Object[] getArguments() {
return arguments;
}
Returns the arguments for this exception,
if there are any. |
public final int getErrorCode() {
return severity;
}
|
public String getErrorProperty(String type) {
return getErrorProperty(getMessageId(), type);
}
Get the error code for an error given a type. The value of
the property messageId.type will be returned, e.g.
deadlock.sqlstate. |
public String getMessage() {
if (textMessage == null)
textMessage = MessageService.getCompleteMessage(getMessageId(), getArguments());
return textMessage;
}
The message stored in the super class Throwable must be set
up object creation. At this time we cannot get any information
about the object itself (ie. this) in order to determine the
natural language message. Ie. we need to class of the objec in
order to look up its message, but we can't get the class of the
exception before calling the super class message.
Thus the message stored by Throwable and obtained by the
getMessage() of Throwable (ie. super.getMessage() in this
class) is the message identifier. The actual text message
is stored in this class at the first request. |
public final String getMessageId() {
return super.getMessage();
}
Return the message identifier that is used to look up the
error message text in the messages.properties file. |
public final String getSQLState() {
return sqlState;
}
Return the 5 character SQL State.
If you need teh identifier that was used to create the
message, then use getMessageId(). getMessageId() will return the
string that corresponds to the field in org.apache.derby.iapi.reference.SQLState. |
public static String getSQLStateFromIdentifier(String messageID) {
if (messageID.length() == 5)
return messageID;
return messageID.substring(0, 5);
}
Convert a message identifer from org.apache.derby.iapi.reference.SQLState to
a SQLState five character string. |
public final int getSeverity() {
return severity;
}
|
public static int getSeverityFromIdentifier(String messageID) {
int lseverity = ExceptionSeverity.NO_APPLICABLE_SEVERITY;
switch (messageID.length()) {
case 5:
switch (messageID.charAt(0)) {
case '0':
switch (messageID.charAt(1)) {
case '1':
lseverity = ExceptionSeverity.WARNING_SEVERITY;
break;
case 'A':
case '7':
lseverity = ExceptionSeverity.STATEMENT_SEVERITY;
break;
case '8':
lseverity = ExceptionSeverity.SESSION_SEVERITY;
break;
}
break;
case '2':
case '3':
lseverity = ExceptionSeverity.STATEMENT_SEVERITY;
break;
case '4':
switch (messageID.charAt(1)) {
case '0':
lseverity = ExceptionSeverity.TRANSACTION_SEVERITY;
break;
case '2':
lseverity = ExceptionSeverity.STATEMENT_SEVERITY;
break;
}
break;
}
break;
default:
switch (messageID.charAt(6)) {
case 'M':
lseverity = ExceptionSeverity.SYSTEM_SEVERITY;
break;
case 'D':
lseverity = ExceptionSeverity.DATABASE_SEVERITY;
break;
case 'C':
lseverity = ExceptionSeverity.SESSION_SEVERITY;
break;
case 'T':
lseverity = ExceptionSeverity.TRANSACTION_SEVERITY;
break;
case 'S':
lseverity = ExceptionSeverity.STATEMENT_SEVERITY;
break;
case 'U':
lseverity = ExceptionSeverity.NO_APPLICABLE_SEVERITY;
break;
}
break;
}
return lseverity;
}
Get the severity given a message identifier from org.apache.derby.iapi.reference.SQLState. |
public static StandardException interrupt(InterruptedException ie) {
StandardException se = StandardException.newException(SQLState.CONN_INTERRUPT, ie);
return se;
}
|
public static StandardException newException(String messageID) {
return new StandardException(messageID);
}
|
public static StandardException newException(String messageID,
Throwable t) {
return new StandardException(messageID, t, (Object[]) null);
}
|
public static StandardException newException(String messageID,
Object a1) {
Object[] oa = new Object[] {a1};
return new StandardException(messageID, oa);
}
|
public static StandardException newException(String messageID,
Object[] a1) {
return new StandardException(messageID, a1);
}
|
public static StandardException newException(String messageID,
Throwable t,
Object a1) {
Object[] oa = new Object[] {a1};
return new StandardException(messageID, t, oa);
}
|
public static StandardException newException(String messageID,
Object a1,
Object a2) {
Object[] oa = new Object[] {a1, a2};
return new StandardException(messageID, oa);
}
|
public static StandardException newException(String messageID,
Object a1,
Throwable t) throws BadMessageArgumentException {
throw new BadMessageArgumentException();
}
Dummy overload which should never be called. Only used to
detect incorrect usage, at compile time. |
public static StandardException newException(String messageID,
Throwable t,
Object a1,
Object a2) {
Object[] oa = new Object[] {a1, a2};
return new StandardException(messageID, t, oa);
}
|
public static StandardException newException(String messageID,
Object a1,
Object a2,
Object a3) {
Object[] oa = new Object[] {a1, a2, a3};
return new StandardException(messageID, oa);
}
|
public static StandardException newException(String messageID,
Object a1,
Object a2,
Throwable t) throws BadMessageArgumentException {
throw new BadMessageArgumentException();
}
Dummy overload which should never be called. Only used to
detect incorrect usage, at compile time. |
public static StandardException newException(String messageID,
Throwable t,
Object a1,
Object a2,
Object a3) {
Object[] oa = new Object[] {a1, a2, a3};
return new StandardException(messageID, t, oa);
}
|
public static StandardException newException(String messageID,
Object a1,
Object a2,
Object a3,
Object a4) {
Object[] oa = new Object[] {a1, a2, a3, a4};
return new StandardException(messageID, oa);
}
|
public static StandardException newException(String messageID,
Throwable t,
Object a1,
Object a2,
Object a3,
Object a4) {
Object[] oa = new Object[] {a1, a2, a3, a4};
return new StandardException(messageID, t, oa);
}
|
public static StandardException newException(String messageID,
Object a1,
Object a2,
Object a3,
Object a4,
Object a5) {
Object[] oa = new Object[] {a1, a2, a3, a4, a5};
return new StandardException(messageID, oa);
}
|
public static StandardException newException(String messageID,
Throwable t,
Object a1,
Object a2,
Object a3,
Object a4,
Object a5) {
Object[] oa = new Object[] {a1, a2, a3, a4, a5};
return new StandardException(messageID, t, oa);
}
|
public static StandardException newException(String messageID,
Object a1,
Object a2,
Object a3,
Object a4,
Object a5,
Object a6) {
Object[] oa = new Object[] {a1, a2, a3, a4, a5, a6};
return new StandardException(messageID, oa);
}
|
public static StandardException newException(String messageID,
Throwable t,
Object a1,
Object a2,
Object a3,
Object a4,
Object a5,
Object a6) {
Object[] oa = new Object[] {a1, a2, a3, a4, a5, a6};
return new StandardException(messageID, t, oa);
}
|
public static StandardException newException(String messageID,
Object a1,
Object a2,
Object a3,
Object a4,
Object a5,
Object a6,
Object a7) {
Object[] oa = new Object[] {a1, a2, a3, a4, a5, a6, a7};
return new StandardException(messageID, oa);
}
|
public static StandardException newException(String messageID,
Throwable t,
Object a1,
Object a2,
Object a3,
Object a4,
Object a5,
Object a6,
Object a7) {
Object[] oa = new Object[] {a1, a2, a3, a4, a5, a6, a7};
return new StandardException(messageID, t, oa);
}
|
public static StandardException newException(String messageID,
Object a1,
Object a2,
Object a3,
Object a4,
Object a5,
Object a6,
Object a7,
Object a8) {
Object[] oa = new Object[] {a1, a2, a3, a4, a5, a6, a7, a8};
return new StandardException(messageID, oa);
}
|
public static StandardException newException(String messageID,
Throwable t,
Object a1,
Object a2,
Object a3,
Object a4,
Object a5,
Object a6,
Object a7,
Object a8) {
Object[] oa = new Object[] {a1, a2, a3, a4, a5, a6, a7, a8};
return new StandardException(messageID, t, oa);
}
|
public static StandardException newPreLocalizedException(String MessageID,
Throwable t,
String localizedMessage) {
StandardException se = new StandardException( MessageID, localizedMessage);
if( t != null)
se.initCause(t);
return se;
}
Creates a new StandardException using message text that has already been localized. |
public static SQLWarning newWarning(String messageId) {
return newWarningCommon( messageId, (Object[]) null );
}
|
public static SQLWarning newWarning(String messageId,
Object a1) {
Object[] oa = new Object[] {a1};
return newWarningCommon( messageId, oa );
}
|
public static SQLWarning newWarning(String messageId,
Object a1,
Object a2) {
Object[] oa = new Object[] {a1, a2};
return newWarningCommon( messageId, oa );
}
|
public static StandardException normalClose() {
StandardException se = newException( SQLState.NORMAL_CLOSE );
se.report = REPORT_NEVER;
return se;
}
|
public static StandardException plainWrapException(Throwable t) {
if (t instanceof StandardException)
return (StandardException) t;
if (t instanceof SQLException) {
SQLException sqle = (SQLException) t;
String sqlState = sqle.getSQLState();
if (sqlState != null) {
StandardException se = new StandardException(sqlState, "(" + sqle.getErrorCode() + ") " + sqle.getMessage());
sqle = sqle.getNextException();
if (sqle != null)
se.initCause(plainWrapException(sqle));
return se;
}
}
String detailMessage = t.getMessage();
if (detailMessage == null)
{
detailMessage = "";
} else {
detailMessage = detailMessage.trim();
}
StandardException se =
newException(SQLState.JAVA_EXCEPTION, t, detailMessage, t.getClass().getName());
return se;
}
Similar to unexpectedUserException but makes no assumtion about
when the execption is being called. The error is wrapped as simply
as possible. |
public final int report() {
return report;
}
Yes, report me. Errors that need this method to return
false are in the minority. |
public final void setReport(int report) {
this.report = report;
}
|
public final void setSeverity(int severity) {
this.severity = severity;
}
|
public String toString() {
String msg = getMessage();
return "ERROR " + getSQLState() + ": " + msg;
}
Don't print the class name in the toString() method. |
public static StandardException unexpectedUserException(Throwable t) {
// If the exception is an SQLException generated by Derby, it has an
// argument ferry which is an DerbySQLException. Use this to check
// whether the exception was generated by Derby.
DerbySQLException ferry = null;
if (t instanceof SQLException) {
SQLException sqle =
getArgumentFerry((SQLException) t);
if (sqle instanceof DerbySQLException) {
ferry = (DerbySQLException) sqle;
}
}
/*
** If we have a SQLException that isn't an EmbedSQLException
** (i.e. it didn't come from Derby), then we check
** to see if it is a valid user defined exception range
** (38001-38XXX). If so, then we convert it into a
** StandardException without further ado.
*/
if ((t instanceof SQLException) && (ferry == null))
{
SQLException sqlex = (SQLException)t;
String state = sqlex.getSQLState();
if ((state != null) &&
(state.length() == 5) &&
state.startsWith("38") &&
!state.equals("38000"))
{
StandardException se = new StandardException(state, sqlex.getMessage());
if (sqlex.getNextException() != null)
{
se.initCause(sqlex.getNextException());
}
return se;
}
}
// Look for simple wrappers for 3.0.1 - will be cleaned up in main
if (ferry != null) {
if (ferry.isSimpleWrapper()) {
Throwable wrapped = ((SQLException)ferry).getCause();
if (wrapped instanceof StandardException)
return (StandardException) wrapped;
}
}
// no need to wrap a StandardException
if (t instanceof StandardException)
{
return (StandardException) t;
}
else
{
/*
**
** The exception at this point could be a:
**
** standard java exception, e.g. NullPointerException
** SQL Exception - from some server-side JDBC
** 3rd party exception - from some application
** some Derby exception that is not a standard exception.
**
**
** We don't want to call t.toString() here, because the JVM is
** inconsistent about whether it includes a detail message
** with some exceptions (esp. NullPointerException). In those
** cases where there is a detail message, t.toString() puts in
** a colon character, even when the detail message is blank.
** So, we do our own string formatting here, including the colon
** only when there is a non-blank message.
**
** The above is because our test canons contain the text of
** error messages.
**
** In the past we didn't want to place the class name in
** an exception because Cloudscape builds were
** obfuscated, so the class name would change from build
** to build. This is no longer true for Derby, but for
** exceptions that are Derby's, i.e. EmbedSQLException,
** we use toString(). If this returns an empty or null
** then we use the class name to make tracking the
** problem down easier, though the lack of a message
** should be seen as a bug.
*/
String detailMessage;
boolean derbyException = false;
if (ferry != null) {
detailMessage = ferry.toString();
derbyException = true;
}
else {
detailMessage = t.getMessage();
}
if (detailMessage == null)
{
detailMessage = "";
} else {
detailMessage = detailMessage.trim();
}
// if no message, use the class name
if (detailMessage.length() == 0) {
detailMessage = t.getClass().getName();
}
else {
if (!derbyException) {
detailMessage = t.getClass().getName() + ": " + detailMessage;
}
}
StandardException se =
newException(SQLState.LANG_UNEXPECTED_USER_EXCEPTION, t, detailMessage);
return se;
}
}
|