Search in sources :

Example 6 with JavaEETransactionManager

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);
    }
}
Also used : JavaEETransactionManagerSimplified(com.sun.enterprise.transaction.JavaEETransactionManagerSimplified) JavaEETransactionManager(com.sun.enterprise.transaction.api.JavaEETransactionManager)

Example 7 with JavaEETransactionManager

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
    }
}
Also used : ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation) InvocationManager(org.glassfish.api.invocation.InvocationManager) JavaEETransactionManager(com.sun.enterprise.transaction.api.JavaEETransactionManager) InvocationException(org.glassfish.api.invocation.InvocationException) PoolingException(com.sun.appserv.connectors.internal.api.PoolingException)

Example 8 with JavaEETransactionManager

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);
    }
}
Also used : PoolingException(com.sun.appserv.connectors.internal.api.PoolingException) ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation) InvocationManager(org.glassfish.api.invocation.InvocationManager) JavaEETransactionManager(com.sun.enterprise.transaction.api.JavaEETransactionManager) InvocationException(org.glassfish.api.invocation.InvocationException) PoolingException(com.sun.appserv.connectors.internal.api.PoolingException)

Example 9 with JavaEETransactionManager

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");
            }
        }
    }
}
Also used : InvocationException(org.glassfish.api.invocation.InvocationException) ResourceHandle(com.sun.enterprise.resource.ResourceHandle) ResourceSpec(com.sun.enterprise.resource.ResourceSpec) JavaEETransactionManager(com.sun.enterprise.transaction.api.JavaEETransactionManager) ResourceException(javax.resource.ResourceException)

Example 10 with JavaEETransactionManager

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);
        }
    }
}
Also used : ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation) JavaEETransactionManager(com.sun.enterprise.transaction.api.JavaEETransactionManager) ListIterator(java.util.ListIterator) PoolManager(com.sun.enterprise.resource.pool.PoolManager) PoolingException(com.sun.appserv.connectors.internal.api.PoolingException) ResourceException(javax.resource.ResourceException) ResourceHandle(com.sun.enterprise.resource.ResourceHandle) ResourceException(javax.resource.ResourceException) List(java.util.List) ManagedConnection(javax.resource.spi.ManagedConnection)

Aggregations

JavaEETransactionManager (com.sun.enterprise.transaction.api.JavaEETransactionManager)15 PoolingException (com.sun.appserv.connectors.internal.api.PoolingException)5 ComponentInvocation (org.glassfish.api.invocation.ComponentInvocation)4 InvocationException (org.glassfish.api.invocation.InvocationException)4 ResourceException (javax.resource.ResourceException)3 SystemException (javax.transaction.SystemException)3 Transaction (javax.transaction.Transaction)3 InvocationManager (org.glassfish.api.invocation.InvocationManager)3 ResourceHandle (com.sun.enterprise.resource.ResourceHandle)2 ResourceSpec (com.sun.enterprise.resource.ResourceSpec)1 PoolManager (com.sun.enterprise.resource.pool.PoolManager)1 JavaEETransactionManagerSimplified (com.sun.enterprise.transaction.JavaEETransactionManagerSimplified)1 Method (java.lang.reflect.Method)1 List (java.util.List)1 ListIterator (java.util.ListIterator)1 Logger (java.util.logging.Logger)1 ManagedConnection (javax.resource.spi.ManagedConnection)1