Search in sources :

Example 11 with JavaEETransaction

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

the class JavaEETransactionManagerSimplified method checkTransactionExport.

/**
 * Called from the CORBA Interceptors on the client-side when
 * a client makes a call to a remote object (not in the same JVM).
 * Check if there is an active, exportable transaction.
 * @exception RuntimeException if the transaction is not exportable
 */
public void checkTransactionExport(boolean isLocal) {
    if (isLocal) {
        // Put a counter in TLS indicating this is a local call.
        // Use int[1] as a mutable java.lang.Integer!
        int[] count = (int[]) localCallCounter.get();
        if (count == null) {
            count = new int[1];
            localCallCounter.set(count);
        }
        count[0]++;
        return;
    }
    JavaEETransaction tx = transactions.get();
    if (tx == null)
        return;
    if (// a JTS tx, can be exported
    !tx.isLocalTx())
        return;
    // XXX what if this is a call on a non-transactional remote object ?
    if (tx.getNonXAResource() != null)
        throw new RuntimeException(sm.getString("enterprise_distributedtx.cannot_export_transaction_having_nonxa"));
    // resources, so start a JTS tx which can be exported.
    try {
        startJTSTx(tx);
    } catch (RollbackException rlex) {
        throw new RuntimeException(sm.getString("enterprise_distributedtx.unable_tostart_JTSTransaction"), rlex);
    } catch (IllegalStateException isex) {
        throw new RuntimeException(sm.getString("enterprise_distributedtx.unable_tostart_JTSTransaction"), isex);
    } catch (SystemException ex) {
        throw new RuntimeException(sm.getString("enterprise_distributedtx.unable_tostart_JTSTransaction"), ex);
    } catch (Exception excep) {
        throw new RuntimeException(sm.getString("enterprise_distributedtx.unable_tostart_JTSTransaction"), excep);
    }
}
Also used : JavaEETransaction(com.sun.enterprise.transaction.api.JavaEETransaction) InvocationException(org.glassfish.api.invocation.InvocationException) WorkException(javax.resource.spi.work.WorkException) RemoteException(java.rmi.RemoteException) XAException(javax.transaction.xa.XAException)

Example 12 with JavaEETransaction

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

the class JavaEETransactionManagerSimplified method resume.

public void resume(Transaction tobj) throws InvalidTransactionException, IllegalStateException, SystemException {
    JavaEETransaction tx = transactions.get();
    if (tx != null)
        throw new IllegalStateException(sm.getString("enterprise_distributedtx.transaction_exist_on_currentThread"));
    if (tobj != null) {
        int status = tobj.getStatus();
        if (status == Status.STATUS_ROLLEDBACK || status == Status.STATUS_COMMITTED || status == Status.STATUS_NO_TRANSACTION || status == Status.STATUS_UNKNOWN) {
            throw new InvalidTransactionException(sm.getString("enterprise_distributedtx.resume_invalid_transaction", tobj));
        }
    } else {
        throw new InvalidTransactionException(sm.getString("enterprise_distributedtx.resume_invalid_transaction", "null"));
    }
    if (tobj instanceof JavaEETransactionImpl) {
        JavaEETransactionImpl javaEETx = (JavaEETransactionImpl) tobj;
        if (!javaEETx.isLocalTx())
            getDelegate().resume(javaEETx.getJTSTx());
        setCurrentTransaction(javaEETx);
    } else {
        // probably a JTS imported tx
        getDelegate().resume(tobj);
    }
}
Also used : JavaEETransaction(com.sun.enterprise.transaction.api.JavaEETransaction) PluginPoint(org.glassfish.external.probe.provider.PluginPoint)

Example 13 with JavaEETransaction

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

the class JavaEETransactionManagerSimplified method commit.

public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, SecurityException, IllegalStateException, SystemException {
    boolean acquiredlock = false;
    try {
        JavaEETransaction tx = transactions.get();
        if (tx != null && tx.isLocalTx()) {
            if (monitoringEnabled) {
                // XXX acquireReadLock();
                getDelegate().getReadLock().lock();
                acquiredlock = true;
            }
            // commit local tx
            tx.commit();
        } else {
            try {
                // an XA transaction
                getDelegate().commitDistributedTransaction();
            } finally {
                if (tx != null) {
                    ((JavaEETransactionImpl) tx).onTxCompletion(true);
                }
            }
        }
        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();
        }
    }
// END IASRI 4662745
}
Also used : JavaEETransaction(com.sun.enterprise.transaction.api.JavaEETransaction) RequestTraceSpanLog(fish.payara.notification.requesttracing.RequestTraceSpanLog)

Example 14 with JavaEETransaction

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

the class JavaEETransactionManagerJTSDelegate method enlistLAOResource.

public boolean enlistLAOResource(Transaction tran, TransactionalResource h) throws RollbackException, IllegalStateException, SystemException {
    if (tran instanceof JavaEETransaction) {
        JavaEETransaction tx = (JavaEETransaction) tran;
        ((JavaEETransactionManagerSimplified) javaEETM).startJTSTx(tx);
        // Non XA to LAO
        if (useLAO()) {
            if (h != null && (tx.getLAOResource() == null)) {
                tx.setLAOResource(h);
                if (h.isTransactional()) {
                    XAResource res = h.getXAResource();
                    return tran.enlistResource(res);
                }
            }
        }
        return true;
    } else {
        // Should not be called
        return false;
    }
}
Also used : OracleXAResource(com.sun.enterprise.transaction.jts.recovery.OracleXAResource) SybaseXAResource(com.sun.enterprise.transaction.jts.recovery.SybaseXAResource) JavaEETransaction(com.sun.enterprise.transaction.api.JavaEETransaction) JavaEETransactionManagerSimplified(com.sun.enterprise.transaction.JavaEETransactionManagerSimplified)

Example 15 with JavaEETransaction

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

the class EntityManagerWrapper method _getDelegate.

private EntityManager _getDelegate() {
    if (entityManagerFactory == null) {
        init();
    }
    EntityManager delegate;
    if (contextType == PersistenceContextType.TRANSACTION) {
        JavaEETransaction tx = getCurrentTransaction();
        if (tx != null) {
            // If there is an active extended persistence context
            // for the same entity manager factory and the same tx,
            // it takes precedence.
            PhysicalEntityManagerWrapper propagatedPersistenceContext = getExtendedEntityManager(tx, entityManagerFactory);
            if (propagatedPersistenceContext == null) {
                propagatedPersistenceContext = getTxEntityManager(tx, entityManagerFactory);
                if (propagatedPersistenceContext == null) {
                    // If there is a transaction and this is the first
                    // access of the wrapped entity manager, create an
                    // actual entity manager and associate it with the
                    // entity manager factory.
                    EntityManager em = entityManagerFactory.createEntityManager(synchronizationType, emProperties);
                    propagatedPersistenceContext = new PhysicalEntityManagerWrapper(em, synchronizationType);
                    tx.addTxEntityManagerMapping(entityManagerFactory, propagatedPersistenceContext);
                } else {
                    // Check if sync type of current persistence context is compatible with persistence context being propagated
                    if (synchronizationType == SYNCHRONIZED && propagatedPersistenceContext.getSynchronizationType() == UNSYNCHRONIZED) {
                        throw new IllegalStateException("Detected an UNSYNCHRONIZED  persistence context being propagated to SYNCHRONIZED persistence context.");
                    }
                }
            }
            delegate = propagatedPersistenceContext.getEM();
        } else {
            // Get non transactional entity manager corresponding to this wrapper from current invocation
            delegate = getNonTxEMFromCurrentInvocation();
        }
    } else {
        if (extendedEntityManager == null) {
            ComponentInvocation ci = invMgr.getCurrentInvocation();
            if (ci != null) {
                Object cc = ci.getContainer();
                if (cc instanceof JavaEEContainer) {
                    extendedEntityManager = ((JavaEEContainer) cc).lookupExtendedEntityManager(entityManagerFactory);
                }
            }
        }
        delegate = extendedEntityManager;
    }
    if (_logger.isLoggable(Level.FINE)) {
        _logger.fine("In EntityManagerWrapper::_getDelegate(). " + "Logical entity manager  = " + this);
        _logger.fine("Physical entity manager = " + delegate);
    }
    return delegate;
}
Also used : JavaEEContainer(com.sun.enterprise.container.common.spi.JavaEEContainer) JavaEETransaction(com.sun.enterprise.transaction.api.JavaEETransaction) ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation)

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