Search in sources :

Example 1 with NotSupportedException

use of javax.resource.NotSupportedException in project spring-framework by spring-projects.

the class CciTemplate method execute.

@Override
public <T> T execute(ConnectionCallback<T> action) throws DataAccessException {
    Assert.notNull(action, "Callback object must not be null");
    Connection con = ConnectionFactoryUtils.getConnection(getConnectionFactory(), getConnectionSpec());
    try {
        return action.doInConnection(con, getConnectionFactory());
    } catch (NotSupportedException ex) {
        throw new CciOperationNotSupportedException("CCI operation not supported by connector", ex);
    } catch (ResourceException ex) {
        throw new DataAccessResourceFailureException("CCI operation failed", ex);
    } catch (SQLException ex) {
        throw new InvalidResultSetAccessException("Parsing of CCI ResultSet failed", ex);
    } finally {
        ConnectionFactoryUtils.releaseConnection(con, getConnectionFactory());
    }
}
Also used : CciOperationNotSupportedException(org.springframework.jca.cci.CciOperationNotSupportedException) DataAccessResourceFailureException(org.springframework.dao.DataAccessResourceFailureException) SQLException(java.sql.SQLException) Connection(javax.resource.cci.Connection) ResourceException(javax.resource.ResourceException) InvalidResultSetAccessException(org.springframework.jca.cci.InvalidResultSetAccessException) RecordTypeNotSupportedException(org.springframework.jca.cci.RecordTypeNotSupportedException) NotSupportedException(javax.resource.NotSupportedException) CciOperationNotSupportedException(org.springframework.jca.cci.CciOperationNotSupportedException)

Example 2 with NotSupportedException

use of javax.resource.NotSupportedException in project spring-framework by spring-projects.

the class CciTemplateTests method testTemplateExecuteWithCreatorAndRecordFactoryNotSupported.

@Test
public void testTemplateExecuteWithCreatorAndRecordFactoryNotSupported() throws ResourceException {
    ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
    Connection connection = mock(Connection.class);
    Interaction interaction = mock(Interaction.class);
    Record inputRecord = mock(Record.class);
    final Record outputRecord = mock(Record.class);
    InteractionSpec interactionSpec = mock(InteractionSpec.class);
    given(connectionFactory.getConnection()).willReturn(connection);
    given(connectionFactory.getRecordFactory()).willThrow(new NotSupportedException("not supported"));
    given(connection.createInteraction()).willReturn(interaction);
    given(interaction.execute(interactionSpec, inputRecord, outputRecord)).willReturn(true);
    CciTemplate ct = new CciTemplate(connectionFactory);
    ct.setOutputRecordCreator(new RecordCreator() {

        @Override
        public Record createRecord(RecordFactory recordFactory) {
            assertTrue(recordFactory instanceof NotSupportedRecordFactory);
            return outputRecord;
        }
    });
    ct.execute(interactionSpec, inputRecord);
    verify(interaction).execute(interactionSpec, inputRecord, outputRecord);
    verify(interaction).close();
    verify(connection).close();
}
Also used : ConnectionFactory(javax.resource.cci.ConnectionFactory) RecordFactory(javax.resource.cci.RecordFactory) NotSupportedRecordFactory(org.springframework.jca.cci.connection.NotSupportedRecordFactory) Interaction(javax.resource.cci.Interaction) InteractionSpec(javax.resource.cci.InteractionSpec) RecordCreator(org.springframework.jca.cci.core.RecordCreator) Connection(javax.resource.cci.Connection) NotSupportedRecordFactory(org.springframework.jca.cci.connection.NotSupportedRecordFactory) MappedRecord(javax.resource.cci.MappedRecord) IndexedRecord(javax.resource.cci.IndexedRecord) Record(javax.resource.cci.Record) CciTemplate(org.springframework.jca.cci.core.CciTemplate) NotSupportedException(javax.resource.NotSupportedException) Test(org.junit.Test)

Example 3 with NotSupportedException

use of javax.resource.NotSupportedException in project teiid by teiid.

