Search in sources :

Example 21 with ManagedConnection

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

the class ConnectorConnectionPoolAdminServiceImpl method getManagedConnection.

/**
 * Utility method to get Managed connection from the supplied mcf and
 * default subject.
 * @param mcf
 * @param defaultSubject
 * @return
 * @throws javax.resource.ResourceException
 */
protected ManagedConnection getManagedConnection(ManagedConnectionFactory mcf, Subject defaultSubject, ConnectionRequestInfo cReqInfo) throws ResourceException {
    ManagedConnection mc = null;
    // Create the ManagedConnection
    mc = mcf.createManagedConnection(defaultSubject, cReqInfo);
    return mc;
}
Also used : ManagedConnection(javax.resource.spi.ManagedConnection)

Example 22 with ManagedConnection

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

the class ConnectorXAResource method end.

public void end(Xid xid, int flags) throws XAException {
    if (_logger.isLoggable(Level.FINE)) {
        _logger.log(Level.FINE, "connection_sharing_end");
    }
    try {
        ResourceHandle handleInTransaction = getResourceHandleAndBeginTxIfNeeded();
        if (!localHandle_.equals(handleInTransaction)) {
            LocalTxConnectionEventListener l = (LocalTxConnectionEventListener) handleInTransaction.getListener();
            ResourceHandle handle = l.removeAssociation(userHandle);
            if (handle != null) {
                // not needed, just to be sure.
                ManagedConnection associatedConnection = (ManagedConnection) handle.getResource();
                associatedConnection.associateConnection(userHandle);
                if (_logger.isLoggable(Level.FINE)) {
                    _logger.log(Level.FINE, "connection_sharing_reset_association", userHandle);
                }
            }
        }
    } catch (Exception e) {
        handleResourceException(e);
    }
}
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 23 with ManagedConnection

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

the class ConnectorXAResource method commit.

public void commit(Xid xid, boolean onePhase) throws XAException {
    try {
        ResourceHandle handle = getResourceHandleAndBeginTxIfNeeded();
        ManagedConnection mc = (ManagedConnection) handle.getResource();
        mc.getLocalTransaction().commit();
    } 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 24 with ManagedConnection

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

the class NoTxConnectorAllocator method createResource.

public ResourceHandle createResource() throws PoolingException {
    try {
        ManagedConnection mc = mcf.createManagedConnection(subject, reqInfo);
        ResourceHandle resource = createResourceHandle(mc, spec, this, info);
        ConnectionEventListener l = new ConnectionListenerImpl(resource);
        mc.addConnectionEventListener(l);
        return resource;
    } catch (ResourceException ex) {
        Object[] params = new Object[] { spec.getPoolInfo(), ex.toString() };
        _logger.log(Level.WARNING, "poolmgr.create_resource_error", params);
        if (_logger.isLoggable(Level.FINE)) {
            _logger.log(Level.FINE, "Resource Exception while creating resource", ex);
        }
        if (ex.getLinkedException() != null) {
            _logger.log(Level.WARNING, "poolmgr.create_resource_linked_error", ex.getLinkedException().toString());
        }
        throw new PoolingException(ex);
    }
}
Also used : PoolingException(com.sun.appserv.connectors.internal.api.PoolingException) ResourceHandle(com.sun.enterprise.resource.ResourceHandle) ManagedConnection(javax.resource.spi.ManagedConnection) ResourceException(javax.resource.ResourceException) ConnectionEventListener(com.sun.enterprise.resource.listener.ConnectionEventListener)

Example 25 with ManagedConnection

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

the class AbstractConnectorAllocator method closeUserConnection.

public void closeUserConnection(ResourceHandle resource) throws PoolingException {
    try {
        ManagedConnection mc = (ManagedConnection) resource.getResource();
        mc.cleanup();
    } catch (ResourceException ex) {
        throw new PoolingException(ex);
    }
}
Also used : PoolingException(com.sun.appserv.connectors.internal.api.PoolingException) ManagedConnection(javax.resource.spi.ManagedConnection) ResourceException(javax.resource.ResourceException)

Aggregations

ManagedConnection (javax.resource.spi.ManagedConnection)70 Test (org.junit.Test)24 ResourceException (javax.resource.ResourceException)20 XAResource (javax.transaction.xa.XAResource)17 Iterator (java.util.Iterator)15 PoolingException (com.sun.appserv.connectors.internal.api.PoolingException)14 SystemException (javax.transaction.SystemException)12 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 ResourceAllocationException (javax.resource.spi.ResourceAllocationException)6 RollbackException (javax.transaction.RollbackException)6 XAException (javax.transaction.xa.XAException)6 Connection (java.sql.Connection)5 NamingException (javax.naming.NamingException)5 ConnectionRequestInfo (javax.resource.spi.ConnectionRequestInfo)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4