Search in sources :

Example 91 with SystemException

use of javax.transaction.SystemException in project geode by apache.

the class JCAConnectionManagerImpl method connectionErrorOccurred.

/**
   * CallBack for Connection Error.
   * 
   * @param event ConnectionEvent
   */
public void connectionErrorOccurred(ConnectionEvent event) {
    if (isActive) {
        // If its an XAConnection
        ManagedConnection conn = (ManagedConnection) event.getSource();
        XAResource xar = (XAResource) xaResourcesMap.get(conn);
        xaResourcesMap.remove(conn);
        TransactionManagerImpl transManager = TransactionManagerImpl.getTransactionManager();
        try {
            Transaction txn = transManager.getTransaction();
            if (txn != null && xar != null)
                txn.delistResource(xar, XAResource.TMSUCCESS);
        } catch (SystemException se) {
            se.printStackTrace();
        }
        try {
            mannPoolCache.expirePooledConnection(conn);
        // mannPoolCache.destroyPooledConnection(conn);
        } catch (Exception ex) {
            String exception = "JCAConnectionManagerImpl::connectionErrorOccurred: Exception occurred due to " + ex;
            if (logger.isDebugEnabled()) {
                logger.debug(exception, ex);
            }
        }
    }
}
Also used : XAResource(javax.transaction.xa.XAResource) Transaction(javax.transaction.Transaction) SystemException(javax.transaction.SystemException) TransactionManagerImpl(org.apache.geode.internal.jta.TransactionManagerImpl) ManagedConnection(javax.resource.spi.ManagedConnection) ResourceException(javax.resource.ResourceException) SystemException(javax.transaction.SystemException) RollbackException(javax.transaction.RollbackException)

Example 92 with SystemException

use of javax.transaction.SystemException in project geode by apache.

the class FacetsJCAConnectionManagerImpl method allocateConnection.

/*
   * allocates a ManagedConnection from the ConnectionPool or creates a new
   * ManagedConnection. @param javax.resource.spi.ManagedConnectionFactory
   * 
   * @param javax.resource.spi.ConnectionRequestInfo
   * 
   * @throws ResourceException
   */
public Object allocateConnection(ManagedConnectionFactory mcf, ConnectionRequestInfo reqInfo) throws ResourceException {
    if (!isActive) {
        throw new ResourceException(LocalizedStrings.FacetsJCAConnectionManagerImpl_FACETSJCACONNECTIONMANAGERIMPLALLOCATECONNECTIONNO_VALID_CONNECTION_AVAILABLE.toLocalizedString());
    }
    ManagedConnection conn = null;
    try {
        conn = (ManagedConnection) mannPoolCache.getPooledConnectionFromPool();
    } catch (PoolException ex) {
        ex.printStackTrace();
        throw new ResourceException(LocalizedStrings.FacetsJCAConnectionManagerImpl_FACETSJCACONNECTIONMANAGERIMPL_ALLOCATECONNECTION_IN_GETTING_CONNECTION_FROM_POOL_DUE_TO_0.toLocalizedString(ex.getMessage()), ex);
    }
    // Transaction Manager.
    try {
        synchronized (this) {
            if (transManager == null) {
                transManager = JNDIInvoker.getTransactionManager();
            }
        }
        Transaction txn = transManager.getTransaction();
        if (txn != null) {
            // Check if Data Source provides XATransaction
            // if(configs.getTransactionType = "XATransaction")
            XAResource xar = conn.getXAResource();
            txn.enlistResource(xar);
            java.util.List resList = (List) xalistThreadLocal.get();
            if (resList.size() == 0) {
                // facets specific implementation
                // register syschronisation only once
                txn.registerSynchronization(this);
            }
            resList.add(conn);
        // xalistThreadLocal.set(resList);
        // Asif :Add in the Map after successful registration of XAResource
        // xaResourcesMap.put(conn, xar);
        // else throw a resource exception
        }
    } catch (RollbackException ex) {
        String exception = LocalizedStrings.FacetsJCAConnectionManagerImpl_FACETSJCACONNECTIONMANAGERIMPL_AN_EXCEPTION_WAS_CAUGHT_WHILE_ALLOCATING_A_CONNECTION_DUE_TO_0.toLocalizedString(ex.getMessage());
        throw new ResourceException(exception, ex);
    } catch (SystemException ex) {
        throw new ResourceException(LocalizedStrings.FacetsJCAConnectionManagerImpl_FACETSJCACONNECTIONMANAGERIMPL_ALLOCATECONNECTION_SYSTEM_EXCEPTION_DUE_TO_0.toLocalizedString(ex.getMessage()), ex);
    }
    return conn.getConnection(subject, reqInfo);
}
Also used : XAResource(javax.transaction.xa.XAResource) List(java.util.List) Transaction(javax.transaction.Transaction) SystemException(javax.transaction.SystemException) ResourceException(javax.resource.ResourceException) ManagedConnection(javax.resource.spi.ManagedConnection) ArrayList(java.util.ArrayList) List(java.util.List) RollbackException(javax.transaction.RollbackException)

Example 93 with SystemException

use of javax.transaction.SystemException in project geode by apache.

the class TransactionManagerImpl method setTransactionTimeout.

/**
   * not supported
   * 
   * @see javax.transaction.TransactionManager#setTransactionTimeout(int)
   */
public void setTransactionTimeout(int seconds) throws SystemException {
    if (!isActive) {
        throw new SystemException(LocalizedStrings.TransactionManagerImpl_TRANSACTIONMANAGER_INVALID.toLocalizedString());
    }
    GlobalTransaction gtx = getGlobalTransaction();
    if (gtx == null) {
        String exception = LocalizedStrings.TransactionManagerImpl_TRANSACTIONMANAGERIMPL_SETTRANSACTIONTIMEOUT_NO_GLOBAL_TRANSACTION_EXISTS.toLocalizedString();
        LogWriterI18n writer = TransactionUtils.getLogWriterI18n();
        if (VERBOSE)
            writer.fine(exception);
        throw new SystemException(exception);
    }
    long newExpiry = gtx.setTransactionTimeoutForXARes(seconds);
    if (newExpiry > 0) {
        // long expirationTime = System.currentTimeMillis() + (seconds * 1000);
        gtxSet.remove(gtx);
        // Asif :Lets blindly remove the current gtx from the TreeMap &
        // Add only if status is neither Rolledback, Unknown , committed or no
        // transaction or GTX not
        // expired, which gurantees that the client thread will be returning &
        // cleaning up .so we
        // don't add it
        int status = gtx.getStatus();
        if (status != Status.STATUS_NO_TRANSACTION && status != Status.STATUS_COMMITTED && status != Status.STATUS_ROLLEDBACK && !gtx.isExpired()) {
            // Asif : Take a lock on GTX while setting the new Transaction timeout
            // value,
            // so that cleaner thread sees the new value immediately else due to
            // volatility issue
            // we may have inconsistent values of time out
            boolean toAdd = false;
            synchronized (gtx) {
                if (!gtx.isExpired()) {
                    gtx.setTimeoutValue(newExpiry);
                    toAdd = true;
                }
            }
            // of it.
            if (toAdd) {
                synchronized (gtxSet) {
                    gtxSet.add(gtx);
                    if (gtxSet.first() == gtx) {
                        gtxSet.notify();
                    }
                }
            }
        } else {
            String exception = LocalizedStrings.TransactionManagerImpl_TRANSACTIONMANAGERIMPL_SETTRANSACTIONTIMEOUT_TRANSACTION_HAS_EITHER_EXPIRED_OR_ROLLEDBACK_OR_COMITTED.toLocalizedString();
            LogWriterI18n writer = TransactionUtils.getLogWriterI18n();
            if (VERBOSE)
                writer.fine(exception);
            throw new SystemException(exception);
        }
    }
}
Also used : SystemException(javax.transaction.SystemException) LogWriterI18n(org.apache.geode.i18n.LogWriterI18n)

