Search in sources :

Example 1 with ManagedConnection

use of javax.resource.spi.ManagedConnection in project geode by apache.

the class FacetsJCAConnectionManagerImpl method afterCompletion.

/*
   * (non-Javadoc)
   * 
   * @see javax.transaction.Synchronization#afterCompletion(int)
   */
public void afterCompletion(int arg0) {
    // DELIST THE XARESOURCE FROM THE LIST. RETURN ALL THE CONNECTIONS TO THE
    // POOL.
    java.util.List lsConn = (ArrayList) xalistThreadLocal.get();
    Iterator itr = lsConn.iterator();
    while (itr.hasNext()) {
        ManagedConnection conn = (ManagedConnection) itr.next();
        mannPoolCache.returnPooledConnectionToPool(conn);
    }
    lsConn.clear();
// return all the connections to pool.
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ManagedConnection(javax.resource.spi.ManagedConnection)

Example 2 with ManagedConnection

use of javax.resource.spi.ManagedConnection in project geode by apache.

the class FacetsJCAConnectionManagerImpl method connectionErrorOccurred.

/**
   * CallBack for Connection Error.
   * 
   * @param event ConnectionEvent
   */
public void connectionErrorOccurred(ConnectionEvent event) {
    if (isActive) {
        // If its an XAConnection
        ManagedConnection conn = (ManagedConnection) event.getSource();
        // XAResource xar = (XAResource) xaResourcesMap.get(conn);
        ((List) xalistThreadLocal.get()).remove(conn);
        TransactionManagerImpl transManager = TransactionManagerImpl.getTransactionManager();
        try {
            Transaction txn = transManager.getTransaction();
            if (txn == null) {
                mannPoolCache.returnPooledConnectionToPool(conn);
            } else {
            // do nothing.
            }
        } catch (Exception se) {
            se.printStackTrace();
        }
        try {
            mannPoolCache.expirePooledConnection(conn);
        // mannPoolCache.destroyPooledConnection(conn);
        } catch (Exception ex) {
            String exception = "FacetsJCAConnectionManagerImpl::connectionErrorOccurred: Exception occurred due to " + ex.getMessage();
            if (logger.isDebugEnabled()) {
                logger.debug(exception, ex);
            }
        }
    }
}
Also used : Transaction(javax.transaction.Transaction) TransactionManagerImpl(org.apache.geode.internal.jta.TransactionManagerImpl) ManagedConnection(javax.resource.spi.ManagedConnection) ArrayList(java.util.ArrayList) List(java.util.List) ResourceException(javax.resource.ResourceException) SystemException(javax.transaction.SystemException) RollbackException(javax.transaction.RollbackException)

Example 3 with ManagedConnection

use of javax.resource.spi.ManagedConnection in project geode by apache.

the class JCAConnectionManagerImpl method allocateConnection.

/*
   * allocates a ManagedConnection from the ConnectionPool or creates a new
   * ManagedConnection. @param javax.resource.spi.ManagedConnectionFactory
   * 
   * @param javax.resource.spi.ConnectionRequestInfo
   * 
   * @throws ResourceException
   */
public Object allocateConnection(ManagedConnectionFactory mcf, ConnectionRequestInfo reqInfo) throws ResourceException {
    if (!isActive) {
        throw new ResourceException(LocalizedStrings.JCAConnectionManagerImpl_JCACONNECTIONMANAGERIMPLALLOCATECONNECTIONNO_VALID_CONNECTION_AVAILABLE.toLocalizedString());
    }
    ManagedConnection conn = null;
    try {
        conn = (ManagedConnection) mannPoolCache.getPooledConnectionFromPool();
    } catch (PoolException ex) {
        // ex.printStackTrace();
        throw new ResourceException(LocalizedStrings.JCAConnectionManagerImpl_JCACONNECTIONMANAGERIMPL_ALLOCATECONNECTION_IN_GETTING_CONNECTION_FROM_POOL_DUE_TO_0.toLocalizedString(ex.getMessage()), ex);
    }
    // Transaction Manager.
    try {
        synchronized (this) {
            if (transManager == null) {
                transManager = JNDIInvoker.getTransactionManager();
            }
        }
        Transaction txn = transManager.getTransaction();
        if (txn != null) {
            // Check if Data Source provides XATransaction
            // if(configs.getTransactionType = "XATransaction")
            XAResource xar = conn.getXAResource();
            txn.enlistResource(xar);
            // Asif :Add in the Map after successful registration of XAResource
            xaResourcesMap.put(conn, xar);
        // else throw a resource exception
        }
    } catch (RollbackException ex) {
        throw new ResourceException(LocalizedStrings.JCAConnectionManagerImpl_JCACONNECTIONMANAGERIMPL_ALLOCATECONNECTION_IN_TRANSACTION_DUE_TO_0.toLocalizedString(ex.getMessage()), ex);
    } catch (SystemException ex) {
        throw new ResourceException(LocalizedStrings.JCAConnectionManagerImpl_JCACONNECTIONMANAGERIMPL_ALLOCATECONNECTION_SYSTEM_EXCEPTION_DUE_TO_0.toLocalizedString(ex.getMessage()), ex);
    }
    return conn.getConnection(subject, reqInfo);
}
Also used : XAResource(javax.transaction.xa.XAResource) Transaction(javax.transaction.Transaction) SystemException(javax.transaction.SystemException) ResourceException(javax.resource.ResourceException) ManagedConnection(javax.resource.spi.ManagedConnection) RollbackException(javax.transaction.RollbackException)

Example 4 with ManagedConnection

use of javax.resource.spi.ManagedConnection in project geode by apache.

the class ManagedPoolCacheImpl method getNewPoolConnection.

/**
   * Creates a new connection for the managed connection pool.
   * 
   * @return the managed connection from the EIS as ManagedConnection object.
   * @throws PoolException
   */
@Override
public Object getNewPoolConnection() throws PoolException {
    ManagedConnection manConn = null;
    try {
        manConn = connFactory.createManagedConnection(sub, connReqInfo);
    } catch (ResourceException rex) {
        rex.printStackTrace();
        throw new PoolException(LocalizedStrings.ManagedPoolCacheImpl_MANAGEDPOOLCACHEIMPLGETNEWCONNECTION_EXCEPTION_IN_CREATING_NEW_MANAGED_POOLEDCONNECTION.toLocalizedString(), rex);
    }
    manConn.addConnectionEventListener((javax.resource.spi.ConnectionEventListener) connEventListner);
    return manConn;
}
Also used : ManagedConnection(javax.resource.spi.ManagedConnection) ResourceException(javax.resource.ResourceException)

Example 5 with ManagedConnection

use of javax.resource.spi.ManagedConnection in project tomee by apache.

the class SampleManagedConnectionFactory method matchManagedConnections.

public ManagedConnection matchManagedConnections(Set connectionSet, Subject subject, ConnectionRequestInfo cxRequestInfo) throws ResourceException {
    log.finest("matchManagedConnections()");
    ManagedConnection result = null;
    Iterator it = connectionSet.iterator();
    while (result == null && it.hasNext()) {
        ManagedConnection mc = (ManagedConnection) it.next();
        if (mc instanceof SampleManagedConnection) {
            result = mc;
        }
    }
    return result;
}
Also used : Iterator(java.util.Iterator) ManagedConnection(javax.resource.spi.ManagedConnection)

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