K
- type of the map keyV
- type of the map valuepublic interface TransactionalMap<K,V> extends TransactionalObject, BaseMap<K,V>
BaseMap
.
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();
}
Modifier and Type | Method and Description |
---|---|
boolean |
containsKey(Object key)
Transactional implementation of
IMap.containsKey(Object) . |
void |
delete(Object key)
Transactional implementation of
IMap.delete(Object) . |
V |
get(Object key)
Transactional implementation of
IMap.get(Object) . |
V |
getForUpdate(Object key)
Locks the key and then gets and returns the value to which the specified
key is mapped.
|
boolean |
isEmpty()
Transactional implementation of
Map.isEmpty() . |
Set<K> |
keySet()
Transactional implementation of
IMap.keySet() . |
Set<K> |
keySet(Predicate<K,V> predicate)
Transactional implementation of
IMap.keySet(com.hazelcast.query.Predicate) . |
V |
put(K key,
V value)
Transactional implementation of
IMap.put(Object, Object) . |
V |
put(K key,
V value,
long ttl,
TimeUnit timeunit)
Transactional implementation of
IMap.put(Object, Object, long, TimeUnit) . |
V |
putIfAbsent(K key,
V value)
Transactional implementation of
IMap.putIfAbsent(Object, Object) . |
V |
remove(Object key)
Transactional implementation of
IMap.remove(Object) . |
boolean |
remove(Object key,
Object value)
Transactional implementation of
IMap.remove(Object, Object) . |
V |
replace(K key,
V value)
Transactional implementation of
IMap.replace(Object, Object) . |
boolean |
replace(K key,
V oldValue,
V newValue)
Transactional implementation of
IMap.replace(Object, Object, Object) . |
void |
set(K key,
V value)
Transactional implementation of
IMap.set(Object, Object) . |
int |
size()
Transactional implementation of
Map.size() . |
Collection<V> |
values()
Transactional implementation of
IMap.values() . |
Collection<V> |
values(Predicate<K,V> predicate)
Transactional implementation of
IMap.values(com.hazelcast.query.Predicate) . |
destroy, getName, getPartitionKey, getServiceName
boolean containsKey(Object key)
IMap.containsKey(Object)
.containsKey
in interface BaseMap<K,V>
key
- The specified key.true
if this map contains an entry for the specified key.NullPointerException
- if the specified key is null
IMap.containsKey(Object)
V get(Object key)
IMap.get(Object)
.get
in interface BaseMap<K,V>
key
- The specified key.NullPointerException
- if the specified key is null
IMap.get(Object)
V getForUpdate(Object key)
NullPointerException
- if the specified key is null
TransactionTimedOutException
- if the key could not be locked for update in the transaction timeoutIMap.get(Object)
int size()
Map.size()
.size
in interface BaseMap<K,V>
Map.size()
boolean isEmpty()
Map.isEmpty()
.isEmpty
in interface BaseMap<K,V>
true
if this map contains no entries.Map.isEmpty()
V put(K key, V value)
IMap.put(Object, Object)
.
The object to be put will be accessible only in the current transaction context till transaction is committed.
put
in interface BaseMap<K,V>
key
- The specified key.value
- The value to associate with the key.key
or null
if there was no mapping for key
.NullPointerException
- if the specified key or value is null
TransactionTimedOutException
- if the key could not be locked for update in the transaction timeoutIMap.put(Object, Object)
V put(K key, V value, long ttl, TimeUnit timeunit)
IMap.put(Object, Object, long, TimeUnit)
.
The object to be put will be accessible only in the current transaction context till transaction is committed.
put
in interface BaseMap<K,V>
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 ttlkey
or null
if there was no mapping for key
.NullPointerException
- if the specified key, value or timeunit is null
TransactionTimedOutException
- if the key could not be locked for update in the transaction timeoutIMap.put(Object, Object, long, TimeUnit)
void set(K key, V value)
IMap.set(Object, Object)
.
The object to be set will be accessible only in the current transaction context till transaction is committed.
set
in interface BaseMap<K,V>
key
- The specified key.value
- The value to associate with the key.NullPointerException
- if the specified key or value is null
TransactionTimedOutException
- if the key could not be locked for update in the transaction timeoutIMap.set(Object, Object)
V putIfAbsent(K key, V value)
IMap.putIfAbsent(Object, Object)
.
The object to be put will be accessible only in the current transaction context until the transaction is committed.
putIfAbsent
in interface BaseMap<K,V>
key
- The specified key.value
- The value to associate with the key when there is no previous value.key
, or null
if there was no mapping for key
.NullPointerException
- if the specified key or value is null
TransactionTimedOutException
- if the key could not be locked for update in the transaction timeoutIMap.putIfAbsent(Object, Object)
V replace(K key, V value)
IMap.replace(Object, Object)
.
The object to be replaced will be accessible only in the current transaction context until the transaction is committed.
replace
in interface BaseMap<K,V>
key
- The specified key.value
- The value to replace the previous value.key
, or null
if there was no mapping for key
.NullPointerException
- if the specified key or null
TransactionTimedOutException
- if the key could not be locked for update in the transaction timeoutIMap.replace(Object, Object)
boolean replace(K key, V oldValue, V newValue)
IMap.replace(Object, Object, Object)
.
The object to be replaced will be accessible only in the current transaction context until the transaction is committed.
replace
in interface BaseMap<K,V>
key
- The specified key.oldValue
- Replace the key value if it is the old value.newValue
- The new value to replace the old value.true
if the value was replaced.NullPointerException
- if the specified key, oldValue or newValue is null
TransactionTimedOutException
- if the key could not be locked for update in the transaction timeoutIMap.replace(Object, Object, Object)
V remove(Object key)
IMap.remove(Object)
.
The object to be removed will be removed from only the current transaction context until the transaction is committed.
remove
in interface BaseMap<K,V>
key
- Remove the mapping for this key.key
, or null
if there was no mapping for key
.NullPointerException
- if the specified key is null
TransactionTimedOutException
- if the key could not be locked for update in the transaction timeoutIMap.remove(Object)
void delete(Object key)
IMap.delete(Object)
.
The object to be deleted will be removed from only the current transaction context until the transaction is committed.
delete
in interface BaseMap<K,V>
key
- Remove the mapping for this key.NullPointerException
- if the specified key is null
TransactionTimedOutException
- if the key could not be locked for update in the transaction timeoutIMap.delete(Object)
boolean remove(Object key, Object value)
IMap.remove(Object, Object)
.
The object to be removed will be removed from only the current transaction context until the transaction is committed.
remove
in interface BaseMap<K,V>
key
- The specified key.value
- Remove the key if it has this value.true
if the value was removed.NullPointerException
- if the specified key or value null
TransactionTimedOutException
- if the key could not be locked for update in the transaction timeoutIMap.remove(Object, Object)
Set<K> keySet()
IMap.keySet()
.keySet
in interface BaseMap<K,V>
IMap.keySet()
Set<K> keySet(Predicate<K,V> predicate)
IMap.keySet(com.hazelcast.query.Predicate)
.keySet
in interface BaseMap<K,V>
predicate
- specified query criteria.NullPointerException
- if the specified predicate is null
IMap.keySet(com.hazelcast.query.Predicate)
Collection<V> values()
IMap.values()
.values
in interface BaseMap<K,V>
IMap.values()
Collection<V> values(Predicate<K,V> predicate)
IMap.values(com.hazelcast.query.Predicate)
.values
in interface BaseMap<K,V>
predicate
- specified query criteria.NullPointerException
- if the specified predicate is null
IMap.values(com.hazelcast.query.Predicate)
Copyright © 2020 Hazelcast, Inc.. All rights reserved.