Search in sources :

Example 1 with TransactionalObject

use of com.hazelcast.transaction.TransactionalObject 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 TransactionalObject

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

the class TransactionContextImpl method getTransactionalObject.

@SuppressWarnings("unchecked")
@Override
public TransactionalObject getTransactionalObject(String serviceName, String name) {
    checkActive(serviceName, name);
    if (requiresBackupLogs(serviceName)) {
        transaction.ensureBackupLogsExist();
    }
    TransactionalObjectKey key = new TransactionalObjectKey(serviceName, name);
    TransactionalObject obj = txnObjectMap.get(key);
    if (obj != null) {
        return obj;
    }
    TransactionalService transactionalService = getTransactionalService(serviceName);
    nodeEngine.getProxyService().initializeDistributedObject(serviceName, name);
    obj = transactionalService.createTransactionalObject(name, transaction);
    txnObjectMap.put(key, obj);
    return obj;
}
Also used : TransactionalService(com.hazelcast.spi.TransactionalService) TransactionalObject(com.hazelcast.transaction.TransactionalObject)

Example 3 with TransactionalObject

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

the class TransactionContextImpl_backupLogsTest method assertBackupLogCreationForced.

public void assertBackupLogCreationForced(String serviceName) {
    TransactionOptions options = new TransactionOptions();
    TransactionContextImpl txContext = new TransactionContextImpl(localTxManager, localNodeEngine, options, ownerUuid, false);
    txContext.beginTransaction();
    TransactionalObject result = txContext.getTransactionalObject(serviceName, "foo");
    assertNotNull(result);
    assertNotNull(remoteTxManager.txBackupLogs.get(txContext.getTxnId()));
}
Also used : TransactionOptions(com.hazelcast.transaction.TransactionOptions) TransactionalObject(com.hazelcast.transaction.TransactionalObject)

Example 4 with TransactionalObject

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

the class TransactionContextImpl_backupLogsTest method assertBackupLogCreationNotForced.

public void assertBackupLogCreationNotForced(String serviceName) {
    TransactionOptions options = new TransactionOptions();
    TransactionContextImpl txContext = new TransactionContextImpl(localTxManager, localNodeEngine, options, ownerUuid, false);
    txContext.beginTransaction();
    TransactionalObject result = txContext.getTransactionalObject(serviceName, "foo");
    assertNotNull(result);
    assertNull(remoteTxManager.txBackupLogs.get(txContext.getTxnId()));
}
Also used : TransactionOptions(com.hazelcast.transaction.TransactionOptions) TransactionalObject(com.hazelcast.transaction.TransactionalObject)

Example 5 with TransactionalObject

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

the class XATransactionContextImpl method getTransactionalObject.

@SuppressWarnings("unchecked")
@Override
public TransactionalObject 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) {
        return obj;
    }
    final Object service = nodeEngine.getService(serviceName);
    if (service instanceof TransactionalService) {
        nodeEngine.getProxyService().initializeDistributedObject(serviceName, name);
        obj = ((TransactionalService) service).createTransactionalObject(name, transaction);
        txnObjectMap.put(key, obj);
    } else {
        throw new IllegalArgumentException("Service[" + serviceName + "] is not transactional!");
    }
    return obj;
}
Also used : TransactionalService(com.hazelcast.spi.TransactionalService) TransactionNotActiveException(com.hazelcast.transaction.TransactionNotActiveException) TransactionalObject(com.hazelcast.transaction.TransactionalObject) TransactionalObject(com.hazelcast.transaction.TransactionalObject) TransactionalObjectKey(com.hazelcast.transaction.impl.TransactionalObjectKey)

Aggregations

TransactionalObject (com.hazelcast.transaction.TransactionalObject)6 TransactionNotActiveException (com.hazelcast.transaction.TransactionNotActiveException)3 TransactionalObjectKey (com.hazelcast.transaction.impl.TransactionalObjectKey)3 TransactionalService (com.hazelcast.spi.TransactionalService)2 TransactionOptions (com.hazelcast.transaction.TransactionOptions)2 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