Search in sources :

Example 21 with JavaEETransaction

use of com.sun.enterprise.transaction.api.JavaEETransaction in project Payara by payara.

the class JavaEETransactionManagerSimplified method rollback.

public void rollback() throws IllegalStateException, SecurityException, SystemException {
    boolean acquiredlock = false;
    try {
        JavaEETransaction tx = transactions.get();
        if (tx != null && tx.isLocalTx()) {
            if (monitoringEnabled) {
                // XXX acquireReadLock();
                getDelegate().getReadLock().lock();
                acquiredlock = true;
            }
            // rollback local tx
            tx.rollback();
        } else {
            try {
                // an XA transaction
                getDelegate().rollbackDistributedTransaction();
            } finally {
                if (tx != null) {
                    ((JavaEETransactionImpl) tx).onTxCompletion(false);
                }
            }
        }
        if (requestTracing != null && getRequestTracing().isRequestTracingEnabled()) {
            RequestTraceSpanLog spanLog = constructJTAEndSpanLog(tx);
            getRequestTracing().addSpanLog(spanLog);
        }
    } finally {
        // clear current thread's tx
        setCurrentTransaction(null);
        delegates.set(null);
        if (acquiredlock) {
            // XXX releaseReadLock();
            getDelegate().getReadLock().unlock();
        }
    }
}
Also used : JavaEETransaction(com.sun.enterprise.transaction.api.JavaEETransaction) RequestTraceSpanLog(fish.payara.notification.requesttracing.RequestTraceSpanLog)

Example 22 with JavaEETransaction

use of com.sun.enterprise.transaction.api.JavaEETransaction in project Payara by payara.

the class JavaEETransactionManagerJTSDelegate method getStatus.

public int getStatus() throws SystemException {
    JavaEETransaction tx = javaEETM.getCurrentTransaction();
    int status = javax.transaction.Status.STATUS_NO_TRANSACTION;
    TransactionManager tm = tmLocal.get();
    if (tx != null)
        status = tx.getStatus();
    else if (tm != null)
        status = tm.getStatus();
    if (_logger.isLoggable(Level.FINE))
        _logger.log(Level.FINE, "TM: status: " + JavaEETransactionManagerSimplified.getStatusAsString(status));
    return status;
}
Also used : JavaEETransaction(com.sun.enterprise.transaction.api.JavaEETransaction) JavaEETransactionManager(com.sun.enterprise.transaction.api.JavaEETransactionManager)

Example 23 with JavaEETransaction

use of com.sun.enterprise.transaction.api.JavaEETransaction in project Payara by payara.

the class JavaEETransactionManagerJTSDelegate method getTransaction.

public Transaction getTransaction() throws SystemException {
    JavaEETransaction tx = javaEETM.getCurrentTransaction();
    if (_logger.isLoggable(Level.FINE))
        _logger.log(Level.FINE, "TM: getTransaction: tx=" + tx + ", tm=" + tmLocal.get());
    if (tx != null)
        return tx;
    // Check for a JTS imported tx
    TransactionInternal jtsTx = null;
    TransactionManager tm = tmLocal.get();
    if (tm != null) {
        jtsTx = (TransactionInternal) tm.getTransaction();
    }
    if (jtsTx == null)
        return null;
    else {
        // check if this JTS Transaction was previously active
        // in this JVM (possible for distributed loopbacks).
        tx = (JavaEETransaction) globalTransactions.get(jtsTx);
        if (_logger.isLoggable(Level.FINE))
            _logger.log(Level.FINE, "TM: getTransaction: tx=" + tx + ", jtsTx=" + jtsTx);
        if (tx == null) {
            tx = ((JavaEETransactionManagerSimplified) javaEETM).createImportedTransaction(jtsTx);
            globalTransactions.put(jtsTx, tx);
        }
        // associate tx with thread
        javaEETM.setCurrentTransaction(tx);
        return tx;
    }
}
Also used : JavaEETransaction(com.sun.enterprise.transaction.api.JavaEETransaction) JavaEETransactionManager(com.sun.enterprise.transaction.api.JavaEETransactionManager) TransactionInternal(com.sun.enterprise.transaction.spi.TransactionInternal)

Example 24 with JavaEETransaction

use of com.sun.enterprise.transaction.api.JavaEETransaction in project Payara by payara.

the class AsynchronousTask method enlistExtendedEntityManagers.

