Giriş
Şu satırı dahil ederiz
import com.hazelcast.transaction.TransactionContext;
Bu sınıfı yaratmak için şöyle yaparız. Daha sonra, rollbackTransaction(), commitTransaction() gibi çağrılar yapılır
TransactionOptions options = ...; TransactionContext context = hazelcastInstance.newTransactionContext(options);
Örnek - TWO_PHASE
Şöyle yaparız
import com.hazelcast.transaction.TransactionOptions; HazelcastInstance hazelcastInstance = ...; TransactionOptions options = new TransactionOptions() .setTransactionType(TransactionType.TWO_PHASE); TransactionContext context = hazelcastInstance.newTransactionContext(options);
Örnek - ONE_PHASE
Şöyle yaparız
HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance(); TransactionOptions options = new TransactionOptions() .setTransactionType(TransactionOptions.TransactionType.ONE_PHASE); TransactionContext context = hazelcastInstance.newTransactionContext(options);
Örnek - ONE_PHASE + Timeout
Şöyle yaparız. timeout commit() yapılınca tespit edilir.
TransactionOptions options = new TransactionOptions() .setTransactionType(TransactionOptions.TransactionType.ONE_PHASE); options.setTimeout(1, TimeUnit.SECONDS); TransactionContext context = hazelcastInstance.newTransactionContext (options);
Örnek - XA Transaction
Şöyle yaparız
HazelcastInstance instance = ... HazelcastXAResource xaResource = instance.getXAResource(); UserTransactionManager tm = new UserTransactionManager(); tm.begin(); Transaction transaction = tm.getTransaction(); transaction.enlistResource(xaResource); TransactionContext context = xaResource.getTransactionContext(); TransactionalMap<Object, Object> map = context.getMap("map"); map.put("key", "val"); transaction.delistResource(xaResource, XAResource.TMSUCCESS); tm.commit();
getMap metodu
TransactionalMap döndürür.
rollbackTransaction metodu
Örnek
Şöyle yaparız
TransactionContext context = hz.newTransactionContext(options); context.beginTransaction(); try { ... } catch (Exception e) { context.rollbackTransaction(); }
Hiç yorum yok:
Yorum Gönder