use of com.sun.enterprise.transaction.api.JavaEETransaction in project Payara by payara.
the class ConnectorXAResource method getResourceHandle.
private ResourceHandle getResourceHandle(boolean beginTxIfNeeded) throws PoolingException {
try {
ResourceHandle h = null;
JavaEETransaction j2eetran = getCurrentTransaction();
if (j2eetran == null) {
// Only if some thing is wrong with tx manager.
// Just return the local handle.
h = localHandle_;
} else {
h = (ResourceHandle) j2eetran.getNonXAResource();
// can be acquired. If the resource in question is not the one in transaction, fail
if (!localHandle_.isShareable()) {
if (h != localHandle_) {
throw new ResourceAllocationException("Cannot use more than one local-tx resource in unshareable scope");
}
}
}
if (beginTxIfNeeded && h.getResourceState().isUnenlisted()) {
ManagedConnection mc = (ManagedConnection) h.getResource();
// begin the local transaction if first time
// this ManagedConnection is used in this JTA transaction
mc.getLocalTransaction().begin();
}
return h;
} catch (Exception ex) {
_logger.log(Level.SEVERE, "poolmgr.system_exception", ex);
throw new PoolingException(ex.toString(), ex);
}
}
use of com.sun.enterprise.transaction.api.JavaEETransaction in project Payara by payara.
the class ActiveTxCache method getEJBLocalObjectForPrimaryKey.
/**
* Called only from the Persistence Manager for EJB2.0 CMP EntityBeans.
* Called only during cascade delete......
* This is a private API between the PM and Container because there
* is no standard API defined in EJB2.0 for the PM to get an EJBLocalObject
* for a primary key (findByPrimaryKey cant be used because it may
* not run in the same tx).
*
* Example 1:
* A cascadeDeletes B and B calls getA() (expected return value: null)
*
* In the above case, getA() eventualy calls getEJBLocalObjectForPrimaryKey(PK_of_A, Ctx_of_B)
* We first check if B is in the process of being cascade deleted by checking the
* cascadeDeleteBeforeEJBRemove flag. If this flag is true, only then we bother to check if
* the Context associated with the PK_of_A in this transaction is marked for cascade delete
* which can be figured out by checking isCascadeDeleteAfterSuperEJBRemove() in A's context.
* If A is marked for cascade delete then we return null else the EJBLocalObject associated
* with A.
*
* Example 2:
* C cascadeDeletes B and B calls getA() (expected return value: EJBLocalObject for PK_of_A)
*
* In the above case, getA() eventualy calls getEJBLocalObjectForPrimaryKey(PK_of_A, Ctx_of_B)
* We first check if B is in the process of being cascade deleted by checking the
* cascadeDeleteBeforeEJBRemove flag. This flag will be true, and hence we check if
* the Context associated with the PK_of_A in this transaction is marked for cascade delete
* which can be figured out by checking isCascadeDeleteAfterSuperEJBRemove() in A's context.
* In this case this flag will be false and hcen we return the ejbLocalObject
* Example 2:
* B is *NOT* cascade deleted and B calls getA() (expected return value: EJBLocalObject for PK_of_A)
*
* In the above case, getA() eventualy calls getEJBLocalObjectForPrimaryKey(PK_of_A, Ctx_of_B)
* We first check if B is in the process of being cascade deleted by checking the
* cascadeDeleteBeforeEJBRemove flag. This flag will be FALSE, and hence we do not make
* any further check and return the EJBLocalObject associated with A
*
* @param pkey The primary key for which the EJBLocalObject is required
* @param ctx The context associated with the bean from which the accessor method is invoked
* @return The EJBLocalObject associated with the PK or null if it is cascade deleted.
*/
public EJBLocalObject getEJBLocalObjectForPrimaryKey(Object pkey, EJBContext ctx) {
// EntityContextImpl should always be used in conjunction with EntityContainer so we can always cast
assert ctx instanceof EntityContextImpl;
EntityContextImpl context = (EntityContextImpl) ctx;
EJBLocalObjectImpl ejbLocalObjectImpl = internalGetEJBLocalObjectImpl(pkey);
if (context.isCascadeDeleteBeforeEJBRemove()) {
JavaEETransaction current = null;
try {
current = (JavaEETransaction) transactionManager.getTransaction();
} catch (SystemException ex) {
throw new EJBException(ex);
}
ActiveTxCache activeTxCache = (current == null) ? null : (ActiveTxCache) (ejbContainerUtilImpl.getActiveTxCache(current));
if (activeTxCache != null) {
EntityContextImpl ctx2 = (EntityContextImpl) activeTxCache.get(this, pkey);
if ((ctx2 != null) && (ctx2.isCascadeDeleteAfterSuperEJBRemove())) {
return null;
}
}
return (EJBLocalObject) ejbLocalObjectImpl.getClientObject();
}
return (EJBLocalObject) ejbLocalObjectImpl.getClientObject();
}
use of com.sun.enterprise.transaction.api.JavaEETransaction in project Payara by payara.
the class ActiveTxCache method removeIncompleteTxEJB.
/**
* Called from releaseContext if ejb is removed, from afterCompletion,
* and from passivateEJB.
*/
protected void removeIncompleteTxEJB(EntityContextImpl context, boolean updateTxBeanTable) {
JavaEETransaction current = (JavaEETransaction) context.getTransaction();
if (current == null) {
return;
}
if ((containerStateManager.isNullEJBObject(context)) && (containerStateManager.isNullEJBLocalObject(context))) {
return;
}
ActiveTxCache activeTxCache = (ActiveTxCache) ejbContainerUtilImpl.getActiveTxCache(current);
if (activeTxCache != null) {
activeTxCache.remove(this, context.getPrimaryKey());
}
if (updateTxBeanTable) {
Vector beans = ejbContainerUtilImpl.getBeans(current);
// this is a little expensive...
beans.remove(context);
}
}
use of com.sun.enterprise.transaction.api.JavaEETransaction in project Payara by payara.
the class JavaEETransactionManagerSimplified method enlistResource.
public boolean enlistResource(Transaction tran, TransactionalResource h) throws RollbackException, IllegalStateException, SystemException {
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "\n\nIn JavaEETransactionManagerSimplified.enlistResource, h=" + h + " h.xares=" + h.getXAResource() + /**
* +" h.alloc=" +h.getResourceAllocator() *
*/
" tran=" + tran);
}
if (!h.isTransactional())
return true;
// If LazyEnlistment is suspended, do not enlist resource.
if (h.isEnlistmentSuspended()) {
return false;
}
if (monitoringEnabled) {
JavaEETransaction tx = getDelegate().getJavaEETransaction(tran);
if (tx != null) {
((JavaEETransactionImpl) tx).addResourceName(h.getName());
}
}
if (!(tran instanceof JavaEETransaction)) {
return enlistXAResource(tran, h);
}
JavaEETransactionImpl tx = (JavaEETransactionImpl) tran;
JavaEETransactionManagerDelegate d = setDelegate();
boolean useLAO = d.useLAO();
if ((tx.getNonXAResource() != null) && (!useLAO || !h.supportsXA())) {
boolean isSameRM = false;
try {
isSameRM = h.getXAResource().isSameRM(tx.getNonXAResource().getXAResource());
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "\n\nIn JavaEETransactionManagerSimplified.enlistResource, isSameRM? " + isSameRM);
}
} catch (XAException xex) {
throw new SystemException(sm.getString("enterprise_distributedtx.samerm_excep", xex));
} catch (Exception ex) {
throw new SystemException(sm.getString("enterprise_distributedtx.samerm_excep", ex));
}
if (!isSameRM) {
throw new IllegalStateException(sm.getString("enterprise_distributedtx.already_has_nonxa"));
}
}
if (h.supportsXA()) {
if (!d.supportsXAResource()) {
throw new IllegalStateException(sm.getString("enterprise_distributedtx.xaresource_not_supported"));
}
if (tx.isLocalTx()) {
d.enlistLAOResource(tx, tx.getNonXAResource());
/**
* XXX TO BE MOVED TO XA DELEGATE XXX **
* startJTSTx(tx);
*
* //If transaction conatains a NonXA and no LAO, convert the existing
* //Non XA to LAO
* if(useLAO) {
* if(tx.getNonXAResource()!=null && (tx.getLAOResource()==null) ) {
* tx.setLAOResource(tx.getNonXAResource());
* // XXX super.enlistLAOResource(tx, tx.getNonXAResource());
* }
* }
** XXX TO BE MOVED TO XA DELEGATE XXX *
*/
}
return enlistXAResource(tx, h);
} else {
// non-XA resource
if (tx.isImportedTransaction())
throw new IllegalStateException(sm.getString("enterprise_distributedtx.nonxa_usein_jts"));
if (tx.getNonXAResource() == null) {
tx.setNonXAResource(h);
}
if (tx.isLocalTx()) {
// used by the XAResource implementation for non-XA resources.
try {
h.getXAResource().start(tx.getLocalXid(), 0);
} catch (XAException ex) {
throw new RuntimeException(sm.getString("enterprise_distributedtx.xaresource_start_excep"), ex);
}
h.enlistedInTransaction(tx);
return true;
} else {
return d.enlistDistributedNonXAResource(tx, h);
/**
* XXX TO BE MOVED TO XA DELEGATE? XXX
* if(useLAO) {
* return super.enlistResource(tx, h);
* } else {
* throw new IllegalStateException(
* sm.getString("enterprise_distributedtx.nonxa_usein_jts"));
* }
** XXX TO BE MOVED TO XA DELEGATE? XXX *
*/
}
}
}
use of com.sun.enterprise.transaction.api.JavaEETransaction in project Payara by payara.
the class JavaEETransactionManagerSimplified method getTransactionAdminBean.
public TransactionAdminBean getTransactionAdminBean(Transaction tran) throws javax.transaction.SystemException {
TransactionAdminBean tBean = null;
if (tran instanceof JavaEETransaction) {
JavaEETransactionImpl tran1 = (JavaEETransactionImpl) tran;
String id = tran1.getTransactionId();
long startTime = tran1.getStartTime();
String componentName = tran1.getComponentName();
ArrayList<String> resourceNames = tran1.getResourceNames();
long elapsedTime = System.currentTimeMillis() - startTime;
String status = getStatusAsString(tran.getStatus());
tBean = new TransactionAdminBean(tran, id, status, elapsedTime, componentName, resourceNames);
}
return tBean;
}
Aggregations