use of com.sun.enterprise.transaction.api.JavaEETransactionManager in project Payara by payara.
the class AppTest method setUp.
public void setUp() {
try {
t = new JavaEETransactionManagerSimplified();
((JavaEETransactionManager) t).setDelegate(new JavaEETransactionManagerXADelegate());
} catch (Exception ex) {
ex.printStackTrace();
assert (false);
}
}
use of com.sun.enterprise.transaction.api.JavaEETransactionManager in project Payara by payara.
the class ResourceManagerImpl method rollBackTransaction.
/**
* Get's the component's transaction and marks it for rolling back.
*/
public void rollBackTransaction() {
InvocationManager invmgr = ConnectorRuntime.getRuntime().getInvocationManager();
JavaEETransactionManager tm = ConnectorRuntime.getRuntime().getTransactionManager();
Transaction tran = null;
try {
ComponentInvocation inv = invmgr.getCurrentInvocation();
if (inv == null) {
// in that, you return the transaction from the TxManager
try {
tran = tm.getTransaction();
} catch (Exception e) {
tran = null;
_logger.log(Level.INFO, e.getMessage());
}
} else {
tran = (Transaction) inv.getTransaction();
}
if (tran != null) {
tran.setRollbackOnly();
}
} catch (SystemException ex) {
_logger.log(Level.WARNING, "poolmgr.system_exception", ex);
} catch (IllegalStateException ex) {
// ignore
}
}
use of com.sun.enterprise.transaction.api.JavaEETransactionManager in project Payara by payara.
the class ResourceManagerImpl method registerResource.
/**
* Register the <code>ResourceHandle</code> in the transaction
*
* @param handle <code>ResourceHandle</code> object
* @exception <code>PoolingException</code>
*/
public void registerResource(ResourceHandle handle) throws PoolingException {
try {
Transaction tran = null;
JavaEETransactionManager tm = ConnectorRuntime.getRuntime().getTransactionManager();
// enlist if necessary
if (handle.isTransactional()) {
InvocationManager invmgr = ConnectorRuntime.getRuntime().getInvocationManager();
ComponentInvocation inv = invmgr.getCurrentInvocation();
if (inv == null) {
// in that, you return the transaction from the TxManager
try {
tran = tm.getTransaction();
} catch (Exception e) {
tran = null;
_logger.log(Level.INFO, e.getMessage());
}
} else {
tran = (Transaction) inv.getTransaction();
tm.registerComponentResource(handle);
}
if (tran != null) {
try {
tm.enlistResource(tran, handle);
} catch (Exception ex) {
if (_logger.isLoggable(Level.FINE)) {
_logger.fine("Exception whle trying to enlist resource " + ex.getMessage());
}
// to enlist the resource
if (inv != null) {
if (_logger.isLoggable(Level.FINE)) {
_logger.fine("Attempting to unregister component resource");
}
tm.unregisterComponentResource(handle);
}
throw ex;
}
}
}
} catch (Exception ex) {
_logger.log(Level.SEVERE, "poolmgr.component_register_exception", ex);
throw new PoolingException(ex.toString(), ex);
}
}
use of com.sun.enterprise.transaction.api.JavaEETransactionManager in project Payara by payara.
the class PoolManagerImpl method handleLazilyAssociatedConnectionPools.
/**
* If the connections associated with the component are lazily-associatable, dissociate them.
* @param comp Component that acquired connections
* @param invToUse component invocation
*/
private void handleLazilyAssociatedConnectionPools(Object comp, ComponentInvocation invToUse) {
JavaEETransactionManager tm = getConnectorRuntime().getTransactionManager();
List list = tm.getExistingResourceList(comp, invToUse);
if (list == null) {
// have any resources and hence the existingResourcesList is null
return;
}
if (list.isEmpty())
return;
ResourceHandle[] handles = new ResourceHandle[list.size()];
handles = (ResourceHandle[]) list.toArray(handles);
for (ResourceHandle h : handles) {
if (h == null) {
_logger.log(Level.WARNING, "lazy_association.lazy_association_resource_handle");
continue;
}
ResourceSpec spec = h.getResourceSpec();
if (spec == null) {
_logger.log(Level.WARNING, "lazy_association.lazy_association_resource_spec");
continue;
}
if (spec.isLazyAssociatable()) {
// of type DissociatableManagedConnection
if (h.getResource() != null) {
javax.resource.spi.DissociatableManagedConnection mc = (javax.resource.spi.DissociatableManagedConnection) h.getResource();
if (h.isEnlisted()) {
getResourceManager(spec).delistResource(h, XAResource.TMSUCCESS);
}
try {
mc.dissociateConnections();
} catch (ResourceException re) {
InvocationException ie = new InvocationException(re.getMessage());
ie.initCause(re);
throw ie;
} finally {
if (h.getResourceState().isBusy()) {
putbackDirectToPool(h, spec.getPoolInfo());
}
}
} else {
_logger.log(Level.WARNING, "lazy_association.lazy_association_resource");
}
}
}
}
use of com.sun.enterprise.transaction.api.JavaEETransactionManager in project Payara by payara.
the class LazyEnlistableResourceManagerImpl method lazyEnlist.
/**
* This is called by the PoolManager (in turn by the LazyEnlistableConnectionManager)
* when a lazy enlistment is sought.
* @param mc ManagedConnection
* @throws ResourceException
*/
public void lazyEnlist(ManagedConnection mc) throws ResourceException {
if (_logger.isLoggable(Level.FINE)) {
_logger.fine("Entering lazyEnlist");
}
// J2EETransactionManager tm = Switch.getSwitch().getTransactionManager();
JavaEETransactionManager tm = ConnectorRuntime.getRuntime().getTransactionManager();
Transaction tran = null;
try {
tran = tm.getTransaction();
if (tran == null) {
if (_logger.isLoggable(Level.FINE)) {
_logger.fine(" Transaction null - not enlisting ");
}
return;
}
} catch (SystemException se) {
ResourceException re = new ResourceException(se.getMessage());
re.initCause(se);
throw re;
}
// List invList = Switch.getSwitch().getInvocationManager().getAllInvocations();
List invList = ConnectorRuntime.getRuntime().getInvocationManager().getAllInvocations();
ResourceHandle h = null;
for (int j = invList.size(); j > 0; j--) {
ComponentInvocation inv = (ComponentInvocation) invList.get(j - 1);
Object comp = inv.getInstance();
List l = tm.getResourceList(comp, inv);
ListIterator it = l.listIterator();
while (it.hasNext()) {
ResourceHandle hand = (ResourceHandle) it.next();
ManagedConnection toEnlist = (ManagedConnection) hand.getResource();
if (mc.equals(toEnlist)) {
h = hand;
break;
}
}
}
// The other case might or might not work
if (h != null && h.getResourceState().isUnenlisted()) {
try {
// Enable the suspended lazyenlistment so as to enlist the resource.
h.setEnlistmentSuspended(false);
tm.enlistResource(tran, h);
// Suspend it back
h.setEnlistmentSuspended(true);
} catch (Exception e) {
// In the rare cases where enlistResource throws exception, we
// should report the resource to the pool as bad
PoolManager mgr = ConnectorRuntime.getRuntime().getPoolManager();
mgr.putbackBadResourceToPool(h);
_logger.log(Level.WARNING, "poolmgr.err_enlisting_res_in_getconn", h.getResourceSpec().getPoolInfo());
if (_logger.isLoggable(Level.FINE)) {
_logger.fine("rm.enlistResource threw Exception. Evicting resource from pool");
}
// and rethrow the exception
throw new ResourceException(e);
}
}
}
Aggregations