/** * @param tx Transaction. * @return {@code True} if given transaction is explicitly started user transaction. */ private boolean activeUserTx(@Nullable IgniteInternalTx tx) { if (tx != null && tx.user() && tx.state() == ACTIVE) { assert tx instanceof GridNearTxLocal : tx; return true; } return false; }
/** * @param ctx Grid kernal context. * @param txId Transaction ID. * @return Currently started user transaction, or {@code null} if none started. * @throws UnsupportedTxModeException If transaction mode is not supported when MVCC is enabled. * @throws NonMvccTransactionException If started transaction spans non MVCC caches. */ @Nullable public static GridNearTxLocal currentTx(GridKernalContext ctx, @Nullable GridCacheVersion txId) throws UnsupportedTxModeException, NonMvccTransactionException { IgniteTxManager tm = ctx.cache().context().tm(); IgniteInternalTx tx0 = txId == null ? tm.tx() : tm.tx(txId); GridNearTxLocal tx = tx0 != null && tx0.user() ? (GridNearTxLocal)tx0 : null; if (tx != null) { if (!tx.pessimistic()) { tx.setRollbackOnly(); throw new UnsupportedTxModeException(); } if (!tx.isOperationAllowed(true)) { tx.setRollbackOnly(); throw new NonMvccTransactionException(); } } return tx; }
/** * @param tx Transaction. * @return {@code True} if given transaction is explicitly started user transaction. */ private boolean activeUserTx(@Nullable IgniteInternalTx tx) { if (tx != null && tx.user() && tx.state() == ACTIVE) { assert tx instanceof GridNearTxLocal : tx; return true; } return false; }
/** * @param ctx Grid kernal context. * @param txId Transaction ID. * @return Currently started user transaction, or {@code null} if none started. */ @Nullable public static GridNearTxLocal tx(GridKernalContext ctx, @Nullable GridCacheVersion txId) { IgniteTxManager tm = ctx.cache().context().tm(); IgniteInternalTx tx0 = txId == null ? tm.tx() : tm.tx(txId); GridNearTxLocal tx = tx0 != null && tx0.user() ? (GridNearTxLocal)tx0 : null; if (tx != null) { if (!tx.pessimistic() || !tx.repeatableRead()) { tx.setRollbackOnly(); throw new IgniteSQLException("Only pessimistic repeatable read transactions are supported at the moment.", IgniteQueryErrorCode.UNSUPPORTED_OPERATION); } if (!tx.isOperationAllowed(true)) { tx.setRollbackOnly(); throw new IgniteSQLException("SQL queries and cache operations " + "may not be used in the same transaction.", IgniteQueryErrorCode.TRANSACTION_TYPE_MISMATCH); } } return tx; }