Interface TransactionalMap<K,V>

Type Parameters:
K - type of the map key
V - type of the map value
All Superinterfaces:
BaseMap<K,V>, DistributedObject, TransactionalObject

public interface TransactionalMap<K,V> extends TransactionalObject, BaseMap<K,V>
Transactional implementation of BaseMap.

MapStore Interaction

When using MapStore, the call to any MapStore method is outside the transactional boundary. If you need to have an XATransaction spanning Hazelcast operations and one more other XAResources (such as a database), you should not use MapStore. Instead, enlist both resources in a transaction as shown below:

 HazelcastInstance client = HazelcastClient.newHazelcastClient();

 UserTransactionManager tm = new UserTransactionManager();
 tm.setTransactionTimeout(60);
 tm.begin();

 HazelcastXAResource xaResource = client.getXAResource();
 Transaction transaction = tm.getTransaction();
 transaction.enlistResource(xaResource);

 // you can enlist more resources here like a database XAResource
 try {
      TransactionContext context = xaResource.getTransactionContext()
      TransactionalMap map = context.getMap("map");
      map.put("key", "value");
      final TransactionalQueue queue = context.getQueue("queue");
      queue.offer("item");

      // you can do other resource operations like store/delete to a database

      transaction.delistResource(xaResource, XAResource.TMSUCCESS);
      tm.commit();
 } catch (TransactionException t) {
      t.printStackTrace();
      transaction.delistResource(xaResource, XAResource.TMFAIL);
      tm.rollback();
 }
 
See Also: