public void Commit( CommitStage c ) { if ( c == CommitStage.Rollback ) { Buffers.Clear(); UnsavedPageNums.Clear(); UnsavedAdded = false; ReadAvail = 0; WriteAvail = 0; CurBufferNum = -1; } else if ( c == CommitStage.Write ) { foreach ( long bufferNum in UnsavedPageNums ) { byte [] b = GetBuffer( bufferNum ); long pos = bufferNum << BufferShift; long n = Len - pos; if ( n > BufferSize ) n = BufferSize; if ( BaseStream.Position != pos ) BaseStream.Position = pos; BaseStream.Write( b, 0, (int)n ); } UnsavedPageNums.Clear(); UnsavedAdded = false; BaseStream.SetLength( Len ); } else if ( c == CommitStage.Flush ) { BaseStream.Flush( true ); } }
/// <summary> /// Checks both internal and external constraints and, if successful, /// changes the state of the variable in accordance with requests (including data writing) /// </summary> internal override void Precommit() { if (!HasChanges) { return; } if (commitStage > CommitStage.Precommitting) { return; } try { /* Checking internal constraints */ DoCheckConstraints(); commitStage = CommitStage.Precommitting; /* Checking external constraints */ if (!FireEventVariableCommitting(changes)) { throw new Exception("Commission is cancelled."); } /* To avoid duplicate execution of the following code, * because it might be executed in Precommit of dependand DataSet as * a part of the VariableCommitting event handling */ if (commitStage > CommitStage.Precommitting) { return; } /* Changing state of the variable */ if (changes.DataPieces != null && changes.DataPieces.Count > 0) { BeginWriteTransaction(); writeTransactionOpened = true; while (changes.DataPieces.Count > 0) { DataPiece piece = changes.DataPieces[0]; WriteData(piece.Origin, piece.Data); changes.DataPieces.RemoveAt(0); } } } catch { /* If operation failed rolling back to "changed" state. * Now it is possible either to Rollback to previous committed state or * make further changes to fix errors.*/ commitStage = CommitStage.Changed; throw; } /* Success: this variable is ready for commission */ commitStage = CommitStage.Precommitted; }
public void Commit( CommitStage c ) { if ( Saved ) return; if ( c == CommitStage.Prepare ) { // Save the pages to the underlying stream. foreach ( G.KeyValuePair<long,IndexPage> pair in PageMap ) { IndexPage p = pair.Value; if ( !p.Saved ) { p.WriteHeader(); F.Position = (long)p.PageId * IndexPage.PageSize; // For last page, only write the amount actually used (so file size is minimised) F.Write( p.Data, 0, p.PageId == PageAlloc-1 ? p.Size() : IndexPage.PageSize ); p.Saved = true; } } } else if ( c == CommitStage.Rollback ) { PageMap.Clear(); Initialise(); } else F.Commit( c ); if ( c >= CommitStage.Flush ) Saved = true; }
private void ClearChanges() { if (writeTransactionOpened) { throw new ApplicationException("Write-transaction cannot be opened at this moment!"); } changes = new Changes(); commitStage = CommitStage.Committed; }
/* Private methods */ void Commit( CommitStage c ) { SysString.Commit( c ); SysBinary.Commit( c ); SysStringIndex.Commit( c ); SysBinaryIndex.Commit( c ); foreach( G.KeyValuePair<string,Schema> p in SchemaDict ) foreach( G.KeyValuePair<string,TableExpression> q in p.Value.TableDict ) q.Value.Commit( c ); }
private void StartChanging() { if (commitStage == CommitStage.Committed) { changes = new Changes(); changes.DataPieces = new List <DataPiece>(); changes.InitialSchema = GetSchema(); changes.Cs = null; } commitStage = CommitStage.Changed; }
/// <summary> /// Makes checks of internal constraints. /// </summary> internal override void CheckConstraints() { if (!HasChanges) { return; } if (commitStage >= CommitStage.ConstrainsChecked) { return; } CheckCoordinateSystems(); OnCheckConstraints(changes); this.commitStage = CommitStage.ConstrainsChecked; }
public override void Commit(CommitStage c) { if (!Dirty) { return; } DataFile.Commit(c); foreach (G.KeyValuePair <long, IndexFile> p in IxDict) { p.Value.Commit(c); } if (c >= CommitStage.Flush) { Dirty = false; } }
/// <summary> /// Initializes an instance of the variable. /// </summary> protected TransactedVariable(IDataSetProvider provider, string query, string name, string[] dims) : base(provider, query, name, dims) { commitStage = CommitStage.Committed; StartChanging(); }
public virtual bool Get( long id, Value[] row, int [] used ){ return false; } // Only called if FindIndex is implemented. // Atomic update. public virtual void Commit( CommitStage c ) { }