Example 94 with SystemException

use of javax.transaction.SystemException in project geode by apache.

the class TransactionManagerImpl method suspend.

/**
   * @see javax.transaction.TransactionManager#suspend()
   */
public Transaction suspend() throws SystemException {
    if (!isActive) {
        throw new SystemException(LocalizedStrings.TransactionManagerImpl_TRANSACTIONMANAGER_INVALID.toLocalizedString());
    }
    Transaction txn = getTransaction();
    if (null != txn) {
        GlobalTransaction gtx = getGlobalTransaction(txn);
        gtx.suspend();
        transactionMap.remove(Thread.currentThread());
        LogWriterI18n writer = TransactionUtils.getLogWriterI18n();
        if (writer.infoEnabled())
            writer.info(LocalizedStrings.TransactionManagerImpl_TRANSACTIONMANAGERIMPLSUSPENDTRANSACTION_SUSPENDED);
    }
    return txn;
}
Also used : SystemException(javax.transaction.SystemException) Transaction(javax.transaction.Transaction) LogWriterI18n(org.apache.geode.i18n.LogWriterI18n)

Example 95 with SystemException

use of javax.transaction.SystemException in project geode by apache.

the class TransactionManagerImpl method rollback.

/**
   * Rolls back the transaction associated with the current thread by calling the
   * GlobalTransaction.rollback(). When this method completes, the thread is no longer associated
   * with a transaction.
   * 
   * @throws java.lang.SecurityException - Thrown to indicate that the thread is not allowed to
   *         commit the transaction.
   * @throws java.lang.IllegalStateException - Thrown if the current thread is not associated with a
   *         transaction.
   * @throws SystemException - Thrown if the transaction manager encounters an unexpected error
   *         condition.
   * 
   * @see javax.transaction.TransactionManager#commit()
   */