@Override
protected void enlistExtendedEntityManagers(ComponentContext ctx) {
    if (ctx.getTransaction() != null) {
        JavaEETransaction j2eeTx = (JavaEETransaction) ctx.getTransaction();
        SessionContextImpl sessionCtx = (SessionContextImpl) ctx;
        Map<EntityManagerFactory, PhysicalEntityManagerWrapper> entityManagerMap = sessionCtx.getExtendedEntityManagerMap();
        for (Map.Entry<EntityManagerFactory, PhysicalEntityManagerWrapper> entry : entityManagerMap.entrySet()) {
            EntityManagerFactory emf = entry.getKey();
            PhysicalEntityManagerWrapper extendedEm = entry.getValue();
            PhysicalEntityManagerWrapper extendedEmAssociatedWithTx = EntityManagerWrapper.getExtendedEntityManager(j2eeTx, emf);
            // this extended EntityManagerFactory within the current tx
            if (extendedEmAssociatedWithTx == null) {
                j2eeTx.addExtendedEntityManagerMapping(emf, extendedEm);
                sessionCtx.setEmfRegisteredWithTx(emf, true);
                // entity manager with the transaction.
                if (extendedEm.getSynchronizationType() == SYNCHRONIZED) {
                    extendedEm.getEM().joinTransaction();
                }
            }
        }
    }
}
Also used : JavaEETransaction(com.sun.enterprise.transaction.api.JavaEETransaction) PhysicalEntityManagerWrapper(com.sun.enterprise.container.common.impl.PhysicalEntityManagerWrapper) EntityManagerFactory(javax.persistence.EntityManagerFactory) Map(java.util.Map) HashMap(java.util.HashMap)

Example 25 with JavaEETransaction

use of com.sun.enterprise.transaction.api.JavaEETransaction in project Payara by payara.

the class AsynchronousTask method delistExtendedEntityManagers.

@Override
protected void delistExtendedEntityManagers(ComponentContext ctx) {
    if (ctx.getTransaction() != null) {
        SessionContextImpl sessionCtx = (SessionContextImpl) ctx;
        JavaEETransaction j2eeTx = (JavaEETransaction) sessionCtx.getTransaction();
        Map<EntityManagerFactory, PhysicalEntityManagerWrapper> entityManagerMap = sessionCtx.getExtendedEntityManagerMap();
        for (Map.Entry<EntityManagerFactory, PhysicalEntityManagerWrapper> entry : entityManagerMap.entrySet()) {
            EntityManagerFactory emf = entry.getKey();
            if (sessionCtx.isEmfRegisteredWithTx(emf)) {
                j2eeTx.removeExtendedEntityManagerMapping(emf);
                sessionCtx.setEmfRegisteredWithTx(emf, false);
            }
        }
    }
}
Also used : JavaEETransaction(com.sun.enterprise.transaction.api.JavaEETransaction) PhysicalEntityManagerWrapper(com.sun.enterprise.container.common.impl.PhysicalEntityManagerWrapper) EntityManagerFactory(javax.persistence.EntityManagerFactory) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

JavaEETransaction (com.sun.enterprise.transaction.api.JavaEETransaction)29 SystemException (javax.transaction.SystemException)5 ResourceHandle (com.sun.enterprise.resource.ResourceHandle)4 XAException (javax.transaction.xa.XAException)4 PoolingException (com.sun.appserv.connectors.internal.api.PoolingException)3 ResourceState (com.sun.enterprise.resource.ResourceState)3 RemoteException (java.rmi.RemoteException)3 Vector (java.util.Vector)3 EJBException (javax.ejb.EJBException)3 WorkException (javax.resource.spi.work.WorkException)3 InvocationException (org.glassfish.api.invocation.InvocationException)3 PhysicalEntityManagerWrapper (com.sun.enterprise.container.common.impl.PhysicalEntityManagerWrapper)2 JavaEETransactionManager (com.sun.enterprise.transaction.api.JavaEETransactionManager)2 RequestTraceSpanLog (fish.payara.notification.requesttracing.RequestTraceSpanLog)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 EntityManagerFactory (javax.persistence.EntityManagerFactory)2 ComponentInvocation (org.glassfish.api.invocation.ComponentInvocation)2 EJBLocalObjectImpl (com.sun.ejb.containers.EJBLocalObjectImpl)1 JavaEEContainer (com.sun.enterprise.container.common.spi.JavaEEContainer)1