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);
}
}
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);
}
}
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
}
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;
}
}
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;
}
Aggregations