String sqlstate = se.getSQLState();
String message = se.getMessage();
int seErrorCode = se.getErrorCode();
int xaErrorCode;
XAException xae;
// Determine the XAException.errorCode. This is known for
// some specific exceptions. For other exceptions, we will
// return XAER_RMFAIL for SESSION_SEVERITY or greater and
// XAER_RMERR for less severe errors. DERBY-4141.
if (sqlstate.equals(StandardException.getSQLStateFromIdentifier(
SQLState.STORE_XA_XAER_DUPID)))
xaErrorCode = XAException.XAER_DUPID;
else if (sqlstate.equals(StandardException.getSQLStateFromIdentifier(
SQLState.STORE_XA_PROTOCOL_VIOLATION)))
xaErrorCode = XAException.XA_RBPROTO;
else if (sqlstate.equals(SQLState.DEADLOCK))
xaErrorCode = XAException.XA_RBDEADLOCK;
else if (sqlstate.equals(SQLState.LOCK_TIMEOUT))
xaErrorCode = XAException.XA_RBTIMEOUT;
else if (seErrorCode >= ExceptionSeverity.SESSION_SEVERITY)
xaErrorCode = XAException.XAER_RMFAIL;
else
xaErrorCode = XAException.XAER_RMERR;
xae = new XAException(message);
xae.errorCode = xaErrorCode;
if (JVMInfo.JDK_ID >= JVMInfo.J2SE_14)
xae.initCause(se);
return xae;
}