use of com.hazelcast.transaction.TransactionException in project hazelcast by hazelcast.
the class AbstractTransactionalCollectionProxy method remove.
public boolean remove(E e) {
checkTransactionActive();
checkObjectNotNull(e);
Data value = getNodeEngine().toData(e);
Iterator<CollectionItem> iterator = getCollection().iterator();
long reservedItemId = INVALID_ITEM_ID;
while (iterator.hasNext()) {
CollectionItem item = iterator.next();
if (value.equals(item.getValue())) {
reservedItemId = item.getItemId();
break;
}
}
CollectionReserveRemoveOperation operation = new CollectionReserveRemoveOperation(name, reservedItemId, value, tx.getTxnId());
try {
Future<CollectionItem> future = operationService.invokeOnPartition(getServiceName(), operation, partitionId);
CollectionItem item = future.get();
if (item != null) {
if (reservedItemId == item.getItemId()) {
iterator.remove();
removeFromRecord(reservedItemId);
itemIdSet.remove(reservedItemId);
return true;
}
if (!itemIdSet.add(item.getItemId())) {
throw new TransactionException("Duplicate itemId: " + item.getItemId());
}
CollectionTxnRemoveOperation op = new CollectionTxnRemoveOperation(name, item.getItemId());
putToRecord(op);
return true;
}
} catch (Throwable t) {
throw rethrow(t);
}
return false;
}
use of com.hazelcast.transaction.TransactionException in project hazelcast by hazelcast.
the class XATransactionRollbackMessageTask method call.
@Override
protected Object call() throws Exception {
UUID transactionId = parameters;
TransactionContext transactionContext = endpoint.getTransactionContext(transactionId);
if (transactionContext == null) {
throw new TransactionException("No transaction context with given transactionId: " + transactionId);
}
Transaction transaction = TransactionAccessor.getTransaction(transactionContext);
transaction.rollback();
endpoint.removeTransactionContext(transactionId);
return null;
}
use of com.hazelcast.transaction.TransactionException in project hazelcast by hazelcast.
the class XATransactionPrepareMessageTask method call.
@Override
protected Object call() throws Exception {
UUID transactionId = parameters;
TransactionContext transactionContext = endpoint.getTransactionContext(transactionId);
if (transactionContext == null) {
throw new TransactionException("No transaction context with given transactionId: " + transactionId);
}
Transaction transaction = TransactionAccessor.getTransaction(transactionContext);
transaction.prepare();
return null;
}
use of com.hazelcast.transaction.TransactionException in project hazelcast by hazelcast.
the class ClientTransactionManagerServiceImpl method executeTransaction.
@Override
public <T> T executeTransaction(@Nonnull TransactionOptions options, @Nonnull TransactionalTask<T> task) throws TransactionException {
checkNotNull(options, "TransactionOptions must not be null!");
checkNotNull(task, "TransactionalTask is required!");
final TransactionContext context = newTransactionContext(options);
context.beginTransaction();
try {
final T value = task.execute(context);
context.commitTransaction();
return value;
} catch (Throwable e) {
context.rollbackTransaction();
if (e instanceof TransactionException) {
throw (TransactionException) e;
}
if (e.getCause() instanceof TransactionException) {
throw (TransactionException) e.getCause();
}
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
}
throw new TransactionException(e);
}
}
use of com.hazelcast.transaction.TransactionException in project hazelcast by hazelcast.
the class TransactionalSetProxy method add.
@Override
public boolean add(E e) {
checkTransactionActive();
checkObjectNotNull(e);
Data value = getNodeEngine().toData(e);
if (!getCollection().add(new CollectionItem(INVALID_ITEM_ID, value))) {
return false;
}
CollectionReserveAddOperation operation = new CollectionReserveAddOperation(name, tx.getTxnId(), value);
try {
Future<Long> future = operationService.invokeOnPartition(getServiceName(), operation, partitionId);
Long itemId = future.get();
if (itemId != null) {
if (!itemIdSet.add(itemId)) {
throw new TransactionException("Duplicate itemId: " + itemId);
}
CollectionTxnAddOperation op = new CollectionTxnAddOperation(name, itemId, value);
putToRecord(op);
return true;
}
} catch (Throwable t) {
throw ExceptionUtil.rethrow(t);
}
return false;
}
Aggregations