Search in sources :

Example 1 with TransactionNotActiveException

use of com.hazelcast.transaction.TransactionNotActiveException in project hazelcast by hazelcast.

the class TransactionContextProxy method getTransactionalObject.

@Override
public <T extends TransactionalObject> T getTransactionalObject(String serviceName, String name) {
    if (transaction.getState() != Transaction.State.ACTIVE) {
        throw new TransactionNotActiveException("No transaction is found while accessing " + "transactional object -> " + serviceName + "[" + name + "]!");
    }
    TransactionalObjectKey key = new TransactionalObjectKey(serviceName, name);
    TransactionalObject obj = txnObjectMap.get(key);
    if (obj == null) {
        if (serviceName.equals(QueueService.SERVICE_NAME)) {
            obj = new ClientTxnQueueProxy(name, this);
        } else if (serviceName.equals(MapService.SERVICE_NAME)) {
            obj = new ClientTxnMapProxy(name, this);
        } else if (serviceName.equals(MultiMapService.SERVICE_NAME)) {
            obj = new ClientTxnMultiMapProxy(name, this);
        } else if (serviceName.equals(ListService.SERVICE_NAME)) {
            obj = new ClientTxnListProxy(name, this);
        } else if (serviceName.equals(SetService.SERVICE_NAME)) {
            obj = new ClientTxnSetProxy(name, this);
        }
        if (obj == null) {
            throw new IllegalArgumentException("Service[" + serviceName + "] is not transactional!");
        }
        txnObjectMap.put(key, obj);
    }
    return (T) obj;
}
Also used : TransactionNotActiveException(com.hazelcast.transaction.TransactionNotActiveException) TransactionalObject(com.hazelcast.transaction.TransactionalObject) TransactionalObjectKey(com.hazelcast.transaction.impl.TransactionalObjectKey)

Example 2 with TransactionNotActiveException

use of com.hazelcast.transaction.TransactionNotActiveException in project hazelcast by hazelcast.

the class TransactionContextProxy method getTransactionalObject.

@Override
public <T extends TransactionalObject> T getTransactionalObject(String serviceName, String name) {
    if (transaction.getState() != Transaction.State.ACTIVE) {
        throw new TransactionNotActiveException("No transaction is found while accessing " + "transactional object -> " + serviceName + "[" + name + "]!");
    }
    TransactionalObjectKey key = new TransactionalObjectKey(serviceName, name);
    TransactionalObject obj = txnObjectMap.get(key);
    if (obj == null) {
        if (serviceName.equals(QueueService.SERVICE_NAME)) {
            obj = new ClientTxnQueueProxy(name, this);
        } else if (serviceName.equals(MapService.SERVICE_NAME)) {
            obj = new ClientTxnMapProxy(name, this);
        } else if (serviceName.equals(MultiMapService.SERVICE_NAME)) {
            obj = new ClientTxnMultiMapProxy(name, this);
        } else if (serviceName.equals(ListService.SERVICE_NAME)) {
            obj = new ClientTxnListProxy(name, this);
        } else if (serviceName.equals(SetService.SERVICE_NAME)) {
            obj = new ClientTxnSetProxy(name, this);
        }
        if (obj == null) {
            throw new IllegalArgumentException("Service[" + serviceName + "] is not transactional!");
        }
        txnObjectMap.put(key, obj);
    }
    return (T) obj;
}
Also used : TransactionNotActiveException(com.hazelcast.transaction.TransactionNotActiveException) TransactionalObject(com.hazelcast.transaction.TransactionalObject) TransactionalObjectKey(com.hazelcast.transaction.impl.TransactionalObjectKey)

Example 3 with TransactionNotActiveException

use of com.hazelcast.transaction.TransactionNotActiveException in project hazelcast by hazelcast.

the class XATransactionProxy method prepare.

void prepare() {
    checkTimeout();
    try {
        if (state != ACTIVE) {
            throw new TransactionNotActiveException("Transaction is not active");
        }
        ClientMessage request = XATransactionPrepareCodec.encodeRequest(txnId);
        ClientTransactionUtil.invoke(request, txnId, client, connection);
        state = PREPARED;
    } catch (Exception e) {
        state = ROLLING_BACK;
        throw rethrow(e);
    }
}
Also used : TransactionNotActiveException(com.hazelcast.transaction.TransactionNotActiveException) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) TransactionException(com.hazelcast.transaction.TransactionException) TransactionNotActiveException(com.hazelcast.transaction.TransactionNotActiveException) XAException(javax.transaction.xa.XAException)

Example 4 with TransactionNotActiveException

use of com.hazelcast.transaction.TransactionNotActiveException in project hazelcast by hazelcast.

the class XATransactionContextProxy method getTransactionalObject.

