Search in sources :

Example 31 with StandardException

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);
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) XAXactId(org.apache.derby.iapi.store.access.xa.XAXactId) ContextService(org.apache.derby.iapi.services.context.ContextService) XAException(javax.transaction.xa.XAException) XAResourceManager(org.apache.derby.iapi.store.access.xa.XAResourceManager) ContextManager(org.apache.derby.iapi.services.context.ContextManager)

Example 32 with StandardException

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);
        }
    }
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) XAXactId(org.apache.derby.iapi.store.access.xa.XAXactId) ContextService(org.apache.derby.iapi.services.context.ContextService) XAException(javax.transaction.xa.XAException) XAResourceManager(org.apache.derby.iapi.store.access.xa.XAResourceManager) SQLException(java.sql.SQLException) ContextManager(org.apache.derby.iapi.services.context.ContextManager)

Example 33 with StandardException

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;
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) FilterReader(java.io.FilterReader)

Example 34 with StandardException

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;
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException)

Example 35 with StandardException

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;
    }
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) SQLException(java.sql.SQLException)

Aggregations

StandardException (org.apache.derby.shared.common.error.StandardException)276 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)43 LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)37 IOException (java.io.IOException)32 Properties (java.util.Properties)29 RawTransaction (org.apache.derby.iapi.store.raw.xact.RawTransaction)27 TransactionController (org.apache.derby.iapi.store.access.TransactionController)26 ContextManager (org.apache.derby.iapi.services.context.ContextManager)22 RawContainerHandle (org.apache.derby.iapi.store.raw.data.RawContainerHandle)20 SQLException (java.sql.SQLException)17 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)17 DataDictionary (org.apache.derby.iapi.sql.dictionary.DataDictionary)16 ConglomerateController (org.apache.derby.iapi.store.access.ConglomerateController)12 RowLocation (org.apache.derby.iapi.types.RowLocation)11 SQLLongint (org.apache.derby.iapi.types.SQLLongint)11 StorageFile (org.apache.derby.io.StorageFile)10 TableDescriptor (org.apache.derby.iapi.sql.dictionary.TableDescriptor)9 ScanController (org.apache.derby.iapi.store.access.ScanController)9 File (java.io.File)8 LogInstant (org.apache.derby.iapi.store.raw.log.LogInstant)8