Search in sources :

Example 6 with ResourceException

use of javax.resource.ResourceException in project geode by apache.

the class JCALocalTransaction method commit.

@Override
public void commit() throws ResourceException {
    LogWriter logger = this.cache.getLogger();
    if (logger.fineEnabled()) {
        logger.fine("JCALocalTransaction:invoked commit");
    }
    TXStateProxy tsp = this.gfTxMgr.getTXState();
    if (tsp != null && this.tid != tsp.getTransactionId()) {
        throw new IllegalStateException("Local Transaction associated with Tid = " + this.tid + " attempting to commit a different transaction");
    }
    try {
        this.gfTxMgr.commit();
        this.tid = null;
    } catch (Exception e) {
        // TODO: consider wrapping the cause
        throw new LocalTransactionException(e.toString());
    }
}
Also used : LocalTransactionException(javax.resource.spi.LocalTransactionException) LogWriter(org.apache.geode.LogWriter) TXStateProxy(org.apache.geode.internal.cache.TXStateProxy) ResourceException(javax.resource.ResourceException) SystemException(javax.transaction.SystemException) LocalTransactionException(javax.resource.spi.LocalTransactionException)

Example 7 with ResourceException

use of javax.resource.ResourceException in project geode by apache.

the class JCALocalTransaction method rollback.

@Override
public void rollback() throws ResourceException {
    TXStateProxy tsp = this.gfTxMgr.getTXState();
    if (tsp != null && this.tid != tsp.getTransactionId()) {
        throw new IllegalStateException("Local Transaction associated with Tid = " + this.tid + " attempting to commit a different transaction");
    }
    LogWriter logger = this.cache.getLogger();
    if (logger.fineEnabled()) {
        logger.fine("JCALocalTransaction:invoked rollback");
    }
    try {
        this.gfTxMgr.rollback();
    } catch (IllegalStateException ise) {
        // It is possible that the GFE transaction has already been rolled back.
        if (ise.getMessage().equals(LocalizedStrings.TXManagerImpl_THREAD_DOES_NOT_HAVE_AN_ACTIVE_TRANSACTION.toLocalizedString())) {
        // ignore
        } else {
            throw new ResourceException(ise);
        }
    } catch (RuntimeException e) {
        throw new ResourceException(e);
    } finally {
        this.tid = null;
    }
}
Also used : TXStateProxy(org.apache.geode.internal.cache.TXStateProxy) LogWriter(org.apache.geode.LogWriter) ResourceException(javax.resource.ResourceException)

Example 8 with ResourceException

use of javax.resource.ResourceException 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 9 with ResourceException

use of javax.resource.ResourceException 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 10 with ResourceException

use of javax.resource.ResourceException in project jackrabbit by apache.

the class JCAManagedConnection method openSession.

/**
     * Create a new session.
     */
private Session openSession() throws ResourceException {
    try {
        Session session = mcf.getRepository().login(cri.getCredentials(), cri.getWorkspace());
        log("Created session (" + session + ")");
        return session;
    } catch (RepositoryException e) {
        log("Failed to create session", e);
        ResourceException exception = new ResourceException("Failed to create session: " + e.getMessage());
        exception.initCause(e);
        throw exception;
    }
}
Also used : RepositoryException(javax.jcr.RepositoryException) ResourceException(javax.resource.ResourceException) Session(javax.jcr.Session)

Aggregations

ResourceException (javax.resource.ResourceException)21 Connection (javax.resource.cci.Connection)4 LocalTransactionException (javax.resource.spi.LocalTransactionException)4 SystemException (javax.transaction.SystemException)4 ManagedConnection (javax.resource.spi.ManagedConnection)3 MessageEndpoint (javax.resource.spi.endpoint.MessageEndpoint)3 LogWriter (org.apache.geode.LogWriter)3 TXStateProxy (org.apache.geode.internal.cache.TXStateProxy)3 IOException (java.io.IOException)2 RepositoryException (javax.jcr.RepositoryException)2 NotSupportedException (javax.resource.NotSupportedException)2 ActivationSpec (javax.resource.spi.ActivationSpec)2 RollbackException (javax.transaction.RollbackException)2 Transaction (javax.transaction.Transaction)2 XAResource (javax.transaction.xa.XAResource)2 TransactionSystemException (org.springframework.transaction.TransactionSystemException)2 IntrospectionException (java.beans.IntrospectionException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 SQLException (java.sql.SQLException)1