Example #1
0
        internal static async Task RollbackTransactionAsync(Guid id)
        {
            await _locker.LockAsync();

            try
            {
                TransactionInternal transactionInternal = transactions[id];

                foreach (ObjectSerializer ser in transactionInternal.nrRecordsBeforeCommit.Keys)
                {
                    await ser.SaveNrRecordsAsync(transactionInternal.nrRecordsBeforeCommit[ser].Key, transactionInternal.nrRecordsBeforeCommit[ser].Value).ConfigureAwait(false);
                }
                foreach (TransactionObject trObj in transactionInternal.transactionObjects)
                {
                    await trObj.RollbackAsync().ConfigureAwait(false);
                }
                transactions.Remove(id);
                await transactionInternal.siaqodbInstance.DropTypeAsync <TransactionObjectHeader>().ConfigureAwait(false);

                await transactionInternal.siaqodbInstance.DropTypeAsync <TransactionTypeHeader>().ConfigureAwait(false);

                transactionInternal.siaqodbInstance.DropTransactionLog();
                transactionInternal.transaction.status = TransactionStatus.Closed;
                await transactionInternal.siaqodbInstance.FlushAsync().ConfigureAwait(false);
            }

            finally
            {
                _locker.Release();
            }
        }
Example #2
0
        public static Transaction BeginTransaction(Siaqodb siaqodb)
        {
            Transaction         trans = new Transaction();
            TransactionInternal trInt = new TransactionInternal(trans, siaqodb);

            transactions.Add(trans.ID, trInt);

            return(trans);
        }
Example #3
0
        internal static void RollbackTransaction(Guid id)
        {
            lock (_SyncRoot)
            {
                TransactionInternal transactionInternal = transactions[id];

                foreach (ObjectSerializer ser in transactionInternal.nrRecordsBeforeCommit.Keys)
                {
                    ser.SaveNrRecords(transactionInternal.nrRecordsBeforeCommit[ser].Key, transactionInternal.nrRecordsBeforeCommit[ser].Value);
                }
                foreach (TransactionObject trObj in transactionInternal.transactionObjects)
                {
                    trObj.Rollback();
                }
                transactions.Remove(id);
                transactionInternal.siaqodbInstance.DropType <TransactionObjectHeader>();
                transactionInternal.siaqodbInstance.DropType <TransactionTypeHeader>();
                transactionInternal.siaqodbInstance.DropTransactionLog();
                transactionInternal.transaction.status = TransactionStatus.Closed;
                transactionInternal.siaqodbInstance.Flush();
            }
        }
Example #4
0
        internal static void CommitTransaction(Guid id)
        {
            lock (_SyncRoot)
            {
                TransactionInternal transactionInternal = transactions[id];

                TransactionObjectHeader lastHeader      = null;
                TransactionsStorage     transactStorage = transactionInternal.siaqodbInstance.GetTransactionLogStorage();
                foreach (SqoTypeInfo ti in transactionInternal.tiInvolvedInTransaction)
                {
                    transactionInternal.siaqodbInstance.PutIndexPersiststenceState(ti, false);
                }
                transactionInternal.siaqodbInstance.TransactionCommitStatus(true);
                try
                {
                    foreach (TransactionObject trObj in transactionInternal.transactionObjects)
                    {
                        if (!transactionInternal.nrRecordsBeforeCommit.ContainsKey(trObj.serializer))
                        {
                            transactionInternal.nrRecordsBeforeCommit.Add(trObj.serializer, new KeyValuePair <SqoTypeInfo, int>(trObj.objInfo.SqoTypeInfo, trObj.objInfo.SqoTypeInfo.Header.numberOfRecords));
                            TransactionTypeHeader tHeader = new TransactionTypeHeader();
                            tHeader.NumberOfRecords = trObj.objInfo.SqoTypeInfo.Header.numberOfRecords;
                            tHeader.TypeName        = trObj.objInfo.SqoTypeInfo.TypeName;
                            transactionInternal.siaqodbInstance.StoreObject(tHeader);
                            transactionInternal.siaqodbInstance.Flush <TransactionTypeHeader>();
                        }


                        TransactionObjectHeader header = trObj.PreCommit();
                        if (header != null)
                        {
                            if (lastHeader != null)
                            {
                                header.Position = lastHeader.Position + lastHeader.BatchSize;
                            }
                            SaveObjectForCrashRollback(trObj.originalObject, trObj.objInfo.SqoTypeInfo, transactStorage, header, trObj.engine);
                            SaveHeader(header, transactionInternal.siaqodbInstance);
                            lastHeader = header;
                        }
                        transactionInternal.siaqodbInstance.circularRefCache.Add(trObj.currentObject);

                        trObj.Commit();
                    }
                }

                finally
                {
                    transactStorage.Close();
                    transactionInternal.siaqodbInstance.TransactionCommitStatus(false);
                }

                foreach (SqoTypeInfo ti in transactionInternal.tiInvolvedInTransaction)
                {
                    transactionInternal.siaqodbInstance.PutIndexPersiststenceState(ti, true);
                    transactionInternal.siaqodbInstance.PersistIndexDirtyNodes(ti);
                }

                transactions.Remove(id);
                transactionInternal.siaqodbInstance.DropType <TransactionObjectHeader>();
                transactionInternal.siaqodbInstance.DropType <TransactionTypeHeader>();
                transactionInternal.siaqodbInstance.DropTransactionLog();
                transactionInternal.transaction.status = TransactionStatus.Closed;
                transactionInternal.siaqodbInstance.Flush();
            }
        }