Search in sources :

Example 6 with ManagedConnection

use of javax.resource.spi.ManagedConnection in project wildfly by wildfly.

the class ValidManagedConnectionFactory1 method matchManagedConnections.

/**
     * Returns a matched connection from the candidate set of connections.
     *
     * @param connectionSet Candidate connection set
     * @param subject       Caller's security information
     * @param cxRequestInfo Additional resource adapter specific connection request information
     * @return ManagedConnection if resource adapter finds an acceptable match otherwise null
     * @throws javax.resource.ResourceException generic exception
     */
public ManagedConnection matchManagedConnections(Set connectionSet, Subject subject, ConnectionRequestInfo cxRequestInfo) throws ResourceException {
    ManagedConnection result = null;
    Iterator it = connectionSet.iterator();
    while (result == null && it.hasNext()) {
        ManagedConnection mc = (ManagedConnection) it.next();
        if (mc instanceof ValidManagedConnection) {
            result = mc;
        }
    }
    return result;
}
Also used : Iterator(java.util.Iterator) ManagedConnection(javax.resource.spi.ManagedConnection)

Example 7 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 8 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 9 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 10 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)

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