public void Rollback(int transactionThreadId) { if (!this._engine.DBisOperable) { return; } TransactionUnit transactionUnit = this.GetTransactionUnit(transactionThreadId); if (transactionUnit != null) { List <ITransactable> tablesForTransaction = transactionUnit.GetTransactionWriteTables(); if (tablesForTransaction.Count() == 0) { //DO NOTHING } else if (tablesForTransaction.Count() == 1) { try { tablesForTransaction[0].SingleRollback(); } catch (OperationCanceledException ex) { throw ex; } //catch (System.Threading.ThreadAbortException ex) //{ // //We don'T make DBisOperable = false; // throw ex; //} catch (Exception ex) { this._engine.DBisOperable = false; this._engine.DBisOperableReason = "TransactionsCoordinator.Rollback tablesForTransaction.Count = 1"; //CASCADE, WHICH MUST BRING TO DB is not opearatbale state throw ex; } } else { //Rollback MANY AT ONCE try { foreach (var tt1 in tablesForTransaction) { tt1.SingleRollback(); } } catch (OperationCanceledException ex) { throw ex; } //catch (System.Threading.ThreadAbortException ex1) //{ // //We don'T make DBisOperable = false; // throw ex1; //} catch (Exception ex1) { //CASCADE, WHICH MUST BRING TO DB is not opearatbale state this._engine.DBisOperable = false; this._engine.DBisOperableReason = "TransactionsCoordinator.Rollback tablesForTransaction.Count > 1"; throw ex1; } } } else { throw DBriizeException.Throw(DBriizeException.eDBriizeExceptions.TRANSACTION_DOESNT_EXIST); } }
public void Commit(int transactionThreadId) { if (!this._engine.DBisOperable) { throw DBriizeException.Throw(DBriizeException.eDBriizeExceptions.DB_IS_NOT_OPERABLE, this._engine.DBisOperableReason, new Exception()); } TransactionUnit transactionUnit = this.GetTransactionUnit(transactionThreadId); if (transactionUnit != null) { List <ITransactable> tablesForTransaction = transactionUnit.GetTransactionWriteTables(); if (tablesForTransaction.Count() == 0) { //DO NOTHING } else if (tablesForTransaction.Count() == 1) { try { tablesForTransaction[0].SingleCommit(); } catch (OperationCanceledException ex) { throw ex; } //catch (System.Threading.ThreadAbortException ex) // { // //We don'T make DBisOperable = false; // throw ex; // } catch (TableNotOperableException ex1) { this._engine.DBisOperable = false; this._engine.DBisOperableReason = "TransactionsCoordinator.Commit tablesForTransaction.Count = 1"; //CASCADE, WHICH MUST BRING TO DB is not opearatbale state throw ex1; } catch (System.Exception ex) { //Rollback was ok, so we just return mistake, why commit failed //CASCADE throw ex; } } else { //Gettign new TransactionJournalId ulong tranNumber = this._engine._transactionsJournal.GetTransactionNumber(); foreach (var tt in tablesForTransaction) { try { //Adding table this._engine._transactionsJournal.AddTableForTransaction(tranNumber, tt); tt.ITRCommit(); } catch (Exception ex) { //SMTH HAPPENED INSIDE OF COMMIT Trying to rollBack tables try { foreach (var tt1 in tablesForTransaction) { tt1.ITRRollBack(); } this._engine._transactionsJournal.RemoveTransactionFromDictionary(tranNumber); } catch (OperationCanceledException ex1) { throw ex1; } //catch (System.Threading.ThreadAbortException ex1) // { // //We don'T make DBisOperable = false; // throw ex1; // } catch (Exception ex1) { //CASCADE, WHICH MUST BRING TO DB is not opearatbale state this._engine.DBisOperable = false; this._engine.DBisOperableReason = "TransactionsCoordinator.Commit tablesForTransaction.Count > 1"; throw new Exception(ex.ToString() + " --> " + ex1.ToString()); } //In case if rollback succeeded we throw exception brough by bad commit //CASCADE from LTrieRootNode.TransactionalCommit throw ex; } } //end of foreach //Here we appear if all tables were succesfully commited (but it's not visible still for READING THREDS and all tables still have their rollback files active) //We have to finish the transaction try { this._engine._transactionsJournal.FinishTransaction(tranNumber); } catch (OperationCanceledException ex) { throw ex; } //catch (System.Threading.ThreadAbortException ex) // { // //We don'T make DBisOperable = false; // throw ex; // } catch (Exception ex) { this._engine.DBisOperable = false; this._engine.DBisOperableReason = "TransactionsCoordinator.Commit FinishTransaction"; throw ex; } } } else { throw DBriizeException.Throw(DBriizeException.eDBriizeExceptions.TRANSACTION_DOESNT_EXIST); } }