Search in sources :

Example 41 with SystemException

use of javax.transaction.SystemException in project wildfly by wildfly.

the class TestEJBRunnable method run.

@Override
public void run() {
    // asserts correct class loader is set
    try {
        Thread.currentThread().getContextClassLoader().loadClass(this.getClass().getName());
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);
    }
    // asserts correct naming context is set
    final InitialContext initialContext;
    try {
        initialContext = new InitialContext();
    } catch (NamingException e) {
        throw new RuntimeException(e);
    }
    final EJBContext ejbContext;
    try {
        ejbContext = (SessionContext) initialContext.lookup("java:comp/EJBContext");
    } catch (NamingException e) {
        throw new RuntimeException(e);
    }
    // asserts correct security context is set
    final Principal callerPrincipal = ejbContext.getCallerPrincipal();
    if (expectedPrincipal != null) {
        if (!expectedPrincipal.equals(callerPrincipal)) {
            throw new IllegalStateException("the caller principal " + callerPrincipal + " is not the expected " + expectedPrincipal);
        }
    } else {
        if (callerPrincipal != null) {
            throw new IllegalStateException("the caller principal " + callerPrincipal + " is not the expected " + expectedPrincipal);
        }
    }
    // assert tx context is set
    try {
        final UserTransaction userTransaction = (UserTransaction) initialContext.lookup("java:comp/UserTransaction");
        userTransaction.begin();
        userTransaction.rollback();
    } catch (NamingException | SystemException | NotSupportedException e) {
        throw new RuntimeException(e);
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) EJBContext(javax.ejb.EJBContext) SystemException(javax.transaction.SystemException) NamingException(javax.naming.NamingException) NotSupportedException(javax.transaction.NotSupportedException) InitialContext(javax.naming.InitialContext) Principal(java.security.Principal)

Example 42 with SystemException

use of javax.transaction.SystemException in project wildfly by wildfly.

the class BMTStateful method createTransaction.

public void createTransaction() {
    try {
        final UserTransaction userTransaction = ejbContext.getUserTransaction();
        Assert.assertEquals(Status.STATUS_NO_TRANSACTION, userTransaction.getStatus());
        userTransaction.begin();
    } catch (SystemException e) {
        throw new RuntimeException(e);
    } catch (NotSupportedException e) {
        throw new RuntimeException(e);
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) SystemException(javax.transaction.SystemException) NotSupportedException(javax.transaction.NotSupportedException)

Example 43 with SystemException

use of javax.transaction.SystemException in project wildfly by wildfly.

the class BMTStateful method rollbackTransaction.

public void rollbackTransaction() {
    try {
        final UserTransaction userTransaction = ejbContext.getUserTransaction();
        Assert.assertEquals(Status.STATUS_ACTIVE, userTransaction.getStatus());
        userTransaction.rollback();
    } catch (SystemException e) {
        throw new RuntimeException(e);
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) SystemException(javax.transaction.SystemException)

Example 44 with SystemException

use of javax.transaction.SystemException in project wildfly by wildfly.

the class JBossContextXATerminator method startWork.

/**
     * <p>
     * Start work gets imported transaction and assign it to current thread.
     * <p>
     * This method mimics behavior of Narayana's {@link JBossXATerminator}.
     */
@Override
public void startWork(Work work, Xid xid) throws WorkCompletedException {
    LocalTransaction transaction = null;
    try {
        ImportResult<LocalTransaction> transactionImportResult = localTransactionContext.findOrImportTransaction(xid, 0);
        transaction = transactionImportResult.getTransaction();
        ContextTransactionManager.getInstance().resume(transaction);
    } catch (XAException xae) {
        throw TransactionLogger.ROOT_LOGGER.cannotFindOrImportInflowTransaction(xid, work, xae);
    } catch (InvalidTransactionException ite) {
        throw TransactionLogger.ROOT_LOGGER.importedInflowTransactionIsInactive(xid, work, ite);
    } catch (SystemException se) {
        throw TransactionLogger.ROOT_LOGGER.cannotResumeInflowTransactionUnexpectedError(transaction, work, se);
    }
}
Also used : XAException(javax.transaction.xa.XAException) LocalTransaction(org.wildfly.transaction.client.LocalTransaction) SystemException(javax.transaction.SystemException) InvalidTransactionException(javax.transaction.InvalidTransactionException)

Example 45 with SystemException

use of javax.transaction.SystemException in project wildfly by wildfly.

the class TransactionSynchronizationRegistryWrapper method registerInterposedSynchronization.

@Override
public void registerInterposedSynchronization(Synchronization sync) throws IllegalStateException {
    try {
        Transaction tx = transactionManager.getTransaction();
        JCAOrderedLastSynchronizationList jcaOrderedLastSynchronization = interposedSyncs.get(tx);
        if (jcaOrderedLastSynchronization == null) {
            JCAOrderedLastSynchronizationList toPut = new JCAOrderedLastSynchronizationList((com.arjuna.ats.jta.transaction.Transaction) tx, interposedSyncs);
            jcaOrderedLastSynchronization = interposedSyncs.putIfAbsent(tx, toPut);
            if (jcaOrderedLastSynchronization == null) {
                jcaOrderedLastSynchronization = toPut;
                delegate.registerInterposedSynchronization(jcaOrderedLastSynchronization);
            }
        }
        jcaOrderedLastSynchronization.registerInterposedSynchronization(sync);
    } catch (SystemException e) {
        throw new IllegalStateException(e);
    }
}
Also used : Transaction(javax.transaction.Transaction) SystemException(javax.transaction.SystemException)

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