the class TransactionServerImpl method start.

/**
 * Global Transaction
 */
public void start(final String threadId, final XidImpl xid, int flags, int timeout, boolean singleTM) throws XATransactionException {
    TransactionContext tc = null;
    switch(flags) {
        case XAResource.TMNOFLAGS:
            {
                try {
                    checkXAState(threadId, xid, false, false);
                    tc = transactions.getOrCreateTransactionContext(threadId);
                    if (tc.getTransactionType() != TransactionContext.Scope.NONE) {
                        throw new XATransactionException(QueryPlugin.Event.TEIID30517, XAException.XAER_PROTO, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30517));
                    }
                    tc.setTransactionTimeout(timeout);
                    tc.setXid(xid);
                    tc.setTransactionType(TransactionContext.Scope.GLOBAL);
                    if (singleTM) {
                        tc.setTransaction(transactionManager.getTransaction());
                        if (tc.getTransaction() == null) {
                            // in theory we could inflow the txn and then change all of the methods to check singleTM off of the context
                            throw new XATransactionException(QueryPlugin.Event.TEIID30590, XAException.XAER_INVAL, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30590));
                        }
                    } else {
                        FutureWork<Transaction> work = new FutureWork<Transaction>(new Callable<Transaction>() {

                            @Override
                            public Transaction call() throws Exception {
                                return transactionManager.getTransaction();
                            }
                        }, 0);
                        workManager.doWork(work, WorkManager.INDEFINITE, tc, null);
                        tc.setTransaction(work.get());
                    }
                } catch (NotSupportedException e) {
                    throw new XATransactionException(QueryPlugin.Event.TEIID30512, XAException.XAER_INVAL, e);
                } catch (WorkException e) {
                    throw new XATransactionException(QueryPlugin.Event.TEIID30512, XAException.XAER_INVAL, e);
                } catch (InterruptedException e) {
                    throw new XATransactionException(QueryPlugin.Event.TEIID30512, XAException.XAER_INVAL, e);
                } catch (ExecutionException e) {
                    throw new XATransactionException(QueryPlugin.Event.TEIID30512, XAException.XAER_INVAL, e);
                } catch (SystemException e) {
                    throw new XATransactionException(QueryPlugin.Event.TEIID30512, XAException.XAER_INVAL, e);
                }
                break;
            }
        case XAResource.TMJOIN:
        case XAResource.TMRESUME:
            {
                tc = checkXAState(threadId, xid, true, false);
                TransactionContext threadContext = transactions.getOrCreateTransactionContext(threadId);
                if (threadContext.getTransactionType() != TransactionContext.Scope.NONE) {
                    throw new XATransactionException(QueryPlugin.Event.TEIID30517, XAException.XAER_PROTO, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30517));
                }
                if (flags == XAResource.TMRESUME && !tc.getSuspendedBy().remove(threadId)) {
                    throw new XATransactionException(QueryPlugin.Event.TEIID30518, XAException.XAER_PROTO, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30518, new Object[] { xid, threadId }));
                }
                break;
            }
        default:
            throw new XATransactionException(QueryPlugin.Event.TEIID30519, XAException.XAER_INVAL, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30519));
    }
    tc.setThreadId(threadId);
    transactions.addTransactionContext(tc);
}
Also used : Transaction(javax.transaction.Transaction) SystemException(javax.transaction.SystemException) TransactionContext(org.teiid.dqp.service.TransactionContext) WorkException(javax.resource.spi.work.WorkException) XATransactionException(org.teiid.client.xa.XATransactionException) NotSupportedException(javax.resource.NotSupportedException) ExecutionException(java.util.concurrent.ExecutionException) Callable(java.util.concurrent.Callable)

Example 4 with NotSupportedException

use of javax.resource.NotSupportedException in project Payara by payara.

the class ManagedConnectionImpl method getXAResource.

/**
 * Returns an <code>XAResource</code> instance.
 *
 * @return <code>XAResource</code> instance
 * @throws ResourceException     if the physical connection is not valid or
 *                               there is an error in allocating the
 *                               <code>XAResource</code> instance
 * @throws NotSupportedException if underlying datasource is not an
 *                               <code>XADataSource</code>
 */
@Override
public XAResource getXAResource() throws ResourceException {
    logFine("In getXAResource");
    checkIfValid();
    if (connectionType == ISXACONNECTION) {
        try {
            if (xar == null) {
                /**
                 * Using the wrapper XAResource.
                 */
                xar = new com.sun.gjc.spi.XAResourceImpl(((XAConnection) pc).getXAResource(), this);
            }
            return xar;
        } catch (SQLException sqle) {
            throw new ResourceException(sqle.getMessage(), sqle);
        }
    } else {
        throw new NotSupportedException("Cannot get an XAResource from a non XA connection");
    }
}
Also used : SQLException(java.sql.SQLException) ResourceException(javax.resource.ResourceException) NotSupportedException(javax.resource.NotSupportedException) XAConnection(javax.sql.XAConnection)

Example 5 with NotSupportedException

use of javax.resource.NotSupportedException in project spring-framework by spring-projects.

the class CciLocalTransactionManager method doBegin.

@Override
protected void doBegin(Object transaction, TransactionDefinition definition) {
    CciLocalTransactionObject txObject = (CciLocalTransactionObject) transaction;
    Connection con = null;
    try {
        con = getConnectionFactory().getConnection();
        if (logger.isDebugEnabled()) {
            logger.debug("Acquired Connection [" + con + "] for local CCI transaction");
        }
        txObject.setConnectionHolder(new ConnectionHolder(con));
        txObject.getConnectionHolder().setSynchronizedWithTransaction(true);
        con.getLocalTransaction().begin();
        int timeout = determineTimeout(definition);
        if (timeout != TransactionDefinition.TIMEOUT_DEFAULT) {
            txObject.getConnectionHolder().setTimeoutInSeconds(timeout);
        }
        TransactionSynchronizationManager.bindResource(getConnectionFactory(), txObject.getConnectionHolder());
    } catch (NotSupportedException ex) {
        ConnectionFactoryUtils.releaseConnection(con, getConnectionFactory());
        throw new CannotCreateTransactionException("CCI Connection does not support local transactions", ex);
    } catch (LocalTransactionException ex) {
        ConnectionFactoryUtils.releaseConnection(con, getConnectionFactory());
        throw new CannotCreateTransactionException("Could not begin local CCI transaction", ex);
    } catch (Throwable ex) {
        ConnectionFactoryUtils.releaseConnection(con, getConnectionFactory());
        throw new TransactionSystemException("Unexpected failure on begin of CCI local transaction", ex);
    }
}
Also used : LocalTransactionException(javax.resource.spi.LocalTransactionException) CannotCreateTransactionException(org.springframework.transaction.CannotCreateTransactionException) Connection(javax.resource.cci.Connection) TransactionSystemException(org.springframework.transaction.TransactionSystemException) NotSupportedException(javax.resource.NotSupportedException)

Aggregations

NotSupportedException (javax.resource.NotSupportedException)6 ResourceException (javax.resource.ResourceException)3 Connection (javax.resource.cci.Connection)3 SQLException (java.sql.SQLException)2 Map (java.util.Map)1 Callable (java.util.concurrent.Callable)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ExecutionException (java.util.concurrent.ExecutionException)1 ConnectionFactory (javax.resource.cci.ConnectionFactory)1 IndexedRecord (javax.resource.cci.IndexedRecord)1 Interaction (javax.resource.cci.Interaction)1 InteractionSpec (javax.resource.cci.InteractionSpec)1 MappedRecord (javax.resource.cci.MappedRecord)1 Record (javax.resource.cci.Record)1 RecordFactory (javax.resource.cci.RecordFactory)1 LocalTransactionException (javax.resource.spi.LocalTransactionException)1 WorkException (javax.resource.spi.work.WorkException)1 XAConnection (javax.sql.XAConnection)1 SystemException (javax.transaction.SystemException)1 Transaction (javax.transaction.Transaction)1