public void rollback() throws IllegalStateException, SecurityException, SystemException {
    if (!isActive) {
        throw new SystemException(LocalizedStrings.TransactionManagerImpl_TRANSACTIONMANAGER_INVALID.toLocalizedString());
    }
    // boolean isRollingBack = false;
    LogWriterI18n writer = TransactionUtils.getLogWriterI18n();
    Transaction transactionImpl = getTransaction();
    if (transactionImpl == null) {
        String exception = LocalizedStrings.TransactionManagerImpl_TRANSACTIONMANAGERIMPL_ROLLBACK_NO_TRANSACTION_EXISTS.toLocalizedString();
        if (VERBOSE)
            writer.fine(exception);
        throw new IllegalStateException(exception);
    }
    GlobalTransaction gtx = getGlobalTransaction(transactionImpl);
    if (gtx == null) {
        String exception = LocalizedStrings.TransactionManagerImpl_TRANSACTIONMANAGERIMPL_ROLLBACK_NO_GLOBAL_TRANSACTION_EXISTS.toLocalizedString();
        if (VERBOSE)
            writer.fine(exception);
        throw new SystemException(exception);
    }
    int status = gtx.getStatus();
    if (!(status == Status.STATUS_ACTIVE || status == Status.STATUS_MARKED_ROLLBACK)) {
        String exception = LocalizedStrings.TransactionManagerImpl_TRANSACTIONMANAGERIMPL_ROLLBACK_TRANSACTION_STATUS_DOES_NOT_ALLOW_ROLLBACK_TRANSACTIONAL_STATUS_0.toLocalizedString(Integer.valueOf(status));
        if (VERBOSE)
            writer.fine(exception);
        throw new IllegalStateException(exception);
    }
    // ensure only one thread proceeds from here
    status = -1;
    synchronized (gtx) {
        if ((status = gtx.getStatus()) == Status.STATUS_ACTIVE || status == Status.STATUS_MARKED_ROLLBACK)
            gtx.setStatus(Status.STATUS_ROLLING_BACK);
        else if (gtx.getStatus() == Status.STATUS_ROLLING_BACK) {
            String exception = LocalizedStrings.TransactionManagerImpl_TRANSACTIONMANAGERIMPL_ROLLBACK_TRANSACTION_ALREADY_IN_A_ROLLING_BACK_STATE_TRANSACTIONAL_STATUS_0.toLocalizedString(Integer.valueOf(status));
            if (VERBOSE)
                writer.fine(exception);
            throw new IllegalStateException(exception);
        } else {
            String exception = LocalizedStrings.TransactionManagerImpl_TRANSACTIONMANAGERIMPL_ROLLBACK_TRANSACTION_STATUS_DOES_NOT_ALLOW_ROLLBACK.toLocalizedString();
            if (VERBOSE)
                writer.fine(exception);
            throw new IllegalStateException(exception);
        }
    }
    // Only one thread can call rollback (the first thread to do reach the
    // block above).
    // Before rollback the notifications to be done before the done are called
    // the global transaction is called and then the after completion
    // notifications
    // are taken care of. The transactions associated to the global
    // transactions are
    // removed from the map and also the tread to transaction.
    //
    // TODO remove all threads-transactions (from the map)
    // for transactions participating in the global transaction
    //
    SystemException se = null;
    try {
        gtx.rollback();
    } catch (SystemException se1) {
        se = se1;
    }
    try {
        ((TransactionImpl) transactionImpl).notifyAfterCompletion(gtx.getStatus());
    } catch (Exception e1) {
        if (writer.infoEnabled())
            writer.info(LocalizedStrings.TransactionManagerImpl_EXCEPTION_IN_NOTIFY_AFTER_COMPLETION_DUE_TO__0, e1.getMessage(), e1);
    }
    Thread thread = Thread.currentThread();
    transactionMap.remove(thread);
    this.gtxSet.remove(gtx);
    if (se != null) {
        if (VERBOSE)
            writer.fine(se);
        throw se;
    }
    gtx.setStatus(Status.STATUS_NO_TRANSACTION);
}
Also used : SystemException(javax.transaction.SystemException) Transaction(javax.transaction.Transaction) LogWriterI18n(org.apache.geode.i18n.LogWriterI18n) HeuristicRollbackException(javax.transaction.HeuristicRollbackException) InvalidTransactionException(javax.transaction.InvalidTransactionException) NotSupportedException(javax.transaction.NotSupportedException) SystemException(javax.transaction.SystemException) RollbackException(javax.transaction.RollbackException) HeuristicMixedException(javax.transaction.HeuristicMixedException) CancelException(org.apache.geode.CancelException)

Aggregations

SystemException (javax.transaction.SystemException)102 Transaction (javax.transaction.Transaction)34 RollbackException (javax.transaction.RollbackException)29 NotSupportedException (javax.transaction.NotSupportedException)22 HeuristicRollbackException (javax.transaction.HeuristicRollbackException)18 IOException (java.io.IOException)16 HeuristicMixedException (javax.transaction.HeuristicMixedException)16 UserTransaction (javax.transaction.UserTransaction)14 XAException (javax.transaction.xa.XAException)13 Test (org.junit.Test)12 TransactionManager (javax.transaction.TransactionManager)11 SQLException (java.sql.SQLException)10 LogWriterI18n (org.apache.geode.i18n.LogWriterI18n)10 InvalidTransactionException (javax.transaction.InvalidTransactionException)9 JtaTransactionManager (org.springframework.transaction.jta.JtaTransactionManager)8 TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)8 TransactionTemplate (org.springframework.transaction.support.TransactionTemplate)8 XAResource (javax.transaction.xa.XAResource)7 Synchronization (javax.transaction.Synchronization)6 File (java.io.File)5