// String and Binary handling. These are represented as a long, which is an offset into a file.
 
  public long EncodeString( string s ) 
  { 
    if ( s == "" ) return 0;
    // See if it is in SysStringIndex
    try
    {
      var start = new StringStart( s );
      foreach( IndexFileRecord ixr in SysStringIndex.From( start.Compare, false ) )
      {
        if ( (string)(ixr.Col[0]._O) == s ) return ixr.Col[0].L;
        break;
      }
    }
    catch ( System.Exception x )
    {
      SysStringIndex.Dump();
      throw x;
    }

    // Save to file.
    long sid = SysString.Length;
    SysString.Position = sid;
    SysStringWriter.Write( s );

    // Insert into the index
    IndexFileRecord r = new IndexFileRecord( 1 );
    r.Col[ 0 ].L = sid + 1;
    r.Col[ 0 ]._O = s;
    SysStringIndex.Insert( ref r );

    return sid + 1; // + 1 because zero indicates the encoding has not yet been done.
  }
Пример #2
0
  /* 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 methods */

  void  RollbackOrCommit()
  {
    if ( Rollback )
    {
      Log.Reset();
      foreach( G.KeyValuePair<string,Schema> p in SchemaDict )
        foreach( G.KeyValuePair<string,TableExpression> q in p.Value.TableDict )
          q.Value.Rollback();
      Rollback = false;
    }
    else 
    {
      // Save indexes to underlying buffered streams ( can add more Log entries ). 
      SysStringIndex.PrepareToCommit();
      SysBinaryIndex.PrepareToCommit();
      foreach( G.KeyValuePair<string,Schema> p in SchemaDict )
        foreach( G.KeyValuePair<string,TableExpression> q in p.Value.TableDict )
          q.Value.PrepareToCommit();  
    
      if ( Log.Commit() )
      {
        SysString.Flush(); SysStringIndex.Commit();
        SysBinary.Flush(); SysBinaryIndex.Commit();

        foreach( G.KeyValuePair<string,Schema> p in SchemaDict )
          foreach( G.KeyValuePair<string,TableExpression> q in p.Value.TableDict )
            q.Value.Commit();

        foreach ( long fileId in DeletedFiles )
        {
          var f = new IO.FileInfo( Name + fileId );
          f.Delete();
        }
        Log.Reset();
      }
    }
    DeletedFiles.Clear();
  }