Search in sources :

Example 56 with ManagedConnection

use of javax.resource.spi.ManagedConnection in project Payara by payara.

the class ConnectorXAResource method rollback.

public void rollback(Xid xid) throws XAException {
    try {
        ResourceHandle handle = getResourceHandleAndBeginTxIfNeeded();
        ManagedConnection mc = (ManagedConnection) handle.getResource();
        mc.getLocalTransaction().rollback();
    } catch (Exception ex) {
        handleResourceException(ex);
    } finally {
        resetAssociation();
        resetAssociatedTransaction();
    }
}
Also used : ManagedConnection(javax.resource.spi.ManagedConnection) PoolingException(com.sun.appserv.connectors.internal.api.PoolingException) SystemException(javax.transaction.SystemException) XAException(javax.transaction.xa.XAException) ResourceAllocationException(javax.resource.spi.ResourceAllocationException)

Example 57 with ManagedConnection

use of javax.resource.spi.ManagedConnection in project Payara by payara.

the class ConnectorXAResource method getResourceHandle.

private ResourceHandle getResourceHandle(boolean beginTxIfNeeded) throws PoolingException {
    ResourceHandle h;
    try {
        JavaEETransaction j2eetran = getCurrentTransaction();
        if (j2eetran == null || j2eetran.getNonXAResource() == 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);
    }
}
Also used : PoolingException(com.sun.appserv.connectors.internal.api.PoolingException) JavaEETransaction(com.sun.enterprise.transaction.api.JavaEETransaction) ManagedConnection(javax.resource.spi.ManagedConnection) ResourceAllocationException(javax.resource.spi.ResourceAllocationException) PoolingException(com.sun.appserv.connectors.internal.api.PoolingException) SystemException(javax.transaction.SystemException) XAException(javax.transaction.xa.XAException) ResourceAllocationException(javax.resource.spi.ResourceAllocationException)

Example 58 with ManagedConnection

use of javax.resource.spi.ManagedConnection in project Payara by payara.

the class ConnectorXAResource method start.

public void start(Xid xid, int flags) throws XAException {
    try {
        ResourceHandle handle = getResourceHandleAndBeginTxIfNeeded();
        if (!localHandle_.equals(handle)) {
            ManagedConnection mc = (ManagedConnection) handle.getResource();
            mc.associateConnection(userHandle);
            LocalTxConnectionEventListener l = (com.sun.enterprise.resource.listener.LocalTxConnectionEventListener) handle.getListener();
            if (_logger.isLoggable(Level.FINE)) {
                _logger.log(Level.FINE, "connection_sharing_start", userHandle);
            }
            l.associateHandle(userHandle, localHandle_);
        } else {
            associatedTransaction = getCurrentTransaction();
        }
    } catch (Exception ex) {
        handleResourceException(ex);
    }
}
Also used : LocalTxConnectionEventListener(com.sun.enterprise.resource.listener.LocalTxConnectionEventListener) ManagedConnection(javax.resource.spi.ManagedConnection) PoolingException(com.sun.appserv.connectors.internal.api.PoolingException) SystemException(javax.transaction.SystemException) XAException(javax.transaction.xa.XAException) ResourceAllocationException(javax.resource.spi.ResourceAllocationException)

Example 59 with ManagedConnection

use of javax.resource.spi.ManagedConnection in project Payara by payara.

the class AbstractConnectorAllocator method cleanup.

public void cleanup(ResourceHandle h) throws PoolingException {
    try {
        ManagedConnection mc = (ManagedConnection) h.getResource();
        mc.cleanup();
    } catch (Exception ex) {
        _logger.log(Level.WARNING, "managed_con.cleanup-failed", ex);
        throw new PoolingException(ex.toString(), ex);
    }
}
Also used : PoolingException(com.sun.appserv.connectors.internal.api.PoolingException) ManagedConnection(javax.resource.spi.ManagedConnection) PoolingException(com.sun.appserv.connectors.internal.api.PoolingException) ResourceException(javax.resource.ResourceException) ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)

Example 60 with ManagedConnection

use of javax.resource.spi.ManagedConnection in project Payara by payara.

the class AbstractConnectorAllocator method matchConnection.

public boolean matchConnection(ResourceHandle h) {
    Set set = new HashSet();
    set.add(h.getResource());
    try {
        ManagedConnection mc = mcf.matchManagedConnections(set, subject, reqInfo);
        return (mc != null);
    } catch (ResourceException ex) {
        return false;
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ManagedConnection(javax.resource.spi.ManagedConnection) ResourceException(javax.resource.ResourceException) HashSet(java.util.HashSet)

Aggregations

ManagedConnection (javax.resource.spi.ManagedConnection)73 Test (org.junit.Test)24 ResourceException (javax.resource.ResourceException)20 XAResource (javax.transaction.xa.XAResource)17 Iterator (java.util.Iterator)16 PoolingException (com.sun.appserv.connectors.internal.api.PoolingException)13 SystemException (javax.transaction.SystemException)11 Subject (javax.security.auth.Subject)10 Xid (javax.transaction.xa.Xid)9 HashSet (java.util.HashSet)8 Transaction (javax.transaction.Transaction)7 ManagedConnectionFactory (javax.resource.spi.ManagedConnectionFactory)6 RollbackException (javax.transaction.RollbackException)6 ResourceHandle (com.sun.enterprise.resource.ResourceHandle)5 Connection (java.sql.Connection)5 NamingException (javax.naming.NamingException)5 ConnectionRequestInfo (javax.resource.spi.ConnectionRequestInfo)5 ResourceAllocationException (javax.resource.spi.ResourceAllocationException)5 XAException (javax.transaction.xa.XAException)5 ArrayList (java.util.ArrayList)4