use of org.apache.derby.shared.common.error.StandardException in project derby by apache.
the class EmbedXAResource method forget.
/**
* Tell the resource manager to forget about a heuristically completed
* transaction branch.
*
* @param xid A global transaction identifier
* @exception XAException An error has occurred. Possible exception values
* are XAER_RMERR, XAER_RMFAIL, XAER_NOTA, XAER_INVAL, or XAER_PROTO.
*/
public final synchronized void forget(Xid xid) throws XAException {
checkXAActive();
// ensure immtable and correct equals method.
XAXactId xid_im = new XAXactId(xid);
XATransactionState tranState = getTransactionState(xid_im);
if (tranState == null) {
XAResourceManager rm = ra.getXAResourceManager();
ContextManager inDoubtCM = rm.find(xid);
// RM also does not know about this xid.
if (inDoubtCM == null)
throw new XAException(XAException.XAER_NOTA);
ContextService csf = getContextService();
csf.setCurrentContextManager(inDoubtCM);
try {
rm.forget(inDoubtCM, xid_im);
// close the connection/transaction since it can never be used again.
inDoubtCM.cleanupOnError(StandardException.closeException(), false);
return;
} catch (StandardException se) {
// The rm threw an exception, clean it up in the approprate
// context. There is no transactionResource to handle the
// exception for us.
inDoubtCM.cleanupOnError(se, con.isActive());
throw wrapInXAException(se);
} finally {
csf.resetCurrentContextManager(inDoubtCM);
}
}
// DERBY-1016; if the transaction exists throw XAER_PROTO on forget
throw new XAException(XAException.XAER_PROTO);
}
use of org.apache.derby.shared.common.error.StandardException in project derby by apache.
the class EmbedXAResource method rollback.
/**
* Inform the resource manager to roll back work done on behalf of a
* transaction branch
*
* @param xid A global transaction identifier
* @exception XAException - An error has occurred
*/
public final synchronized void rollback(Xid xid) throws XAException {
checkXAActive();
// ensure immtable and correct equals method.
XAXactId xid_im = new XAXactId(xid);
XATransactionState tranState = getTransactionState(xid_im);
if (tranState == null) {
XAResourceManager rm = ra.getXAResourceManager();
ContextManager inDoubtCM = rm.find(xid);
// RM also does not know about this xid.
if (inDoubtCM == null)
throw new XAException(XAException.XAER_NOTA);
ContextService csf = getContextService();
csf.setCurrentContextManager(inDoubtCM);
try {
rm.rollback(inDoubtCM, xid_im);
// close the connection/transaction since it can never be used again.
inDoubtCM.cleanupOnError(StandardException.closeException(), false);
return;
} catch (StandardException se) {
// The rm threw an exception, clean it up in the approprate
// context. There is no transactionResource to handle the
// exception for us.
inDoubtCM.cleanupOnError(se, con.isActive());
throw wrapInXAException(se);
} finally {
csf.resetCurrentContextManager(inDoubtCM);
}
}
synchronized (tranState) {
// any XAResource.
switch(tranState.associationState) {
case XATransactionState.T0_NOT_ASSOCIATED:
case XATransactionState.TRO_FAIL:
break;
default:
throw new XAException(XAException.XAER_PROTO);
}
if (tranState.suspendedList != null && tranState.suspendedList.size() != 0)
throw new XAException(XAException.XAER_PROTO);
checkUserCredentials(tranState.creatingResource);
try {
tranState.xa_rollback();
} catch (SQLException sqle) {
throw wrapInXAException(sqle);
} finally {
returnConnectionToResource(tranState, xid_im);
}
}
}
use of org.apache.derby.shared.common.error.StandardException in project derby by apache.
the class TemporaryClob method getInternalReader.
/**
* @see #getReader
*/
public Reader getInternalReader(long characterPosition) throws IOException, SQLException {
if (this.internalReader == null) {
// getCSD obtains a descriptor for the stream to allow the reader
// to configure itself.
this.internalReader = new UTF8Reader(getCSD(), conChild, conChild.getConnectionSynchronization());
this.unclosableInternalReader = new FilterReader(this.internalReader) {
public void close() {
// Do nothing.
// Stream will be closed when the Clob is released.
}
};
}
try {
this.internalReader.reposition(characterPosition);
} catch (StandardException se) {
throw Util.generateCsSQLException(se);
}
return this.unclosableInternalReader;
}
use of org.apache.derby.shared.common.error.StandardException in project derby by apache.
the class TransactionResourceImpl method shutdownDatabaseException.
StandardException shutdownDatabaseException() {
StandardException se = StandardException.newException(SQLState.SHUTDOWN_DATABASE, getDBName());
se.setReport(StandardException.REPORT_NEVER);
return se;
}
use of org.apache.derby.shared.common.error.StandardException in project derby by apache.
the class TransactionResourceImpl method handleException.
/*
* exception handling
*/
/**
* clean up the error and wrap the real exception in some SQLException.
*/
final SQLException handleException(Throwable thrownException, boolean autoCommit, boolean rollbackOnAutoCommit) throws SQLException {
try {
if (SanityManager.DEBUG)
SanityManager.ASSERT(thrownException != null);
/*
just pass SQL exceptions right back. We assume that JDBC driver
code has cleaned up sufficiently. Not passing them through would mean
that all cleanupOnError methods would require knowledge of Utils.
*/
if (thrownException instanceof SQLException) {
InterruptStatus.restoreIntrFlagIfSeen();
return (SQLException) thrownException;
}
boolean checkForShutdown = false;
if (thrownException instanceof StandardException) {
StandardException se = (StandardException) thrownException;
int severity = se.getSeverity();
if (severity <= ExceptionSeverity.STATEMENT_SEVERITY) {
/*
** If autocommit is on, then do a rollback
** to release locks if requested. We did a stmt
** rollback in the cleanupOnError above, but we still
** may hold locks from the stmt.
*/
if (autoCommit && rollbackOnAutoCommit) {
se.setSeverity(ExceptionSeverity.TRANSACTION_SEVERITY);
}
} else if (SQLState.CONN_INTERRUPT.equals(se.getMessageId())) {
// an interrupt closed the connection.
checkForShutdown = true;
}
}
// JDBC objects.
if (cm != null) {
// diagActive should be passed to cleanupOnError
// only if a session is active, Login errors are a special case where
// the database is active but the session is not.
boolean sessionActive = (database != null) && database.isActive() && !isLoginException(thrownException);
boolean isShutdown = cleanupOnError(thrownException, sessionActive);
if (checkForShutdown && isShutdown) {
// Change the error message to be a known shutdown.
thrownException = shutdownDatabaseException();
}
}
InterruptStatus.restoreIntrFlagIfSeen();
return wrapInSQLException(thrownException);
} catch (Throwable t) {
if (cm != null) {
// something to let us cleanup?
cm.cleanupOnError(t, database != null ? isActive() : false);
}
InterruptStatus.restoreIntrFlagIfSeen();
/*
We'd rather throw the Throwable,
but then javac complains...
We assume if we are in this degenerate
case that it is actually a java exception
*/
throw wrapInSQLException(t);
// throw t;
}
}
Aggregations