Interface TransactionalMap<K,V>
- Type Parameters:
K- type of the map keyV- type of the map value
- All Superinterfaces:
BaseMap<K,,V> DistributedObject,TransactionalObject
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();
}
-
Method Summary
Modifier and TypeMethodDescriptionbooleancontainsKey(Object key) Transactional implementation ofIMap.containsKey(Object).voidTransactional implementation ofIMap.delete(Object).Transactional implementation ofIMap.get(Object).getForUpdate(Object key) Locks the key and then gets and returns the value to which the specified key is mapped.booleanisEmpty()Transactional implementation ofMap.isEmpty().keySet()Transactional implementation ofIMap.keySet().Transactional implementation ofIMap.keySet(com.hazelcast.query.Predicate).Transactional implementation ofIMap.put(Object, Object).Transactional implementation ofIMap.put(Object, Object, long, TimeUnit).putIfAbsent(K key, V value) Transactional implementation ofIMap.putIfAbsent(Object, Object).Transactional implementation ofIMap.remove(Object).booleanTransactional implementation ofIMap.remove(Object, Object).Transactional implementation ofIMap.replace(Object, Object).booleanTransactional implementation ofIMap.replace(Object, Object, Object).voidTransactional implementation ofIMap.set(Object, Object).intsize()Transactional implementation ofMap.size().values()Transactional implementation ofIMap.values().Transactional implementation ofIMap.values(com.hazelcast.query.Predicate).Methods inherited from interface com.hazelcast.core.DistributedObject
destroy, getDestroyContextForTenant, getName, getPartitionKey, getServiceName
-
Method Details
-
containsKey
Transactional implementation ofIMap.containsKey(Object).- Specified by:
containsKeyin interfaceBaseMap<K,V> - Parameters:
key- The specified key.- Returns:
trueif this map contains an entry for the specified key.- Throws:
NullPointerException- if the specified key isnull- See Also:
-
get
Transactional implementation ofIMap.get(Object).- Specified by:
getin interfaceBaseMap<K,V> - Parameters:
key- The specified key.- Returns:
- The value for the specified key.
- Throws:
NullPointerException- if the specified key isnull- See Also:
-
getForUpdate
Locks the key and then gets and returns the value to which the specified key is mapped. The lock will be released at the end of the transaction (either commit or rollback).- Throws:
NullPointerException- if the specified key isnullTransactionTimedOutException- if the key could not be locked for update in the transaction timeout- See Also:
-
size
int size()Transactional implementation ofMap.size(). -
isEmpty
boolean isEmpty()Transactional implementation ofMap.isEmpty(). -
put
Transactional implementation ofIMap.put(Object, Object).The object to be put will be accessible only in the current transaction context till transaction is committed.
- Specified by:
putin interfaceBaseMap<K,V> - Parameters:
key- The specified key.value- The value to associate with the key.- Returns:
- Previous value associated with
keyornullif there was no mapping forkey. - Throws:
NullPointerException- if the specified key or value isnullTransactionTimedOutException- if the key could not be locked for update in the transaction timeout- See Also:
-
put
Transactional implementation ofIMap.put(Object, Object, long, TimeUnit).The object to be put will be accessible only in the current transaction context till transaction is committed.
- Specified by:
putin interfaceBaseMap<K,V> - Parameters:
key- The specified key.value- The value to associate with the key.ttl- maximum time for this entry to stay in the map 0 means infinite.timeunit- time unit for the ttl- Returns:
- Previous value associated with
keyornullif there was no mapping forkey. - Throws:
NullPointerException- if the specified key, value or timeunit isnullTransactionTimedOutException- if the key could not be locked for update in the transaction timeout- See Also:
-
set
Transactional implementation ofIMap.set(Object, Object).The object to be set will be accessible only in the current transaction context till transaction is committed.
- Specified by:
setin interfaceBaseMap<K,V> - Parameters:
key- The specified key.value- The value to associate with the key.- Throws:
NullPointerException- if the specified key or value isnullTransactionTimedOutException- if the key could not be locked for update in the transaction timeout- See Also:
-
putIfAbsent
Transactional implementation ofIMap.putIfAbsent(Object, Object).The object to be put will be accessible only in the current transaction context until the transaction is committed.
- Specified by:
putIfAbsentin interfaceBaseMap<K,V> - Parameters:
key- The specified key.value- The value to associate with the key when there is no previous value.- Returns:
- The previous value associated with
key, ornullif there was no mapping forkey. - Throws:
NullPointerException- if the specified key or value isnullTransactionTimedOutException- if the key could not be locked for update in the transaction timeout- See Also:
-
replace
Transactional implementation ofIMap.replace(Object, Object).The object to be replaced will be accessible only in the current transaction context until the transaction is committed.
- Specified by:
replacein interfaceBaseMap<K,V> - Parameters:
key- The specified key.value- The value to replace the previous value.- Returns:
- The previous value associated with
key, ornullif there was no mapping forkey. - Throws:
NullPointerException- if the specified key ornullTransactionTimedOutException- if the key could not be locked for update in the transaction timeout- See Also:
-
replace
Transactional implementation ofIMap.replace(Object, Object, Object).The object to be replaced will be accessible only in the current transaction context until the transaction is committed.
- Specified by:
replacein interfaceBaseMap<K,V> - Parameters:
key- The specified key.oldValue- Replace the key value if it is the old value.newValue- The new value to replace the old value.- Returns:
trueif the value was replaced.- Throws:
NullPointerException- if the specified key, oldValue or newValue isnullTransactionTimedOutException- if the key could not be locked for update in the transaction timeout- See Also:
-
remove
Transactional implementation ofIMap.remove(Object).The object to be removed will be removed from only the current transaction context until the transaction is committed.
- Specified by:
removein interfaceBaseMap<K,V> - Parameters:
key- Remove the mapping for this key.- Returns:
- The previous value associated with
key, ornullif there was no mapping forkey. - Throws:
NullPointerException- if the specified key isnullTransactionTimedOutException- if the key could not be locked for update in the transaction timeout- See Also:
-
delete
Transactional implementation ofIMap.delete(Object).The object to be deleted will be removed from only the current transaction context until the transaction is committed.
- Specified by:
deletein interfaceBaseMap<K,V> - Parameters:
key- Remove the mapping for this key.- Throws:
NullPointerException- if the specified key isnullTransactionTimedOutException- if the key could not be locked for update in the transaction timeout- See Also:
-
remove
Transactional implementation ofIMap.remove(Object, Object).The object to be removed will be removed from only the current transaction context until the transaction is committed.
- Specified by:
removein interfaceBaseMap<K,V> - Parameters:
key- The specified key.value- Remove the key if it has this value.- Returns:
trueif the value was removed.- Throws:
NullPointerException- if the specified key or valuenullTransactionTimedOutException- if the key could not be locked for update in the transaction timeout- See Also:
-
keySet
Transactional implementation ofIMap.keySet(). -
keySet
Transactional implementation ofIMap.keySet(com.hazelcast.query.Predicate).- Specified by:
keySetin interfaceBaseMap<K,V> - Parameters:
predicate- specified query criteria.- Returns:
- result key set of the query.
- Throws:
NullPointerException- if the specified predicate isnull- See Also:
-
values
Collection<V> values()Transactional implementation ofIMap.values(). -
values
Transactional implementation ofIMap.values(com.hazelcast.query.Predicate).- Specified by:
valuesin interfaceBaseMap<K,V> - Parameters:
predicate- specified query criteria.- Returns:
- result value collection of the query.
- Throws:
NullPointerException- if the specified predicate isnull- See Also:
-