@Override
public <T extends TransactionalObject> T getTransactionalObject(String serviceName, String name) {
    if (transaction.getState() != Transaction.State.ACTIVE) {
        throw new TransactionNotActiveException("No transaction is found while accessing " + "transactional object -> " + serviceName + "[" + name + "]!");
    }
    TransactionalObjectKey key = new TransactionalObjectKey(serviceName, name);
    TransactionalObject obj = txnObjectMap.get(key);
    if (obj == null) {
        if (serviceName.equals(QueueService.SERVICE_NAME)) {
            obj = new ClientTxnQueueProxy(name, this);
        } else if (serviceName.equals(MapService.SERVICE_NAME)) {
            obj = new ClientTxnMapProxy(name, this);
        } else if (serviceName.equals(MultiMapService.SERVICE_NAME)) {
            obj = new ClientTxnMultiMapProxy(name, this);
        } else if (serviceName.equals(ListService.SERVICE_NAME)) {
            obj = new ClientTxnListProxy(name, this);
        } else if (serviceName.equals(SetService.SERVICE_NAME)) {
            obj = new ClientTxnSetProxy(name, this);
        }
        if (obj == null) {
            throw new IllegalArgumentException("Service[" + serviceName + "] is not transactional!");
        }
        txnObjectMap.put(key, obj);
    }
    return (T) obj;
}
Also used : ClientTxnMultiMapProxy(com.hazelcast.client.impl.proxy.txn.ClientTxnMultiMapProxy) ClientTxnSetProxy(com.hazelcast.client.impl.proxy.txn.ClientTxnSetProxy) TransactionNotActiveException(com.hazelcast.transaction.TransactionNotActiveException) ClientTxnQueueProxy(com.hazelcast.client.impl.proxy.txn.ClientTxnQueueProxy) ClientTxnMapProxy(com.hazelcast.client.impl.proxy.txn.ClientTxnMapProxy) TransactionalObject(com.hazelcast.transaction.TransactionalObject) ClientTxnListProxy(com.hazelcast.client.impl.proxy.txn.ClientTxnListProxy) TransactionalObjectKey(com.hazelcast.transaction.impl.TransactionalObjectKey)

Example 5 with TransactionNotActiveException

use of com.hazelcast.transaction.TransactionNotActiveException in project hazelcast by hazelcast.

the class TransactionProxy method commit.

void commit() {
    try {
        if (state != ACTIVE) {
            throw new TransactionNotActiveException("Transaction is not active");
        }
        state = COMMITTING;
        checkThread();
        checkTimeout();
        ClientMessage request = TransactionCommitCodec.encodeRequest(txnId, threadId);
        invoke(request);
        state = COMMITTED;
    } catch (Exception e) {
        state = COMMIT_FAILED;
        throw rethrow(e);
    } finally {
        TRANSACTION_EXISTS.set(null);
    }
}
Also used : TransactionNotActiveException(com.hazelcast.transaction.TransactionNotActiveException) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) TransactionException(com.hazelcast.transaction.TransactionException) TransactionNotActiveException(com.hazelcast.transaction.TransactionNotActiveException)

Aggregations

TransactionNotActiveException (com.hazelcast.transaction.TransactionNotActiveException)9 TransactionalObject (com.hazelcast.transaction.TransactionalObject)5 TransactionalObjectKey (com.hazelcast.transaction.impl.TransactionalObjectKey)5 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)4 TransactionException (com.hazelcast.transaction.TransactionException)3 XAException (javax.transaction.xa.XAException)2 ClientTxnListProxy (com.hazelcast.client.impl.proxy.txn.ClientTxnListProxy)1 ClientTxnMapProxy (com.hazelcast.client.impl.proxy.txn.ClientTxnMapProxy)1 ClientTxnMultiMapProxy (com.hazelcast.client.impl.proxy.txn.ClientTxnMultiMapProxy)1 ClientTxnQueueProxy (com.hazelcast.client.impl.proxy.txn.ClientTxnQueueProxy)1 ClientTxnSetProxy (com.hazelcast.client.impl.proxy.txn.ClientTxnSetProxy)1 ClientTxnListProxy (com.hazelcast.client.proxy.txn.ClientTxnListProxy)1 ClientTxnMapProxy (com.hazelcast.client.proxy.txn.ClientTxnMapProxy)1 ClientTxnMultiMapProxy (com.hazelcast.client.proxy.txn.ClientTxnMultiMapProxy)1 ClientTxnQueueProxy (com.hazelcast.client.proxy.txn.ClientTxnQueueProxy)1 ClientTxnSetProxy (com.hazelcast.client.proxy.txn.ClientTxnSetProxy)1 TransactionalService (com.hazelcast.internal.services.TransactionalService)1 TransactionTimedOutException (com.hazelcast.transaction.TransactionTimedOutException)1